Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java @ 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 | f343b4c2d135 |
children | 6a27949c7022 |
comparison
equal
deleted
inserted
replaced
884:ace7e9cfbb7f | 885:eeea6a02d62c |
---|---|
1 package de.intevation.flys.client.client.ui; | 1 package de.intevation.flys.client.client.ui; |
2 | 2 |
3 import java.util.Date; | 3 import java.util.Date; |
4 import java.util.Map; | 4 import java.util.Map; |
5 import java.util.List; | |
6 import java.util.ArrayList; | |
5 import java.util.MissingResourceException; | 7 import java.util.MissingResourceException; |
6 | 8 |
7 import com.google.gwt.core.client.GWT; | 9 import com.google.gwt.core.client.GWT; |
8 import com.google.gwt.i18n.client.DateTimeFormat; | 10 import com.google.gwt.i18n.client.DateTimeFormat; |
9 import com.google.gwt.user.client.Timer; | 11 import com.google.gwt.user.client.Timer; |
10 import com.google.gwt.user.client.rpc.AsyncCallback; | 12 import com.google.gwt.user.client.rpc.AsyncCallback; |
11 | 13 |
14 import com.smartgwt.client.data.Criteria; | |
15 import de.intevation.flys.client.client.event.FilterHandler; | |
16 import de.intevation.flys.client.client.event.StringFilterEvent; | |
12 import com.smartgwt.client.types.Alignment; | 17 import com.smartgwt.client.types.Alignment; |
13 import com.smartgwt.client.types.ListGridEditEvent; | 18 import com.smartgwt.client.types.ListGridEditEvent; |
14 import com.smartgwt.client.types.ListGridFieldType; | 19 import com.smartgwt.client.types.ListGridFieldType; |
15 import com.smartgwt.client.types.SelectionStyle; | 20 import com.smartgwt.client.types.SelectionStyle; |
16 import com.smartgwt.client.types.SortArrow; | 21 import com.smartgwt.client.types.SortArrow; |
64 * | 69 * |
65 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 70 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
66 */ | 71 */ |
67 public class ProjectList | 72 public class ProjectList |
68 extends VLayout | 73 extends VLayout |
69 implements CollectionChangeHandler, EditCompleteHandler | 74 implements CollectionChangeHandler, EditCompleteHandler, FilterHandler |
70 { | 75 { |
71 /** Interval to refresh the user's projects.*/ | 76 /** Interval to refresh the user's projects.*/ |
72 public static final int UPDATE_INTERVAL = 30000; | 77 public static final int UPDATE_INTERVAL = 30000; |
73 | 78 |
74 /** Min Interval to refresh the user's projects.*/ | 79 /** Min Interval to refresh the user's projects.*/ |
112 protected User user; | 117 protected User user; |
113 | 118 |
114 /** The grid that contains the project rows.*/ | 119 /** The grid that contains the project rows.*/ |
115 protected ListGrid grid; | 120 protected ListGrid grid; |
116 | 121 |
122 /** All user collections.*/ | |
123 protected List<Collection> collections; | |
124 | |
125 /** The collections visible in the grid.*/ | |
126 protected List<Collection> filteredCollections; | |
127 | |
117 /** | 128 /** |
118 * The default constructor that creates a new ProjectList for a specific | 129 * The default constructor that creates a new ProjectList for a specific |
119 * user. | 130 * user. |
120 * | 131 * |
121 * @param user The user. | 132 * @param user The user. |
122 */ | 133 */ |
123 public ProjectList(FLYS flys, User user) { | 134 public ProjectList(FLYS flys, User user) { |
124 this.flys = flys; | 135 this.flys = flys; |
125 this.user = user; | 136 this.user = user; |
126 | 137 |
138 filteredCollections = new ArrayList(); | |
139 collections = new ArrayList(); | |
127 grid = new ListGrid(); | 140 grid = new ListGrid(); |
128 initGrid(); | 141 initGrid(); |
129 init(); | 142 init(); |
130 initTimer(); | 143 initTimer(); |
131 | 144 |
300 Canvas gridWrapper = new Canvas(); | 313 Canvas gridWrapper = new Canvas(); |
301 gridWrapper.setPadding(0); | 314 gridWrapper.setPadding(0); |
302 titleWrapper.setWidth100(); | 315 titleWrapper.setWidth100(); |
303 gridWrapper.addChild(grid); | 316 gridWrapper.addChild(grid); |
304 | 317 |
318 TableFilter filter = new TableFilter(); | |
319 filter.setHeight("30px"); | |
320 filter.addFilterHandler(this); | |
321 | |
305 addMember(titleWrapper); | 322 addMember(titleWrapper); |
306 addMember(gridWrapper); | 323 addMember(gridWrapper); |
324 addMember(filter); | |
325 } | |
326 | |
327 | |
328 public void onFilterCriteriaChanged(StringFilterEvent event) { | |
329 String search = event.getFilter(); | |
330 if (search != null && search.length() > 0) { | |
331 // Filter the records. | |
332 filterCollections(search); | |
333 } | |
334 else { | |
335 filteredCollections.clear(); | |
336 for(int i = 0; i < collections.size(); i++) { | |
337 filteredCollections.add(collections.get(i)); | |
338 } | |
339 updateGrid(); | |
340 } | |
307 } | 341 } |
308 | 342 |
309 | 343 |
310 public void onCollectionChange(CollectionChangeEvent event) { | 344 public void onCollectionChange(CollectionChangeEvent event) { |
311 if (event.getOldValue() == null) { | 345 if (event.getOldValue() == null) { |
471 public void onSuccess(Collection[] collections) { | 505 public void onSuccess(Collection[] collections) { |
472 int num = collections != null ? collections.length : 0; | 506 int num = collections != null ? collections.length : 0; |
473 | 507 |
474 GWT.log("Received " + num + " user collections."); | 508 GWT.log("Received " + num + " user collections."); |
475 | 509 |
476 updateGrid(collections); | 510 updateGridDataSource(collections); |
477 } | 511 } |
478 } | 512 } |
479 ); | 513 ); |
480 } | 514 } |
481 | 515 |
482 | 516 /** |
517 * Delete all entries in the ListGrid. | |
518 */ | |
483 protected void clearGrid() { | 519 protected void clearGrid() { |
484 ListGridRecord[] records = grid.getRecords(); | 520 ListGridRecord[] records = grid.getRecords(); |
485 | 521 |
486 for (ListGridRecord record: records) { | 522 for (ListGridRecord record: records) { |
487 grid.removeData(record); | 523 grid.removeData(record); |
488 } | 524 } |
489 } | 525 } |
490 | 526 |
491 | 527 |
492 protected void updateGrid(Collection[] collections) { | 528 /** |
529 * Update the collections data source. | |
530 * | |
531 * First removes all collections to avoid duplicates, then add new entries. | |
532 * | |
533 * @param c Collections to set to the data source. | |
534 */ | |
535 protected void updateGridDataSource (Collection[] c) { | |
536 collections.clear(); | |
537 for (Collection coll : c) { | |
538 this.collections.add(coll); | |
539 } | |
540 filterCollections(""); | |
541 } | |
542 | |
543 | |
544 /** | |
545 * Updates the ListGrid. | |
546 */ | |
547 protected void updateGrid() { | |
493 clearGrid(); | 548 clearGrid(); |
494 | 549 |
495 if (collections == null || collections.length == 0) { | 550 if (filteredCollections == null || |
551 filteredCollections.size() == 0) { | |
496 return; | 552 return; |
497 } | 553 } |
498 | 554 |
499 for (Collection c: collections) { | 555 for (Collection c: filteredCollections) { |
500 grid.addData(new CollectionRecord(c)); | 556 grid.addData(new CollectionRecord(c)); |
501 } | 557 } |
558 } | |
559 | |
560 /** | |
561 * Filter for the user collections. | |
562 * | |
563 * @param search String to search for in collection names. | |
564 */ | |
565 protected void filterCollections(String search) { | |
566 int j = 0; | |
567 | |
568 // Clear the collection list. | |
569 filteredCollections.clear(); | |
570 | |
571 // Filter the list. | |
572 for (int i = 0; i < collections.size(); i++) { | |
573 String name; | |
574 | |
575 // Get the collection name. | |
576 if (collections.get(i).getName().equals("") || | |
577 collections.get(i).getName() == null) { | |
578 name = collections.get(i).identifier(); | |
579 } | |
580 else { | |
581 name = collections.get(i).getName(); | |
582 } | |
583 | |
584 // Add a collection to the filtered list if the search string | |
585 // matches. | |
586 if (name.contains(search)) { | |
587 filteredCollections.add(collections.get(i)); | |
588 j++; | |
589 } | |
590 } | |
591 updateGrid(); | |
502 } | 592 } |
503 | 593 |
504 | 594 |
505 public int getMaxNameLength() { | 595 public int getMaxNameLength() { |
506 return MAX_NAME_LENGTH; | 596 return MAX_NAME_LENGTH; |