# HG changeset patch # User Björn Ricks # Date 1355757222 -3600 # Node ID 62091b0ef789d031c31fc24e5cc3bcda921f312a # Parent 7c59baa150bdde44503074ddd0fb74f0981d5db8 Fix filtering of Collections/Projects in the gui The filter was reseted after each reloading of the users collections. diff -r 7c59baa150bd -r 62091b0ef789 flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java --- 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 collections; - /** The collections visible in the grid.*/ - protected List 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(); collections = new ArrayList(); 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 :