Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java @ 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 | c1c4c95ae9e4 |
children | f2578acc60d7 |
comparison
equal
deleted
inserted
replaced
4690:7c59baa150bd | 4691:62091b0ef789 |
---|---|
162 protected ListGrid grid; | 162 protected ListGrid grid; |
163 | 163 |
164 /** All user collections.*/ | 164 /** All user collections.*/ |
165 protected List<Collection> collections; | 165 protected List<Collection> collections; |
166 | 166 |
167 /** The collections visible in the grid.*/ | |
168 protected List<Collection> filteredCollections; | |
169 | |
170 /** The collection to clone*/ | 167 /** The collection to clone*/ |
171 protected Collection cloneCollection; | 168 protected Collection cloneCollection; |
172 | 169 |
173 /** The message class that provides i18n strings.*/ | 170 /** The message class that provides i18n strings.*/ |
174 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | 171 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); |
172 | |
173 private String filter; | |
175 | 174 |
176 | 175 |
177 /** | 176 /** |
178 * The default constructor that creates a new ProjectList for a specific | 177 * The default constructor that creates a new ProjectList for a specific |
179 * user. | 178 * user. |
183 public ProjectList(FLYS flys, User user) { | 182 public ProjectList(FLYS flys, User user) { |
184 super(); | 183 super(); |
185 this.flys = flys; | 184 this.flys = flys; |
186 this.user = user; | 185 this.user = user; |
187 | 186 |
188 filteredCollections = new ArrayList<Collection>(); | |
189 collections = new ArrayList<Collection>(); | 187 collections = new ArrayList<Collection>(); |
190 grid = new ListGrid(); | 188 grid = new ListGrid(); |
191 initGrid(); | 189 initGrid(); |
192 init(); | 190 init(); |
193 initTimer(); | 191 initTimer(); |
442 | 440 |
443 | 441 |
444 @Override | 442 @Override |
445 public void onFilterCriteriaChanged(StringFilterEvent event) { | 443 public void onFilterCriteriaChanged(StringFilterEvent event) { |
446 String search = event.getFilter(); | 444 String search = event.getFilter(); |
447 if (search != null && search.length() > 0) { | 445 // Filter the records. |
448 // Filter the records. | 446 setFilter(search); |
449 filterCollections(search); | 447 updateGrid(); |
450 } | |
451 else { | |
452 filteredCollections.clear(); | |
453 for(int i = 0; i < collections.size(); i++) { | |
454 filteredCollections.add(collections.get(i)); | |
455 } | |
456 updateGrid(); | |
457 } | |
458 } | 448 } |
459 | 449 |
460 | 450 |
461 @Override | 451 @Override |
462 public void onFilterCriteriaChanged(RangeFilterEvent event) { | 452 public void onFilterCriteriaChanged(RangeFilterEvent event) { |
673 return; | 663 return; |
674 } | 664 } |
675 for (Collection coll : c) { | 665 for (Collection coll : c) { |
676 this.collections.add(coll); | 666 this.collections.add(coll); |
677 } | 667 } |
678 filterCollections(""); | 668 updateGrid(); |
679 } | 669 } |
680 | 670 |
681 | 671 |
682 /** | 672 /** |
683 * Updates the ListGrid. | 673 * Updates the ListGrid. |
688 if (filteredCollections == null || | 678 if (filteredCollections == null || |
689 filteredCollections.size() == 0) { | 679 filteredCollections.size() == 0) { |
690 return; | 680 return; |
691 } | 681 } |
692 | 682 |
693 for (Collection c: filteredCollections) { | 683 for (Collection col: collections) { |
694 grid.addData(new CollectionRecord(c)); | |
695 } | |
696 } | |
697 | |
698 | |
699 /** | |
700 * Filter for the user collections. | |
701 * | |
702 * @param search String to search for in collection names. | |
703 */ | |
704 protected void filterCollections(String search) { | |
705 // Clear the collection list. | |
706 filteredCollections.clear(); | |
707 | |
708 // Filter the list. | |
709 for (int i = 0; i < collections.size(); i++) { | |
710 String name; | 684 String name; |
711 | 685 |
712 // Get the collection name. | 686 name = col.getDisplayName().toLowerCase(); |
713 if (collections.get(i).getName().equals("") || | 687 |
714 collections.get(i).getName() == null) { | |
715 name = collections.get(i).identifier(); | |
716 } | |
717 else { | |
718 name = collections.get(i).getName(); | |
719 } | |
720 | |
721 name = name.toLowerCase(); | |
722 // Add a collection to the filtered list if the search string | 688 // Add a collection to the filtered list if the search string |
723 // matches. | 689 // matches. |
724 if (name.contains(search.toLowerCase())) { | 690 if (filter == null || filter.isEmpty() || |
725 filteredCollections.add(collections.get(i)); | 691 name.contains(filter.toLowerCase())) { |
726 } | 692 grid.addData(new CollectionRecord(col)); |
727 } | 693 } |
728 updateGrid(); | 694 } |
729 } | 695 } |
730 | |
731 | 696 |
732 public int getMaxNameLength() { | 697 public int getMaxNameLength() { |
733 return MAX_NAME_LENGTH; | 698 return MAX_NAME_LENGTH; |
734 } | 699 } |
735 | 700 |
977 } | 942 } |
978 else { | 943 else { |
979 this.flys.shoHeaderProjectButton(); | 944 this.flys.shoHeaderProjectButton(); |
980 } | 945 } |
981 } | 946 } |
947 | |
948 private void setFilter(String filter) { | |
949 this.filter = filter; | |
950 } | |
982 } | 951 } |
983 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 952 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |