changeset 885:eeea6a02d62c

Added filter functionality to the project list. flys-client/trunk@2719 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 13 Sep 2011 12:26:02 +0000
parents ace7e9cfbb7f
children 2161d3acc83f
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java
diffstat 2 files changed, 101 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Sep 13 11:31:53 2011 +0000
+++ b/flys-client/ChangeLog	Tue Sep 13 12:26:02 2011 +0000
@@ -1,3 +1,8 @@
+2011-09-13  Raimund Renkert <raimund.renkert@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/ProjectList.java:
+	  Added filter functionality to the project list.
+
 2011-09-13  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/shared/model/ArtifactFilter.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Tue Sep 13 11:31:53 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Tue Sep 13 12:26:02 2011 +0000
@@ -2,6 +2,8 @@
 
 import java.util.Date;
 import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
 import java.util.MissingResourceException;
 
 import com.google.gwt.core.client.GWT;
@@ -9,6 +11,9 @@
 import com.google.gwt.user.client.Timer;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
+import com.smartgwt.client.data.Criteria;
+import de.intevation.flys.client.client.event.FilterHandler;
+import de.intevation.flys.client.client.event.StringFilterEvent;
 import com.smartgwt.client.types.Alignment;
 import com.smartgwt.client.types.ListGridEditEvent;
 import com.smartgwt.client.types.ListGridFieldType;
@@ -66,7 +71,7 @@
  */
 public class ProjectList
 extends      VLayout
-implements   CollectionChangeHandler, EditCompleteHandler
+implements   CollectionChangeHandler, EditCompleteHandler, FilterHandler
 {
     /** Interval to refresh the user's projects.*/
     public static final int UPDATE_INTERVAL = 30000;
@@ -114,6 +119,12 @@
     /** The grid that contains the project rows.*/
     protected ListGrid grid;
 
+    /** All user collections.*/
+    protected List<Collection> collections;
+
+    /** The collections visible in the grid.*/
+    protected List<Collection> filteredCollections;
+
     /**
      * The default constructor that creates a new ProjectList for a specific
      * user.
@@ -124,6 +135,8 @@
         this.flys = flys;
         this.user = user;
 
+        filteredCollections = new ArrayList();
+        collections = new ArrayList();
         grid = new ListGrid();
         initGrid();
         init();
@@ -302,8 +315,29 @@
         titleWrapper.setWidth100();
         gridWrapper.addChild(grid);
 
+        TableFilter filter = new TableFilter();
+        filter.setHeight("30px");
+        filter.addFilterHandler(this);
+
         addMember(titleWrapper);
         addMember(gridWrapper);
+        addMember(filter);
+    }
+
+
+    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();
+        }
     }
 
 
@@ -473,13 +507,15 @@
 
                     GWT.log("Received " + num + " user collections.");
 
-                    updateGrid(collections);
+                    updateGridDataSource(collections);
                 }
             }
         );
     }
 
-
+    /**
+     * Delete all entries in the ListGrid.
+     */
     protected void clearGrid() {
         ListGridRecord[] records = grid.getRecords();
 
@@ -489,18 +525,72 @@
     }
 
 
-    protected void updateGrid(Collection[] collections) {
+    /**
+     * Update the collections data source.
+     *
+     * First removes all collections to avoid duplicates, then add new entries.
+     *
+     * @param c Collections to set to the data source.
+     */
+    protected void updateGridDataSource (Collection[] c) {
+        collections.clear();
+        for (Collection coll : c) {
+            this.collections.add(coll);
+        }
+        filterCollections("");
+    }
+
+
+    /**
+     * Updates the ListGrid.
+     */
+    protected void updateGrid() {
         clearGrid();
 
-        if (collections == null || collections.length == 0) {
+        if (filteredCollections == null ||
+            filteredCollections.size() == 0) {
             return;
         }
 
-        for (Collection c: collections) {
+        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) {
+        int j = 0;
+
+        // Clear the collection list.
+        filteredCollections.clear();
+
+        // Filter the list.
+        for (int i = 0; i < collections.size(); i++) {
+            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();
+            }
+
+            // Add a collection to the filtered list if the search string
+            // matches.
+            if (name.contains(search)) {
+                filteredCollections.add(collections.get(i));
+                j++;
+            }
+        }
+        updateGrid();
+    }
+
 
     public int getMaxNameLength() {
         return MAX_NAME_LENGTH;

http://dive4elements.wald.intevation.org