Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixLocationPanel.java @ 5834:f507086aa94b
Repaired internal references.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:31:32 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixLocationPanel.java@acfd48384835 |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.client.ui.fixation; | |
2 | |
3 import java.util.List; | |
4 import java.util.ArrayList; | |
5 | |
6 import com.google.gwt.core.client.GWT; | |
7 | |
8 import com.smartgwt.client.widgets.Canvas; | |
9 import com.smartgwt.client.widgets.Label; | |
10 | |
11 import com.smartgwt.client.widgets.layout.HLayout; | |
12 import com.smartgwt.client.widgets.layout.VLayout; | |
13 | |
14 import com.smartgwt.client.widgets.form.fields.FormItem; | |
15 import com.smartgwt.client.widgets.form.fields.events.BlurHandler; | |
16 import com.smartgwt.client.widgets.form.fields.events.BlurEvent; | |
17 | |
18 import de.intevation.flys.client.client.FLYSConstants; | |
19 import de.intevation.flys.client.client.ui.DoubleRangePanel; | |
20 | |
21 import de.intevation.flys.client.shared.model.Data; | |
22 import de.intevation.flys.client.shared.model.DataItem; | |
23 import de.intevation.flys.client.shared.model.DataList; | |
24 import de.intevation.flys.client.shared.model.DefaultData; | |
25 import de.intevation.flys.client.shared.model.DefaultDataItem; | |
26 /** | |
27 * This UIProvider creates a panel for location or distance input. | |
28 * | |
29 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
30 */ | |
31 public class FixLocationPanel | |
32 extends FixationPanel | |
33 implements BlurHandler | |
34 { | |
35 /** The message class that provides i18n strings. */ | |
36 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); | |
37 | |
38 /** The constant name of the input field to enter locations.*/ | |
39 public static final String FIELD_VALUE_LOCATION = "location"; | |
40 | |
41 /** The constant name of the input field to enter distance.*/ | |
42 public static final String FIELD_VALUE_DISTANCE = "distance"; | |
43 | |
44 DoubleRangePanel inputPanel; | |
45 | |
46 double from; | |
47 double to; | |
48 double step; | |
49 | |
50 public FixLocationPanel() { | |
51 htmlOverview = ""; | |
52 } | |
53 | |
54 public Canvas createWidget(DataList data) { | |
55 instances.put(this.artifact.getUuid(), this); | |
56 | |
57 VLayout layout = new VLayout(); | |
58 | |
59 Canvas title = new Label(MESSAGES.distance()); | |
60 title.setHeight("25px"); | |
61 | |
62 inputPanel = new DoubleRangePanel( | |
63 MESSAGES.unitFrom(), | |
64 MESSAGES.unitTo(), | |
65 MESSAGES.unitWidth(), | |
66 0d, | |
67 0d, | |
68 0d, | |
69 240, | |
70 this); | |
71 | |
72 layout.addMember(title); | |
73 layout.addMember(inputPanel); | |
74 return layout; | |
75 } | |
76 | |
77 @Override | |
78 public Canvas createOld(DataList dataList) { | |
79 List<Data> items = dataList.getAll(); | |
80 | |
81 Data f = getData(items, "ld_from"); | |
82 Data t = getData(items, "ld_to"); | |
83 Data s = getData(items, "ld_step"); | |
84 DataItem[] fItems = f.getItems(); | |
85 DataItem[] tItems = t.getItems(); | |
86 DataItem[] sItems = s.getItems(); | |
87 | |
88 StringBuilder sb = new StringBuilder(); | |
89 sb.append(fItems[0].getLabel()); | |
90 sb.append(" " + MESSAGES.unitFrom() + " "); | |
91 sb.append(tItems[0].getLabel()); | |
92 sb.append(" " + MESSAGES.unitTo() + " "); | |
93 sb.append(sItems[0].getLabel()); | |
94 sb.append(" " + MESSAGES.unitWidth()); | |
95 | |
96 Label old = new Label(sb.toString()); | |
97 old.setWidth(130); | |
98 | |
99 HLayout layout = new HLayout(); | |
100 layout.setWidth("400px"); | |
101 | |
102 Label label = new Label(dataList.getLabel()); | |
103 label.setWidth("200px"); | |
104 | |
105 Canvas back = getBackButton(dataList.getState()); | |
106 | |
107 layout.addMember(label); | |
108 layout.addMember(old); | |
109 layout.addMember(back); | |
110 | |
111 return layout; | |
112 } | |
113 | |
114 | |
115 /** | |
116 * This method returns the selected data. | |
117 * | |
118 * @return the selected/inserted data. | |
119 */ | |
120 public Data[] getData() { | |
121 List<Data> data = new ArrayList<Data>(); | |
122 | |
123 boolean valid = saveRangeValues(inputPanel); | |
124 if (valid) { | |
125 String f = Double.valueOf(this.from).toString(); | |
126 String t = Double.valueOf(this.to).toString(); | |
127 String s = Double.valueOf(this.step).toString(); | |
128 DataItem fi = new DefaultDataItem("ld_from", "ld_from", f); | |
129 DataItem ti = new DefaultDataItem("ld_to", "ld_to", t); | |
130 DataItem si = new DefaultDataItem("ld_step", "ld_step", s); | |
131 data.add(new DefaultData("ld_from", null, null, new DataItem[]{ fi })); | |
132 data.add(new DefaultData("ld_to", null, null, new DataItem[]{ ti })); | |
133 data.add(new DefaultData("ld_step", null, null, new DataItem[]{ si })); | |
134 } | |
135 // what else? | |
136 return data.toArray(new Data[data.size()]); | |
137 } | |
138 | |
139 | |
140 protected boolean saveRangeValues(DoubleRangePanel p) { | |
141 FormItem[] items = p.getFields(); | |
142 boolean valid = p.validateForm(); | |
143 | |
144 if(valid) { | |
145 this.from = p.getFrom(); | |
146 this.to = p.getTo(); | |
147 this.step = p.getStep(); | |
148 } | |
149 return valid; | |
150 } | |
151 | |
152 | |
153 @Override | |
154 public void setValues(String cid, boolean checked) { | |
155 // No user interaction, do nothing. | |
156 } | |
157 | |
158 | |
159 @Override | |
160 public boolean renderCheckboxes() { | |
161 // No selection, return false. | |
162 return false; | |
163 } | |
164 | |
165 | |
166 public void success() { | |
167 inputPanel.setValues(fixInfo.getFrom(), fixInfo.getTo(), 100d); | |
168 } | |
169 | |
170 /** | |
171 * This method is used to validate the inserted data in the form fields. | |
172 * | |
173 * @param event The BlurEvent that gives information about the FormItem that | |
174 * has been modified and its value. | |
175 */ | |
176 public void onBlur(BlurEvent event) { | |
177 FormItem item = event.getItem(); | |
178 String field = item.getFieldName(); | |
179 | |
180 if (field == null) { | |
181 return; | |
182 } | |
183 DoubleRangePanel p = (DoubleRangePanel) event.getForm(); | |
184 } | |
185 | |
186 | |
187 public void dumpGWT(String cid) { | |
188 GWT.log("Setting values for cId: " + cid); | |
189 GWT.log("River: " + fixInfo.getRiver()); | |
190 GWT.log("Date: " + fixInfo.getEventByCId(cid).getDate()); | |
191 GWT.log("Name: " + fixInfo.getEventByCId(cid).getDescription()); | |
192 } | |
193 } |