annotate flys-client/src/main/java/de/intevation/flys/client/client/ui/RangeTableFilter.java @ 2905:51ed89b754ae

FLYS client: Removed trailing whitespace. flys-client/trunk@4671 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 15 Jun 2012 09:35:37 +0000
parents 4f4d29404dba
children 03de5c424f95
rev   line source
1534
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.client.client.ui;
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
2
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
3 import java.util.ArrayList;
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
4 import java.util.List;
1536
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
5 import java.util.Map;
1534
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
6
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
7 import com.google.gwt.core.client.GWT;
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
9 import com.smartgwt.client.widgets.form.DynamicForm;
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10 import com.smartgwt.client.widgets.form.fields.TextItem;
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13 import com.smartgwt.client.widgets.form.fields.events.KeyUpEvent;
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 import com.smartgwt.client.widgets.form.fields.events.KeyUpHandler;
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15 import com.smartgwt.client.widgets.layout.HLayout;
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17 import de.intevation.flys.client.client.event.FilterHandler;
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18 import de.intevation.flys.client.client.event.RangeFilterEvent;
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19 import de.intevation.flys.client.client.FLYSConstants;
1536
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
20 import de.intevation.flys.client.client.utils.DoubleValidator;
1534
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22 /**
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 */
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 public class RangeTableFilter
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26 extends HLayout
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 implements ChangedHandler, KeyUpHandler
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 {
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 /** The message class that provides i18n strings. */
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 protected List<FilterHandler> handlers;
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34 protected TextItem fromField;
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 protected TextItem toField;
1536
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
36 protected DynamicForm filterForm;
1534
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38 public RangeTableFilter() {
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39 super();
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40 fromField = new TextItem();
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 fromField.setTitle(MESSAGES.from());
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42 fromField.setWidth(60);
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 toField = new TextItem();
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 toField.setTitle(MESSAGES.to());
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 toField.setWidth(60);
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48 handlers = new ArrayList<FilterHandler>();
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50 fromField.addChangedHandler(this);
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51 fromField.addKeyUpHandler(this);
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 toField.addChangedHandler(this);
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 toField.addKeyUpHandler(this);
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54
1536
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
55 filterForm = new DynamicForm();
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
56 filterForm.setNumCols(4);
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
57 filterForm.setFields(fromField, toField);
1534
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58
1536
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
59 addMember(filterForm);
1534
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60 }
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63 public void onChanged(ChangedEvent event) {
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64 // This event handler is to slow...
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 // fireFilterCriteriaChanged(getSearchString());
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66 }
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
69 public void onKeyUp(KeyUpEvent event) {
1536
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
70 DoubleValidator validator = new DoubleValidator();
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
71 Map errors = filterForm.getErrors();
2905
51ed89b754ae FLYS client: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1536
diff changeset
72 if(event.getItem().getValue() != null &&
1536
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
73 !validator.validate(event.getItem(), errors)) {
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
74 filterForm.setErrors(errors, true);
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
75 GWT.log("no valid input!");
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
76 return;
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
77 }
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
78 else {
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
79 errors.clear();
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
80 filterForm.setErrors(errors, true);
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1534
diff changeset
81 }
1534
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
82 //To deactivate "As you type" filter add
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
83 // ' && event.getKeyName().equals("Enter")'
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
84 // to the if-clause.
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
85 if (event != null) {
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
86 fireFilterCriteriaChanged(getFrom(), getTo());
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
87 }
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
88 }
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
89
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
90
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
91 public String getFrom() {
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
92 if (fromField.getValueAsString() == null) {
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
93 return "";
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
94 }
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
95 else {
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
96 return fromField.getValueAsString();
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
97 }
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
98 }
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
99
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
100
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
101 public String getTo() {
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
102 if (toField.getValueAsString() == null) {
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
103 return "";
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
104 }
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
105 else {
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
106 return toField.getValueAsString();
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
107 }
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
108 }
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
109
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
110
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
111 public void addFilterHandler(FilterHandler handler) {
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
112 if (handler != null) {
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
113 handlers.add(handler);
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
114 }
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
115 }
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
116
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
117
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
118 protected void fireFilterCriteriaChanged(String from, String to) {
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
119 RangeFilterEvent filter = new RangeFilterEvent(from, to);
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
120
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
121 for (FilterHandler handler: handlers) {
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
122 handler.onFilterCriteriaChanged(filter);
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
123 }
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
124 }
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
125
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
126
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
127 public void clear() {
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
128 fromField.clearValue();
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
129 toField.clearValue();
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
130 fireFilterCriteriaChanged("", "");
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
131 }
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
132 }
98123d34529b Added UI parts and event for filtering distances and locations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
133 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org