Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/RangeTableFilter.java @ 1534:98123d34529b
Added UI parts and event for filtering distances and locations.
flys-client/trunk@3749 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Mon, 23 Jan 2012 11:07:38 +0000 |
parents | |
children | 4f4d29404dba |
comparison
equal
deleted
inserted
replaced
1533:7fcec57c2f2c | 1534:98123d34529b |
---|---|
1 package de.intevation.flys.client.client.ui; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import com.google.gwt.core.client.GWT; | |
7 | |
8 import com.smartgwt.client.widgets.form.DynamicForm; | |
9 import com.smartgwt.client.widgets.form.fields.TextItem; | |
10 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; | |
11 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; | |
12 import com.smartgwt.client.widgets.form.fields.events.KeyUpEvent; | |
13 import com.smartgwt.client.widgets.form.fields.events.KeyUpHandler; | |
14 import com.smartgwt.client.widgets.layout.HLayout; | |
15 | |
16 import de.intevation.flys.client.client.event.FilterHandler; | |
17 import de.intevation.flys.client.client.event.RangeFilterEvent; | |
18 import de.intevation.flys.client.client.FLYSConstants; | |
19 | |
20 | |
21 /** | |
22 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
23 */ | |
24 public class RangeTableFilter | |
25 extends HLayout | |
26 implements ChangedHandler, KeyUpHandler | |
27 { | |
28 /** The message class that provides i18n strings. */ | |
29 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); | |
30 | |
31 protected List<FilterHandler> handlers; | |
32 | |
33 protected TextItem fromField; | |
34 protected TextItem toField; | |
35 | |
36 public RangeTableFilter() { | |
37 super(); | |
38 fromField = new TextItem(); | |
39 fromField.setTitle(MESSAGES.from()); | |
40 fromField.setWidth(60); | |
41 toField = new TextItem(); | |
42 toField.setTitle(MESSAGES.to()); | |
43 toField.setWidth(60); | |
44 | |
45 | |
46 handlers = new ArrayList<FilterHandler>(); | |
47 | |
48 fromField.addChangedHandler(this); | |
49 fromField.addKeyUpHandler(this); | |
50 toField.addChangedHandler(this); | |
51 toField.addKeyUpHandler(this); | |
52 | |
53 DynamicForm form = new DynamicForm(); | |
54 form.setNumCols(4); | |
55 form.setFields(fromField, toField); | |
56 | |
57 addMember(form); | |
58 } | |
59 | |
60 | |
61 public void onChanged(ChangedEvent event) { | |
62 // This event handler is to slow... | |
63 // fireFilterCriteriaChanged(getSearchString()); | |
64 } | |
65 | |
66 | |
67 public void onKeyUp(KeyUpEvent event) { | |
68 //To deactivate "As you type" filter add | |
69 // ' && event.getKeyName().equals("Enter")' | |
70 // to the if-clause. | |
71 if (event != null) { | |
72 fireFilterCriteriaChanged(getFrom(), getTo()); | |
73 } | |
74 } | |
75 | |
76 | |
77 public String getFrom() { | |
78 if (fromField.getValueAsString() == null) { | |
79 return ""; | |
80 } | |
81 else { | |
82 return fromField.getValueAsString(); | |
83 } | |
84 } | |
85 | |
86 | |
87 public String getTo() { | |
88 if (toField.getValueAsString() == null) { | |
89 return ""; | |
90 } | |
91 else { | |
92 return toField.getValueAsString(); | |
93 } | |
94 } | |
95 | |
96 | |
97 public void addFilterHandler(FilterHandler handler) { | |
98 if (handler != null) { | |
99 handlers.add(handler); | |
100 } | |
101 } | |
102 | |
103 | |
104 protected void fireFilterCriteriaChanged(String from, String to) { | |
105 RangeFilterEvent filter = new RangeFilterEvent(from, to); | |
106 | |
107 for (FilterHandler handler: handlers) { | |
108 handler.onFilterCriteriaChanged(filter); | |
109 } | |
110 } | |
111 | |
112 | |
113 public void clear() { | |
114 fromField.clearValue(); | |
115 toField.clearValue(); | |
116 fireFilterCriteriaChanged("", ""); | |
117 } | |
118 } | |
119 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |