comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixLocationPanel.java @ 2505:87ac5c532523

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

http://dive4elements.wald.intevation.org