comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixGaugeSelectPanel.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 import java.util.LinkedHashMap;
6
7 import java.lang.NumberFormatException;
8
9 import com.google.gwt.core.client.GWT;
10
11 import com.smartgwt.client.widgets.Canvas;
12 import com.smartgwt.client.widgets.Label;
13
14 import com.smartgwt.client.widgets.layout.HLayout;
15 import com.smartgwt.client.widgets.layout.VLayout;
16
17 import com.smartgwt.client.widgets.form.DynamicForm;
18 import com.smartgwt.client.widgets.form.fields.SelectItem;
19 import com.smartgwt.client.widgets.form.fields.StaticTextItem;
20
21 import de.intevation.flys.client.client.FLYSConstants;
22
23 import de.intevation.flys.client.shared.model.Data;
24 import de.intevation.flys.client.shared.model.DataItem;
25 import de.intevation.flys.client.shared.model.DataList;
26 import de.intevation.flys.client.shared.model.DefaultData;
27 import de.intevation.flys.client.shared.model.DefaultDataItem;
28
29 /**
30 * This UIProvider creates a panel for location or distance input.
31 *
32 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
33 */
34 public class FixGaugeSelectPanel
35 extends FixationPanel
36 {
37 /** The message class that provides i18n strings. */
38 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);
39
40 protected String first;
41 protected String second;
42
43 protected SelectItem from;
44 protected SelectItem to;
45
46 public FixGaugeSelectPanel() {
47 htmlOverview = "";
48 }
49
50 public Canvas createWidget(DataList data) {
51 instances.put(this.artifact.getUuid(), this);
52
53 VLayout layout = new VLayout();
54
55 Label title = new Label(MESSAGES.gauge_class());
56 title.setHeight(25);
57
58 LinkedHashMap map = new LinkedHashMap();
59 map.put("0", "0");
60 map.put("1", "1");
61 map.put("2", "2");
62 map.put("3", "3");
63
64 from = new SelectItem(MESSAGES.from());
65 to = new SelectItem(MESSAGES.to());
66
67 from.setShowTitle(false);
68 to.setShowTitle(false);
69 from.setValueMap(map);
70 from.setWidth(60);
71 to.setValueMap(map);
72 to.setWidth(60);
73
74 DynamicForm form = new DynamicForm();
75 StaticTextItem separator = new StaticTextItem("separator");
76 separator.setShowTitle(false);
77 separator.setValue(MESSAGES.to());
78 form.setNumCols(5);
79 form.setFields(from, separator, to);
80
81 layout.addMember(title);
82 layout.addMember(form);
83
84 return layout;
85 }
86
87 @Override
88 public Canvas createOld(DataList dataList) {
89 List<Data> items = dataList.getAll();
90
91 Data f = getData(items, "q1");
92 Data t = getData(items, "q2");
93 DataItem[] fItems = f.getItems();
94 DataItem[] tItems = t.getItems();
95
96 StringBuilder sb = new StringBuilder();
97 sb.append(fItems[0].getLabel());
98 sb.append(" " + MESSAGES.to() + " ");
99 sb.append(tItems[0].getLabel());
100
101 Label old = new Label(sb.toString());
102 old.setWidth(130);
103
104 HLayout layout = new HLayout();
105 layout.setWidth("400px");
106 Label label = new Label(dataList.getLabel());
107 label.setWidth("200px");
108
109 Canvas back = getBackButton(dataList.getState());
110
111 layout.addMember(label);
112 layout.addMember(old);
113 layout.addMember(back);
114 return layout;
115 }
116
117
118 /**
119 * This method returns the selected data.
120 *
121 * @return the selected/inserted data.
122 */
123 public Data[] getData() {
124 List<Data> data = new ArrayList<Data>();
125
126 boolean valid = saveClassValues();
127 if (valid) {
128 DataItem firstItem = new DefaultDataItem("q1", "q1", this.first);
129 DataItem secItem = new DefaultDataItem("q2", "q2", this.second);
130 data.add(new DefaultData(
131 "q1",
132 null,
133 null,
134 new DataItem[] { firstItem }));
135 data.add(new DefaultData(
136 "q2",
137 null,
138 null,
139 new DataItem[] { secItem }));
140 }
141 return (Data[]) data.toArray(new Data[data.size()]);
142 }
143
144
145 @Override
146 public void setValues(String cid, boolean checked) {
147 // No user interaction, do nothing.
148 }
149
150
151 @Override
152 public boolean renderCheckboxes() {
153 // No selection, return false.
154 return false;
155 }
156
157
158 protected boolean saveClassValues() {
159 String v1 = from.getValueAsString();
160 String v2 = to.getValueAsString();
161 try {
162 int v1i = Integer.valueOf(v1).intValue();
163 int v2i = Integer.valueOf(v2).intValue();
164 if (v1i <= v2i) {
165 this.first = v1;
166 this.second = v2;
167 return true;
168 }
169 }
170 catch(NumberFormatException nfe) {
171 return false;
172 }
173 return false;
174 }
175 }

http://dive4elements.wald.intevation.org