Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java @ 20:c128d675386b
Added UIProviders that are used to create widgets for entering data.
flys-client/trunk@1334 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 22 Feb 2011 17:17:12 +0000 |
parents | |
children | 5709bd8f4d7c |
comparison
equal
deleted
inserted
replaced
19:f48b2cb2e219 | 20:c128d675386b |
---|---|
1 package de.intevation.flys.client.client.ui; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.LinkedHashMap; | |
5 import java.util.List; | |
6 | |
7 import com.google.gwt.core.client.GWT; | |
8 | |
9 import com.smartgwt.client.widgets.Canvas; | |
10 import com.smartgwt.client.widgets.IButton; | |
11 import com.smartgwt.client.widgets.events.ClickEvent; | |
12 import com.smartgwt.client.widgets.events.ClickHandler; | |
13 import com.smartgwt.client.widgets.form.DynamicForm; | |
14 import com.smartgwt.client.widgets.form.fields.ComboBoxItem; | |
15 import com.smartgwt.client.widgets.layout.VLayout; | |
16 | |
17 import de.intevation.flys.client.shared.model.Data; | |
18 import de.intevation.flys.client.shared.model.DataItem; | |
19 import de.intevation.flys.client.shared.model.DefaultData; | |
20 import de.intevation.flys.client.shared.model.DefaultDataItem; | |
21 | |
22 import de.intevation.flys.client.client.FLYSMessages; | |
23 import de.intevation.flys.client.client.event.HasStepForwardHandlers; | |
24 import de.intevation.flys.client.client.event.StepForwardEvent; | |
25 import de.intevation.flys.client.client.event.StepForwardHandler; | |
26 | |
27 | |
28 /** | |
29 * This UIProvider displays the DataItems of the Data object in a combo box. | |
30 * | |
31 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
32 */ | |
33 public class SelectProvider implements UIProvider, HasStepForwardHandlers, | |
34 ClickHandler | |
35 { | |
36 /** The message class that provides i18n strings.*/ | |
37 protected FLYSMessages messages = GWT.create(FLYSMessages.class); | |
38 | |
39 /** The StepForwardHandlers.*/ | |
40 protected List<StepForwardHandler> forwardHandlers; | |
41 | |
42 /** The combobox.*/ | |
43 protected ComboBoxItem combobox; | |
44 | |
45 | |
46 /** | |
47 * Creates a new UIProvider instance of this class. | |
48 */ | |
49 public SelectProvider() { | |
50 forwardHandlers = new ArrayList<StepForwardHandler>(); | |
51 } | |
52 | |
53 | |
54 public void addStepForwardHandler(StepForwardHandler handler) { | |
55 if (handler != null) { | |
56 GWT.log("SelectProvider - addStepForwardHandler()"); | |
57 forwardHandlers.add(handler); | |
58 } | |
59 | |
60 GWT.log("Handlers now: " + forwardHandlers.size()); | |
61 } | |
62 | |
63 | |
64 /** | |
65 * This method is called after the user has clicked on the 'next' button to | |
66 * step to the next state. | |
67 * | |
68 * @param e The StepForwardEvent. | |
69 */ | |
70 protected void fireStepForwardEvent(StepForwardEvent e) { | |
71 GWT.log("SelectProvider - fireStepForwardEvent() handlers: " + forwardHandlers.size()); | |
72 for (StepForwardHandler handler: forwardHandlers) { | |
73 GWT.log("SelectProvider - fireStepForwardEvent()"); | |
74 handler.onStepForward(e); | |
75 } | |
76 } | |
77 | |
78 public void onClick(ClickEvent e) { | |
79 GWT.log("SelectProvider - feed and advance..."); | |
80 Data[] data = getData(); | |
81 | |
82 GWT.log("GO ON..."); | |
83 SelectProvider.this.fireStepForwardEvent(new StepForwardEvent(data)); | |
84 } | |
85 | |
86 /** | |
87 * This method currently returns a | |
88 * {@link com.smartgwt.client.widgets.form.DynamicForm} that contains all | |
89 * data items in a combobox stored in <i>data</i>. | |
90 * | |
91 * @param data The {@link Data} object. | |
92 * | |
93 * @return a combobox. | |
94 */ | |
95 public Canvas create(Data data) { | |
96 VLayout v = new VLayout(); | |
97 | |
98 Canvas content = createWidget(data); | |
99 | |
100 IButton button = new IButton(messages.next(), this); | |
101 //IButton button = new IButton(messages.next(), new ClickHandler() { | |
102 // public void onClick(ClickEvent e) { | |
103 // GWT.log("SelectProvider - feed and advance..."); | |
104 // Data[] data = getData(); | |
105 | |
106 // GWT.log("GO ON..."); | |
107 // SelectProvider.this.fireStepForwardEvent(new StepForwardEvent(data)); | |
108 // } | |
109 //}); | |
110 | |
111 v.addMember(content); | |
112 v.addMember(button); | |
113 | |
114 return v; | |
115 } | |
116 | |
117 | |
118 /** | |
119 * This method creates the content of the widget. | |
120 * | |
121 * @param data The {@link Data} object. | |
122 * | |
123 * @return a combobox. | |
124 */ | |
125 protected Canvas createWidget(Data data) { | |
126 GWT.log("SelectProvider - create()"); | |
127 | |
128 DynamicForm form = new DynamicForm(); | |
129 combobox = new ComboBoxItem("river"); | |
130 | |
131 LinkedHashMap<String, String> it = new LinkedHashMap<String, String>(); | |
132 | |
133 for (DataItem item: data.getItems()) { | |
134 GWT.log("Add item: " + item.getLabel()); | |
135 it.put(item.getStringValue(), item.getLabel()); | |
136 } | |
137 | |
138 combobox.setValueMap(it); | |
139 form.setItems(combobox); | |
140 | |
141 return form; | |
142 } | |
143 | |
144 | |
145 protected Data[] getData() { | |
146 String selection = combobox.getValueAsString(); | |
147 | |
148 GWT.log("SelectProvider - getData() Selected value = " + selection); | |
149 DataItem item = new DefaultDataItem("river", null, selection); | |
150 | |
151 return new Data[] { new DefaultData( | |
152 "river", null, null, new DataItem[] { item }, null) }; | |
153 } | |
154 } | |
155 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |