changeset 4691:62091b0ef789

Fix filtering of Collections/Projects in the gui The filter was reseted after each reloading of the users collections.
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 17 Dec 2012 16:13:42 +0100
parents 7c59baa150bd
children f2578acc60d7
files flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java
diffstat 1 files changed, 15 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Mon Dec 17 16:11:48 2012 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Mon Dec 17 16:13:42 2012 +0100
@@ -164,15 +164,14 @@
     /** All user collections.*/
     protected List<Collection> collections;
 
-    /** The collections visible in the grid.*/
-    protected List<Collection> filteredCollections;
-
     /** The collection to clone*/
     protected Collection cloneCollection;
 
     /** The message class that provides i18n strings.*/
     protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
 
+    private String filter;
+
 
     /**
      * The default constructor that creates a new ProjectList for a specific
@@ -185,7 +184,6 @@
         this.flys = flys;
         this.user = user;
 
-        filteredCollections = new ArrayList<Collection>();
         collections = new ArrayList<Collection>();
         grid = new ListGrid();
         initGrid();
@@ -444,17 +442,9 @@
     @Override
     public void onFilterCriteriaChanged(StringFilterEvent event) {
         String search = event.getFilter();
-        if (search != null && search.length() > 0) {
-            // Filter the records.
-            filterCollections(search);
-        }
-        else {
-            filteredCollections.clear();
-            for(int i = 0; i < collections.size(); i++) {
-                filteredCollections.add(collections.get(i));
-            }
-            updateGrid();
-        }
+        // Filter the records.
+        setFilter(search);
+        updateGrid();
     }
 
 
@@ -675,7 +665,7 @@
         for (Collection coll : c) {
             this.collections.add(coll);
         }
-        filterCollections("");
+        updateGrid();
     }
 
 
@@ -690,45 +680,20 @@
             return;
         }
 
-        for (Collection c: filteredCollections) {
-            grid.addData(new CollectionRecord(c));
-        }
-    }
-
-
-    /**
-     * Filter for the user collections.
-     *
-     * @param search String to search for in collection names.
-     */
-    protected void filterCollections(String search) {
-        // Clear the collection list.
-        filteredCollections.clear();
-
-        // Filter the list.
-        for (int i = 0; i < collections.size(); i++) {
+        for (Collection col: collections) {
             String name;
 
-            // Get the collection name.
-            if (collections.get(i).getName().equals("") ||
-                collections.get(i).getName() == null) {
-                name = collections.get(i).identifier();
-            }
-            else {
-                name = collections.get(i).getName();
-            }
+            name = col.getDisplayName().toLowerCase();
 
-            name = name.toLowerCase();
             // Add a collection to the filtered list if the search string
             // matches.
-            if (name.contains(search.toLowerCase())) {
-                filteredCollections.add(collections.get(i));
+            if (filter == null || filter.isEmpty() ||
+                    name.contains(filter.toLowerCase())) {
+                grid.addData(new CollectionRecord(col));
             }
         }
-        updateGrid();
     }
 
-
     public int getMaxNameLength() {
         return MAX_NAME_LENGTH;
     }
@@ -979,5 +944,9 @@
             this.flys.shoHeaderProjectButton();
         }
     }
+
+    private void setFilter(String filter) {
+        this.filter = filter;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org