Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageTwinPanel.java @ 914:39a39e9be5af
Made DatacageTwinPanel somewhat usable.
flys-client/trunk@2775 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 16 Sep 2011 11:21:38 +0000 |
parents | 6a2ed979dfcf |
children | b48c36076e17 |
comparison
equal
deleted
inserted
replaced
913:9976d99aea34 | 914:39a39e9be5af |
---|---|
1 package de.intevation.flys.client.client.ui; | 1 package de.intevation.flys.client.client.ui; |
2 | 2 |
3 import java.util.ArrayList; | |
4 import java.util.Map; | |
5 import java.util.List; | |
6 import java.util.Set; | |
7 | |
3 import com.google.gwt.core.client.GWT; | 8 import com.google.gwt.core.client.GWT; |
9 import com.google.gwt.user.client.rpc.AsyncCallback; | |
4 | 10 |
5 import com.smartgwt.client.widgets.Canvas; | 11 import com.smartgwt.client.widgets.Canvas; |
6 import com.smartgwt.client.widgets.Label; | 12 import com.smartgwt.client.widgets.Label; |
7 import com.smartgwt.client.widgets.layout.HLayout; | 13 import com.smartgwt.client.widgets.layout.HLayout; |
8 import com.smartgwt.client.widgets.layout.VLayout; | 14 import com.smartgwt.client.widgets.layout.VLayout; |
9 | 15 import com.smartgwt.client.widgets.grid.ListGrid; |
16 import com.smartgwt.client.widgets.grid.ListGridField; | |
17 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
18 import com.smartgwt.client.widgets.events.ClickEvent; | |
19 | |
20 import de.intevation.flys.client.shared.model.Artifact; | |
10 import de.intevation.flys.client.shared.model.Data; | 21 import de.intevation.flys.client.shared.model.Data; |
11 import de.intevation.flys.client.shared.model.DataItem; | 22 import de.intevation.flys.client.shared.model.DataItem; |
12 import de.intevation.flys.client.shared.model.DefaultData; | 23 import de.intevation.flys.client.shared.model.DefaultData; |
13 import de.intevation.flys.client.shared.model.DefaultDataItem; | 24 import de.intevation.flys.client.shared.model.DefaultDataItem; |
14 import de.intevation.flys.client.shared.model.DataList; | 25 import de.intevation.flys.client.shared.model.DataList; |
15 import de.intevation.flys.client.shared.model.User; | 26 import de.intevation.flys.client.shared.model.User; |
16 | 27 |
17 import de.intevation.flys.client.client.FLYSConstants; | 28 import de.intevation.flys.client.client.FLYSConstants; |
29 import de.intevation.flys.client.client.event.DatacageHandler; | |
30 import de.intevation.flys.client.client.event.StepForwardEvent; | |
31 import de.intevation.flys.client.shared.model.Recommendation; | |
32 import de.intevation.flys.client.shared.model.ToLoad; | |
33 import de.intevation.flys.client.shared.model.Recommendation.Facet; | |
34 import de.intevation.flys.client.shared.model.Recommendation.Filter; | |
35 | |
36 import de.intevation.flys.client.client.services.LoadArtifactService; | |
37 import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; | |
38 import de.intevation.flys.client.client.Config; | |
18 | 39 |
19 // TODO Probably better to branch off AbstractUIProvider. | 40 // TODO Probably better to branch off AbstractUIProvider. |
20 public class DatacageTwinPanel extends TextProvider { | 41 // TODO Merge with other datacage-widget impls. |
42 /** | |
43 * Panel containing a Grid and a "next" button. The Grid is fed by a | |
44 * DatacagePairWidget which is put in the input-helper area. | |
45 */ | |
46 public class DatacageTwinPanel | |
47 extends TextProvider { | |
21 | 48 |
22 protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); | 49 protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); |
23 | 50 |
24 protected String dataName; | 51 protected String dataName; |
25 | 52 |
26 protected User user; | 53 protected User user; |
54 | |
55 protected ToLoad toLoad1; | |
56 | |
57 protected ToLoad toLoad2; | |
58 | |
59 protected ListGrid differencesList; | |
60 | |
61 LoadArtifactServiceAsync loadArtifactService = GWT.create( | |
62 de.intevation.flys.client.client.services.LoadArtifactService.class); | |
27 | 63 |
28 | 64 |
29 public DatacageTwinPanel(User user) { | 65 public DatacageTwinPanel(User user) { |
30 super(); | 66 super(); |
31 this.user = user; | 67 this.user = user; |
41 Canvas label = new Label(data.getDescription()); | 77 Canvas label = new Label(data.getDescription()); |
42 Canvas widget = createWidget(); | 78 Canvas widget = createWidget(); |
43 Canvas submit = getNextButton(); | 79 Canvas submit = getNextButton(); |
44 | 80 |
45 VLayout layout = new VLayout(); | 81 VLayout layout = new VLayout(); |
82 HLayout helperLayout = new HLayout(); | |
46 label.setHeight(50); | 83 label.setHeight(50); |
47 DatacageWidget baseDataCage = new DatacageWidget(this.artifact, user); | 84 helperLayout.addMember(new DatacagePairWidget(this.artifact, |
48 DatacageWidget modDataCage = new DatacageWidget(this.artifact, user); | 85 user, "longitudinal_section", differencesList)); |
49 baseDataCage.setHeight(250); | |
50 modDataCage.setHeight(250); | |
51 layout.addMember(baseDataCage); | |
52 layout.addMember(modDataCage); | |
53 | 86 |
54 /*layout.addMember(label);*/ | 87 /*layout.addMember(label);*/ |
55 layout.addMember(widget); | 88 layout.addMember(widget); |
56 layout.addMember(submit); | 89 layout.addMember(submit); |
57 layout.setMembersMargin(10); | 90 layout.setMembersMargin(10); |
58 this.helperContainer.addMember(layout); | 91 this.helperContainer.addMember(helperLayout); |
59 | 92 |
60 // return layout; | 93 return layout; |
61 return new VLayout(); | 94 } |
95 | |
96 | |
97 @Override | |
98 public List<String> validate() { | |
99 List<String> errors = new ArrayList<String>(); | |
100 if (differencesList.getRecords().length == 0) { | |
101 // TODO i18n of error message. (MSG.no_waterlevel_pair_selected()) | |
102 errors.add("No pair of waterlevel items selected"); | |
103 } | |
104 | |
105 return errors; | |
62 } | 106 } |
63 | 107 |
64 | 108 |
65 public Canvas createWidget() { | 109 public Canvas createWidget() { |
66 HLayout layout = new HLayout(); | 110 VLayout layout = new VLayout(); |
67 layout.setMembersMargin(10); | 111 |
68 | 112 differencesList = new ListGrid(); |
69 layout.addMember(createForm()); | 113 differencesList.setHeight(150); |
70 layout.addMember(new DatacageWidget()); | 114 differencesList.setShowAllRecords(true); |
71 // TODO: fetch current user! | 115 differencesList.setCanEdit(false); |
72 // TODO: fetch collection view! | 116 |
73 /*layout.addMember( | 117 ListGridField nameField = new ListGridField("first", "Minuend"); |
74 new DatacageButton( | 118 ListGridField capitalField = new ListGridField("second", "Subtrahend"); |
75 MSG.databasket(), artifact, null, null)); | 119 differencesList.setFields(new ListGridField[] {nameField, capitalField}); |
76 */ | 120 |
121 layout.addMember(differencesList); | |
77 | 122 |
78 return layout; | 123 return layout; |
79 } | 124 } |
80 | 125 |
81 | 126 |
82 @Override | 127 @Override |
128 public void onClick(ClickEvent e) { | |
129 /* | |
130 TODO: Validation/Error | |
131 List<String> errors = validate(); | |
132 if (errors == null || errors.isEmpty()) { | |
133 ... | |
134 else {showErrors(errors);} | |
135 | |
136 * */ | |
137 GWT.log("DatacageTwinPanel.onClick"); | |
138 Config config = Config.getInstance(); | |
139 ListGridRecord[] records = differencesList.getRecords(); | |
140 ArrayList<Recommendation> ar = new ArrayList<Recommendation>(); | |
141 for (ListGridRecord record : records) { | |
142 DatacagePairWidget.RecommendationPairRecord r = | |
143 (DatacagePairWidget.RecommendationPairRecord) record; | |
144 ar.add(r.getFirst()); | |
145 ar.add(r.getSecond()); | |
146 } | |
147 final Recommendation[] rs = ar.toArray(new Recommendation[ar.size()]); | |
148 loadArtifactService.loadMany( | |
149 this.collection, | |
150 rs, | |
151 "winfo", | |
152 config.getServerUrl(), | |
153 config.getLocale(), | |
154 new AsyncCallback<Artifact[]>() { | |
155 public void onFailure(Throwable caught) { | |
156 GWT.log("No success in cloning Thing!"); | |
157 } | |
158 public void onSuccess(Artifact[] artifacts) { | |
159 GWT.log("Success of cloning thing!"); | |
160 fireStepForwardEvent(new StepForwardEvent( | |
161 getData(rs, artifacts))); | |
162 } } | |
163 ); | |
164 } | |
165 | |
166 | |
167 protected Data[] getData(Recommendation[] rs, Artifact[] newArtifacts) { | |
168 // Construct string with info about selections. | |
169 String dataItemString = ""; | |
170 for (int i = 0; i < rs.length; i++) { | |
171 Recommendation r = rs[i]; | |
172 Artifact newArtifact = newArtifacts[i]; | |
173 String uuid = newArtifact.getUuid(); | |
174 r.setMasterArtifact(uuid); | |
175 if (i>0) dataItemString += "#"; | |
176 | |
177 dataItemString += createDataString(uuid, r.getFilter()); | |
178 } | |
179 DataItem item = new DefaultDataItem(dataName, dataName, dataItemString); | |
180 return new Data[] { new DefaultData( | |
181 dataName, null, null, new DataItem[] {item}) }; | |
182 } | |
183 | |
184 | |
185 protected String createDataString(String artifact, Filter filter) { | |
186 Facet f = null; | |
187 | |
188 Map<String, List<Facet>> outs = filter.getOuts(); | |
189 Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); | |
190 | |
191 for (Map.Entry<String, List<Facet>> entry: entries) { | |
192 List<Facet> fs = entry.getValue(); | |
193 | |
194 f = fs.get(0); | |
195 if (f != null) { | |
196 break; | |
197 } | |
198 } | |
199 | |
200 return "[" + artifact + ";" + f.getName() + ";" + f.getIndex() + "]"; | |
201 } | |
202 | |
203 /*@Override | |
83 protected Data[] getData() { | 204 protected Data[] getData() { |
84 String value = "TODO:FIND VALUE"; | 205 // TODO ToLoadRecord ! |
85 DataItem item = new DefaultDataItem(dataName, dataName, value); | 206 String value = "TODO:FIND VALUE"; |
207 if (toLoad1 != null) { | |
208 List<Recommendation> recommendations = toLoad1.toRecommendations(); | |
209 value = recommendations.get(0).getIDs(); | |
210 } | |
211 DataItem item1 = new DefaultDataItem(dataName, dataName, value); | |
212 DataItem item2 = new DefaultDataItem(dataName, dataName, value); | |
86 return new Data[] { new DefaultData( | 213 return new Data[] { new DefaultData( |
87 dataName, null, null, new DataItem[] { item }) }; | 214 dataName, null, null, new DataItem[] { item1, item2}) }; |
88 } | 215 }*/ |
89 } | 216 } |
90 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 217 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |