Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/TableFilter.java @ 875:a77958780e1c
Updated the search field style including i18n and changed the handler
implementation of TableFilter.
flys-client/trunk@2702 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Mon, 12 Sep 2011 11:47:42 +0000 |
parents | d08cf5ed1bfc |
children | 89c01218172b |
comparison
equal
deleted
inserted
replaced
874:d900ab031dfe | 875:a77958780e1c |
---|---|
1 package de.intevation.flys.client.client.ui; | 1 package de.intevation.flys.client.client.ui; |
2 | 2 |
3 import java.util.ArrayList; | 3 import java.util.ArrayList; |
4 import java.util.List; | 4 import java.util.List; |
5 | |
6 import com.google.gwt.core.client.GWT; | |
5 | 7 |
6 import com.smartgwt.client.widgets.IButton; | 8 import com.smartgwt.client.widgets.IButton; |
7 import com.smartgwt.client.widgets.events.ClickEvent; | 9 import com.smartgwt.client.widgets.events.ClickEvent; |
8 import com.smartgwt.client.widgets.events.ClickHandler; | 10 import com.smartgwt.client.widgets.events.ClickHandler; |
9 import com.smartgwt.client.widgets.form.DynamicForm; | 11 import com.smartgwt.client.widgets.form.DynamicForm; |
10 import com.smartgwt.client.widgets.form.fields.TextItem; | 12 import com.smartgwt.client.widgets.form.fields.TextItem; |
11 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; | 13 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; |
12 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; | 14 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; |
13 import com.smartgwt.client.widgets.form.fields.events.KeyPressEvent; | 15 import com.smartgwt.client.widgets.form.fields.events.KeyUpEvent; |
14 import com.smartgwt.client.widgets.form.fields.events.KeyPressHandler; | 16 import com.smartgwt.client.widgets.form.fields.events.KeyUpHandler; |
15 import com.smartgwt.client.widgets.layout.HLayout; | 17 import com.smartgwt.client.widgets.layout.HLayout; |
16 | 18 |
17 import de.intevation.flys.client.client.event.FilterHandler; | 19 import de.intevation.flys.client.client.event.FilterHandler; |
18 import de.intevation.flys.client.client.event.StringFilterEvent; | 20 import de.intevation.flys.client.client.event.StringFilterEvent; |
21 import de.intevation.flys.client.client.FLYSConstants; | |
19 | 22 |
20 | 23 |
21 /** | 24 /** |
22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 25 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
23 */ | 26 */ |
24 public class TableFilter | 27 public class TableFilter |
25 extends HLayout | 28 extends HLayout |
26 implements ChangedHandler, ClickHandler, KeyPressHandler | 29 implements ChangedHandler, KeyUpHandler |
27 { | 30 { |
28 public static final String SEARCH_FIELD = "searchfield"; | 31 /** The message class that provides i18n strings. */ |
29 | 32 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); |
30 | 33 |
31 protected List<FilterHandler> handlers; | 34 protected List<FilterHandler> handlers; |
32 | 35 |
33 protected TextItem searchfield; | 36 protected TextItem searchfield; |
34 | 37 |
35 | 38 |
36 public TableFilter() { | 39 public TableFilter() { |
37 super(); | 40 super(); |
38 searchfield = new TextItem(SEARCH_FIELD); | 41 searchfield = new TextItem(MESSAGES.search()); |
39 handlers = new ArrayList<FilterHandler>(); | 42 handlers = new ArrayList<FilterHandler>(); |
40 | 43 |
41 searchfield.addChangedHandler(this); | 44 searchfield.addChangedHandler(this); |
42 searchfield.addKeyPressHandler(this); | 45 searchfield.addKeyUpHandler(this); |
43 | 46 |
44 DynamicForm form = new DynamicForm(); | 47 DynamicForm form = new DynamicForm(); |
45 form.setFields(searchfield); | 48 form.setFields(searchfield); |
46 | 49 |
47 IButton clear = new IButton("Clear"); | |
48 clear.addClickHandler(this); | |
49 | |
50 addMember(form); | 50 addMember(form); |
51 addMember(clear); | |
52 } | 51 } |
53 | 52 |
54 | 53 |
55 public void onChanged(ChangedEvent event) { | 54 public void onChanged(ChangedEvent event) { |
56 // This event handler is to slow... | 55 // This event handler is to slow... |
57 // fireFilterCriteriaChanged(getSearchString()); | 56 // fireFilterCriteriaChanged(getSearchString()); |
58 } | 57 } |
59 | 58 |
60 | 59 |
61 public void onKeyPress(KeyPressEvent event) { | 60 public void onKeyUp(KeyUpEvent event) { |
62 //To deactivate "As you type" filter add | 61 //To deactivate "As you type" filter add |
63 // ' && event.getKeyName().equals("Enter")' | 62 // ' && event.getKeyName().equals("Enter")' |
64 // to the if-clause. | 63 // to the if-clause. |
65 if (event != null) { | 64 if (event != null) { |
66 fireFilterCriteriaChanged(getSearchString()); | 65 fireFilterCriteriaChanged(getSearchString()); |
67 } | 66 } |
68 } | 67 } |
69 | 68 |
70 | 69 |
71 public void onClick(ClickEvent event) { | |
72 searchfield.setValue(""); | |
73 fireFilterCriteriaChanged(""); | |
74 } | |
75 | |
76 | |
77 public void clearSearch() { | |
78 searchfield.setValue(""); | |
79 } | |
80 | |
81 | |
82 public String getSearchString() { | 70 public String getSearchString() { |
83 return searchfield.getValueAsString(); | 71 if (searchfield.getValueAsString() == null) { |
72 return ""; | |
73 } | |
74 else { | |
75 return searchfield.getValueAsString(); | |
76 } | |
84 } | 77 } |
85 | 78 |
86 | 79 |
87 public void addFilterHandler(FilterHandler handler) { | 80 public void addFilterHandler(FilterHandler handler) { |
88 if (handler != null) { | 81 if (handler != null) { |