Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WspDatacagePanel.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-client/src/main/java/org/dive4elements/river/client/client/ui/WspDatacagePanel.java@821a02bbfb4e |
children | 172338b1407f |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.client.client.ui; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 import com.google.gwt.user.client.rpc.AsyncCallback; | |
5 | |
6 import com.smartgwt.client.util.SC; | |
7 import com.smartgwt.client.widgets.events.ClickEvent; | |
8 | |
9 import org.dive4elements.river.client.client.Config; | |
10 import org.dive4elements.river.client.client.FLYS; | |
11 import org.dive4elements.river.client.client.FLYSConstants; | |
12 import org.dive4elements.river.client.client.event.StepForwardEvent; | |
13 import org.dive4elements.river.client.client.services.LoadArtifactService; | |
14 import org.dive4elements.river.client.client.services.LoadArtifactServiceAsync; | |
15 import org.dive4elements.river.client.shared.model.Artifact; | |
16 import org.dive4elements.river.client.shared.model.Collection; | |
17 import org.dive4elements.river.client.shared.model.Data; | |
18 import org.dive4elements.river.client.shared.model.DataItem; | |
19 import org.dive4elements.river.client.shared.model.DefaultData; | |
20 import org.dive4elements.river.client.shared.model.DefaultDataItem; | |
21 import org.dive4elements.river.client.shared.model.Recommendation; | |
22 import org.dive4elements.river.client.shared.model.Recommendation.Facet; | |
23 import org.dive4elements.river.client.shared.model.Recommendation.Filter; | |
24 import org.dive4elements.river.client.shared.model.ToLoad; | |
25 import org.dive4elements.river.client.shared.model.User; | |
26 | |
27 import java.util.List; | |
28 import java.util.Map; | |
29 import java.util.Set; | |
30 | |
31 | |
32 public class WspDatacagePanel extends DatacagePanel { | |
33 | |
34 private static final long serialVersionUID = 2494432743877141135L; | |
35 | |
36 public static final String WATERLEVEL_OUTS = "waterlevels"; | |
37 | |
38 public static final FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
39 | |
40 | |
41 protected LoadArtifactServiceAsync loadService = | |
42 GWT.create(LoadArtifactService.class); | |
43 | |
44 protected Recommendation recommendation; | |
45 protected Artifact artifact; | |
46 | |
47 | |
48 public WspDatacagePanel() { | |
49 super(); | |
50 } | |
51 | |
52 | |
53 public WspDatacagePanel(User user) { | |
54 super(user); | |
55 } | |
56 | |
57 | |
58 @Override | |
59 public String getOuts() { | |
60 return WATERLEVEL_OUTS; | |
61 } | |
62 | |
63 | |
64 @Override | |
65 protected void createWidget() { | |
66 super.createWidget(); | |
67 widget.setIsMutliSelectable(false); | |
68 } | |
69 | |
70 | |
71 /** | |
72 * We need to override this method (defined in AbstractUIProvider) because | |
73 * we have to create a new Artifact specified by the Datacage selection via | |
74 * Async request. | |
75 * | |
76 * @param e The ClickEvent. | |
77 */ | |
78 @Override | |
79 public void onClick(ClickEvent e) { | |
80 List<String> errors = validate(); | |
81 if (errors == null || errors.isEmpty()) { | |
82 // 1) Fetch selected recommendation | |
83 Config config = Config.getInstance(); | |
84 final String locale = config.getLocale(); | |
85 final Collection c = this.collection; | |
86 final Recommendation r = getSelectedRecommendation(); | |
87 | |
88 | |
89 if (r == null) { | |
90 SC.warn(MSG.warning_no_wsp_selected()); | |
91 return; | |
92 } | |
93 | |
94 // 2) Create, load Artifact and fire event | |
95 loadService.load( | |
96 c, r, "winfo", locale, | |
97 new AsyncCallback<Artifact>() { | |
98 @Override | |
99 public void onFailure(Throwable caught) { | |
100 GWT.log("WspDatacagePanel", caught); | |
101 SC.warn(FLYS.getExceptionString(MSG, caught)); | |
102 } | |
103 | |
104 @Override | |
105 public void onSuccess(Artifact artifact) { | |
106 fireStepForwardEvent(new StepForwardEvent( | |
107 getData(r, artifact))); | |
108 } | |
109 } | |
110 ); | |
111 } | |
112 else { | |
113 showErrors(errors); | |
114 } | |
115 } | |
116 | |
117 | |
118 protected Recommendation getSelectedRecommendation() { | |
119 ToLoad toLoad = widget.getSelection(); | |
120 List<Recommendation> recoms = toLoad.toRecommendations(); | |
121 | |
122 return recoms.size() > 0 ? recoms.get(0) : null; | |
123 } | |
124 | |
125 | |
126 /** | |
127 * Nothing is done in this method. It returns null, because we serve the | |
128 * Data another way! | |
129 * | |
130 * @return always null! | |
131 */ | |
132 @Override | |
133 protected Data[] getData() { | |
134 // do nothing here, the Data is fetched on another way in this panel. | |
135 return null; | |
136 } | |
137 | |
138 | |
139 protected Data[] getData(Recommendation r, Artifact newArtifact) { | |
140 String uuid = newArtifact.getUuid(); | |
141 r.setMasterArtifact(uuid); | |
142 | |
143 String value = createDataString(uuid, r.getFilter()); | |
144 | |
145 DataItem item = new DefaultDataItem(dataName, dataName, value); | |
146 return new Data[] { new DefaultData( | |
147 dataName, null, null, new DataItem[] { item }) }; | |
148 } | |
149 | |
150 | |
151 protected String createDataString(String artifact, Filter filter) { | |
152 Facet f = null; | |
153 | |
154 Map<String, List<Facet>> outs = filter.getOuts(); | |
155 Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); | |
156 | |
157 for (Map.Entry<String, List<Facet>> entry: entries) { | |
158 List<Facet> fs = entry.getValue(); | |
159 | |
160 f = fs.get(0); | |
161 if (f != null) { | |
162 break; | |
163 } | |
164 } | |
165 | |
166 return "[" + artifact + ";" + f.getName() + ";" + f.getIndex() + "]"; | |
167 } | |
168 } | |
169 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |