From 14acd83abff2b138eaf0f6ceb83ad166d0c70faa Mon Sep 17 00:00:00 2001
From: buczekp <buczekp>
Date: Tue, 19 Jan 2010 08:49:31 +0000
Subject: [PATCH] [LMS-1358] fixed 'Custom Column Filter buggy'

SVN: 14334
---
 .../application/help/HelpPageIdentifier.java  |  2 +-
 .../ui/file/AttachmentFileUploadField.java    |  2 +-
 .../ui/grid/AbstractBrowserGrid.java          | 43 +++++++++++++++----
 3 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/help/HelpPageIdentifier.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/help/HelpPageIdentifier.java
index 7af760f1156..d4f5ead1152 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/help/HelpPageIdentifier.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/help/HelpPageIdentifier.java
@@ -182,7 +182,7 @@ public class HelpPageIdentifier
             // If there is no message for the key return the key as the title,
             // otherwise return the message.
             return messageProvider.containsKey(messageKey) ? messageProvider.getMessage(messageKey)
-                    : messageKey; // TODO 2010-01-12, Piotr Buczek: is it better to return null?
+                    : messageKey;
         }
     }
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/file/AttachmentFileUploadField.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/file/AttachmentFileUploadField.java
index 71b0c7ca25f..51148eec747 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/file/AttachmentFileUploadField.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/file/AttachmentFileUploadField.java
@@ -72,7 +72,7 @@ public class AttachmentFileUploadField extends FileUploadField
     }
 
     private String getFilePathValue()
-    {// FIXME: correct?
+    {// FIXME: this is only relative path, not absolute
         return getFileInput().getValue(); // its not only file name, but full file path
     }
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/AbstractBrowserGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/AbstractBrowserGrid.java
index 96e7150aef7..980a830a671 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/AbstractBrowserGrid.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/AbstractBrowserGrid.java
@@ -205,6 +205,8 @@ public abstract class AbstractBrowserGrid<T/* Entity */, M extends BaseEntityMod
     // finished.
     private ResultSetFetchConfig<String> pendingFetchConfigOrNull;
 
+    private boolean disableFetch = false;
+
     private IDataRefreshCallback refreshCallback;
 
     private LayoutContainer bottomToolbars;
@@ -379,10 +381,6 @@ public abstract class AbstractBrowserGrid<T/* Entity */, M extends BaseEntityMod
                 {
                     if (resultSetKeyOrNull != null && pendingFetchConfigOrNull == null)
                     {
-                        // TODO 2009-09-16, Piotr Buczek: reload of data is not needed in some cases
-                        // - when filters with no text are removed,
-                        // - when new filters are created,
-                        // but when filter with text is removed it is needed.
                         ResultSetFetchConfig<String> fetchConfig =
                                 ResultSetFetchConfig.createFetchFromCache(resultSetKeyOrNull);
                         reloadData(fetchConfig);
@@ -504,7 +502,7 @@ public abstract class AbstractBrowserGrid<T/* Entity */, M extends BaseEntityMod
     {
         if (pendingFetchConfigOrNull == null)
         {
-            // this can happen when we user wants to sort data - the refresh method is not called
+            // this can happen when user wants to sort data - the refresh method is not called
             if (resultSetKeyOrNull == null)
             {
                 // data are not yet cached, so we ignore this call - should not really happen
@@ -911,11 +909,18 @@ public abstract class AbstractBrowserGrid<T/* Entity */, M extends BaseEntityMod
                     pagingToolbar.disableExportButton();
                     pagingToolbar.updateDefaultConfigButton(false);
 
+                    // We don't want to fetch data from cache when filters are reset.
+                    // refresh() invokes fetching of data from DB and would be ignored because of a
+                    // pending fetch.
+                    disableFetch();
+
                     // Need to reset filter fields *before* refreshing the grid so the list can be
                     // correctly retrieved
                     filterToolbar.resetFilterFields();
                     filterToolbar.resetFilterSelection();
 
+                    enableFetch();
+
                     // export and config buttons are enabled when ListEntitiesCallback is complete
                     refresh();
 
@@ -1056,10 +1061,12 @@ public abstract class AbstractBrowserGrid<T/* Entity */, M extends BaseEntityMod
     // Refreshes the data, does not clear the cache. Does not change the column model.
     private void reloadData(ResultSetFetchConfig<String> resultSetFetchConfig)
     {
-        if (pendingFetchConfigOrNull != null)
+        if (isFetchDisabled() || pendingFetchConfigOrNull != null)
         {
-            debug("Cannot reload the data with the mode '" + resultSetFetchConfig
-                    + "', there is an unfinished request already: " + pendingFetchConfigOrNull);
+            final String reason =
+                    isFetchDisabled() ? "fetch is disabled"
+                            : "there is an unfinished request already: " + pendingFetchConfigOrNull;
+            debug("Cannot reload the data with the mode '" + resultSetFetchConfig + "'; " + reason);
             return;
         }
         pendingFetchConfigOrNull = resultSetFetchConfig;
@@ -1352,6 +1359,26 @@ public abstract class AbstractBrowserGrid<T/* Entity */, M extends BaseEntityMod
         return new InternalLinkCellRenderer();
     }
 
+    protected final boolean isFetchDisabled()
+    {
+        return disableFetch;
+    }
+
+    protected final void disableFetch()
+    {
+        setDisableFetch(true);
+    }
+
+    protected final void enableFetch()
+    {
+        setDisableFetch(false);
+    }
+
+    private void setDisableFetch(boolean disableFetch)
+    {
+        this.disableFetch = disableFetch;
+    }
+
     // ------- generic static helpers
 
     private static List<String> getFilteredColumnIds(List<ColumnDataModel> result)
-- 
GitLab