Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/SedLoadEpochPanel.java @ 4223:015b219a97af
Added new UI provider for sediment load parameter input.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 23 Oct 2012 13:21:57 +0200 |
parents | |
children | abd304085bd4 |
comparison
equal
deleted
inserted
replaced
4222:94c76129af7d | 4223:015b219a97af |
---|---|
1 package de.intevation.flys.client.client.ui.minfo; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import com.google.gwt.core.client.GWT; | |
7 import com.smartgwt.client.data.Record; | |
8 import com.smartgwt.client.types.ListGridFieldType; | |
9 import com.smartgwt.client.widgets.Button; | |
10 import com.smartgwt.client.widgets.Canvas; | |
11 import com.smartgwt.client.widgets.Label; | |
12 import com.smartgwt.client.widgets.events.ClickEvent; | |
13 import com.smartgwt.client.widgets.events.ClickHandler; | |
14 import com.smartgwt.client.widgets.form.DynamicForm; | |
15 import com.smartgwt.client.widgets.form.fields.TextItem; | |
16 import com.smartgwt.client.widgets.form.validator.IsIntegerValidator; | |
17 import com.smartgwt.client.widgets.grid.ListGrid; | |
18 import com.smartgwt.client.widgets.grid.ListGridField; | |
19 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
20 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; | |
21 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; | |
22 import com.smartgwt.client.widgets.layout.HLayout; | |
23 import com.smartgwt.client.widgets.layout.VLayout; | |
24 | |
25 import de.intevation.flys.client.client.ui.AbstractUIProvider; | |
26 import de.intevation.flys.client.shared.model.Data; | |
27 import de.intevation.flys.client.shared.model.DataItem; | |
28 import de.intevation.flys.client.shared.model.DataList; | |
29 import de.intevation.flys.client.shared.model.DefaultData; | |
30 import de.intevation.flys.client.shared.model.DefaultDataItem; | |
31 | |
32 | |
33 public class SedLoadEpochPanel | |
34 extends AbstractUIProvider | |
35 { | |
36 protected ListGrid elements; | |
37 private TextItem start; | |
38 private TextItem end; | |
39 | |
40 public Canvas createWidget(DataList data) { | |
41 HLayout input = new HLayout(); | |
42 VLayout root = new VLayout(); | |
43 VLayout grid = new VLayout(); | |
44 VLayout intFields = new VLayout(); | |
45 Button add = new Button(MSG.add_date()); | |
46 elements = new ListGrid(); | |
47 | |
48 Label title = new Label(data.get(0).getDescription()); | |
49 title.setHeight("25px"); | |
50 | |
51 DynamicForm form = new DynamicForm(); | |
52 form.setNumCols(4); | |
53 start = new TextItem(MSG.from()); | |
54 start.setWidth(60); | |
55 start.setValidators(new IsIntegerValidator()); | |
56 end = new TextItem(MSG.to()); | |
57 end.setWidth(60); | |
58 end.setValidators(new IsIntegerValidator()); | |
59 form.setFields(start, end); | |
60 add.addClickHandler(new ClickHandler() { | |
61 @Override | |
62 public void onClick(ClickEvent ce) { | |
63 String v1 = start.getValueAsString(); | |
64 String v2 = end.getValueAsString(); | |
65 //TODO: better validation. | |
66 if (v1 == null || v2 == null) { | |
67 return; | |
68 } | |
69 try { | |
70 int v1i = Integer.parseInt(v1); | |
71 int v2i = Integer.parseInt(v2); | |
72 } | |
73 catch(NumberFormatException nfe) { | |
74 return; | |
75 } | |
76 Record r = new Record(); | |
77 r.setAttribute("from", v1); | |
78 r.setAttribute("to", v2); | |
79 elements.addData(r); | |
80 } | |
81 }); | |
82 | |
83 Label sel = new Label(MSG.select()); | |
84 sel.setHeight(25); | |
85 elements.setWidth(185); | |
86 elements.setHeight(120); | |
87 elements.setShowHeaderContextMenu(false); | |
88 elements.setCanReorderFields(false); | |
89 elements.setCanSort(false); | |
90 elements.setCanEdit(false); | |
91 ListGridField from = new ListGridField("from", MSG.from()); | |
92 ListGridField to = new ListGridField("to", MSG.to()); | |
93 from.setWidth(70); | |
94 to.setWidth(70); | |
95 | |
96 final ListGridField removeField = | |
97 new ListGridField("_removeRecord", "Remove Record"){{ | |
98 setType(ListGridFieldType.ICON); | |
99 setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); | |
100 setCanEdit(false); | |
101 setCanFilter(false); | |
102 setCanSort(false); | |
103 setCanGroupBy(false); | |
104 setCanFreeze(false); | |
105 setWidth(25); | |
106 }}; | |
107 | |
108 elements.addRecordClickHandler(new RecordClickHandler() { | |
109 @Override | |
110 public void onRecordClick(final RecordClickEvent event) { | |
111 // Just handle remove-clicks | |
112 if(!event.getField().getName().equals(removeField.getName())) { | |
113 return; | |
114 } | |
115 event.getViewer().removeData(event.getRecord()); | |
116 } | |
117 }); | |
118 | |
119 elements.setFields(from, to, removeField); | |
120 | |
121 intFields.addMember(form); | |
122 intFields.addMember(add); | |
123 grid.addMember(sel); | |
124 grid.addMember(elements); | |
125 input.addMember(intFields); | |
126 input.addMember(grid); | |
127 root.addMember(title); | |
128 root.addMember(input); | |
129 | |
130 return root; | |
131 } | |
132 @Override | |
133 public Canvas createOld(DataList dataList) { | |
134 GWT.log("old............................"); | |
135 HLayout layout = new HLayout(); | |
136 layout.setWidth("400px"); | |
137 VLayout vLayout = new VLayout(); | |
138 vLayout.setWidth(130); | |
139 Label label = new Label(dataList.getLabel()); | |
140 label.setWidth("200px"); | |
141 label.setHeight(25); | |
142 | |
143 List<Data> items = dataList.getAll(); | |
144 Data str = getData(items, "epochs"); | |
145 DataItem[] strItems = str.getItems(); | |
146 | |
147 String[] pairs = strItems[0].getLabel().split(";"); | |
148 for (int i = 0; i < pairs.length; i++) { | |
149 String[] vals = pairs[i].split(","); | |
150 Label dateLabel = new Label(vals[0] + " - " + vals[1]); | |
151 dateLabel.setHeight(20); | |
152 vLayout.addMember(dateLabel); | |
153 } | |
154 Canvas back = getBackButton(dataList.getState()); | |
155 layout.addMember(label); | |
156 layout.addMember(vLayout); | |
157 layout.addMember(back); | |
158 | |
159 return layout; | |
160 } | |
161 | |
162 @Override | |
163 public Canvas create(DataList data) { | |
164 VLayout layout = new VLayout(); | |
165 Canvas submit = getNextButton(); | |
166 Canvas widget = createWidget(data); | |
167 | |
168 layout.addMember(widget); | |
169 layout.addMember(submit); | |
170 return layout; | |
171 } | |
172 | |
173 @Override | |
174 protected Data[] getData() { | |
175 List<Data> data = new ArrayList<Data>(); | |
176 | |
177 ListGridRecord[] lgr = elements.getRecords(); | |
178 if (lgr.length == 0) { | |
179 return new Data[0]; | |
180 } | |
181 String d = ""; | |
182 for (int i = 0; i < lgr.length; i++) { | |
183 Record r = (Record) lgr[i]; | |
184 d += r.getAttribute("from") + "," + r.getAttribute("to"); | |
185 d += ";"; | |
186 } | |
187 | |
188 DataItem item = new DefaultDataItem("epochs", null, d); | |
189 data.add(new DefaultData( | |
190 "epochs", | |
191 null, | |
192 null, | |
193 new DataItem[] { item })); | |
194 return data.toArray(new Data[data.size()]); | |
195 } | |
196 | |
197 } |