Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/WspDatacagePanel.java @ 909:794d1af42987
Clone Artifacts and add them to the current Collection in the WspDatacagePanel.
flys-client/trunk@2766 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 15 Sep 2011 16:02:23 +0000 |
parents | 3ef7205b814e |
children | d0500e993218 |
comparison
equal
deleted
inserted
replaced
908:a680ccec5dd6 | 909:794d1af42987 |
---|---|
1 package de.intevation.flys.client.client.ui; | 1 package de.intevation.flys.client.client.ui; |
2 | 2 |
3 import java.util.List; | |
4 import java.util.Map; | |
5 import java.util.Set; | |
6 | |
7 import com.google.gwt.core.client.GWT; | |
8 import com.google.gwt.user.client.rpc.AsyncCallback; | |
9 | |
10 import com.smartgwt.client.util.SC; | |
11 import com.smartgwt.client.widgets.events.ClickEvent; | |
12 | |
13 import de.intevation.flys.client.shared.model.Artifact; | |
14 import de.intevation.flys.client.shared.model.Collection; | |
3 import de.intevation.flys.client.shared.model.Data; | 15 import de.intevation.flys.client.shared.model.Data; |
4 import de.intevation.flys.client.shared.model.DataItem; | 16 import de.intevation.flys.client.shared.model.DataItem; |
5 import de.intevation.flys.client.shared.model.DefaultData; | 17 import de.intevation.flys.client.shared.model.DefaultData; |
6 import de.intevation.flys.client.shared.model.DefaultDataItem; | 18 import de.intevation.flys.client.shared.model.DefaultDataItem; |
19 import de.intevation.flys.client.shared.model.Recommendation; | |
20 import de.intevation.flys.client.shared.model.Recommendation.Facet; | |
21 import de.intevation.flys.client.shared.model.Recommendation.Filter; | |
22 import de.intevation.flys.client.shared.model.ToLoad; | |
7 import de.intevation.flys.client.shared.model.User; | 23 import de.intevation.flys.client.shared.model.User; |
24 | |
25 import de.intevation.flys.client.client.Config; | |
26 import de.intevation.flys.client.client.FLYSConstants; | |
27 import de.intevation.flys.client.client.event.StepForwardEvent; | |
28 import de.intevation.flys.client.client.services.LoadArtifactService; | |
29 import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; | |
8 | 30 |
9 | 31 |
10 public class WspDatacagePanel extends DatacagePanel { | 32 public class WspDatacagePanel extends DatacagePanel { |
11 | 33 |
12 public static final String WATERLEVEL_OUTS = "longitudinal_section"; | 34 public static final String WATERLEVEL_OUTS = "longitudinal_section"; |
35 | |
36 public static final FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
37 | |
38 | |
39 protected LoadArtifactServiceAsync loadService = | |
40 GWT.create(LoadArtifactService.class); | |
41 | |
42 protected Recommendation recommendation; | |
43 protected Artifact artifact; | |
13 | 44 |
14 | 45 |
15 public WspDatacagePanel() { | 46 public WspDatacagePanel() { |
16 super(); | 47 super(); |
17 } | 48 } |
26 public String getOuts() { | 57 public String getOuts() { |
27 return WATERLEVEL_OUTS; | 58 return WATERLEVEL_OUTS; |
28 } | 59 } |
29 | 60 |
30 | 61 |
62 /** | |
63 * We need to override this method (defined in AbstractUIProvider) because | |
64 * we have to create a new Artifact specified by the Datacage selection via | |
65 * Async request. | |
66 * | |
67 * @param The ClickEvent. | |
68 */ | |
69 @Override | |
70 public void onClick(ClickEvent e) { | |
71 List<String> errors = validate(); | |
72 if (errors == null || errors.isEmpty()) { | |
73 // 1) Fetch selected recommendation | |
74 Config config = Config.getInstance(); | |
75 final String url = config.getServerUrl(); | |
76 final String locale = config.getLocale(); | |
77 final Collection c = this.collection; | |
78 final Recommendation r = getSelectedRecommendation(); | |
79 | |
80 // 2) Create, load Artifact and fire event | |
81 loadService.load( | |
82 c, r, "winfo", url, locale, | |
83 new AsyncCallback<Artifact>() { | |
84 public void onFailure(Throwable caught) { | |
85 SC.warn(MSG.getString(caught.getMessage())); | |
86 } | |
87 | |
88 public void onSuccess(Artifact artifact) { | |
89 fireStepForwardEvent(new StepForwardEvent( | |
90 getData(r, artifact))); | |
91 } | |
92 } | |
93 ); | |
94 } | |
95 else { | |
96 showErrors(errors); | |
97 } | |
98 } | |
99 | |
100 | |
101 protected Recommendation getSelectedRecommendation() { | |
102 ToLoad toLoad = widget.getSelection(); | |
103 List<Recommendation> recoms = toLoad.toRecommendations(); | |
104 | |
105 return recoms.get(0); | |
106 } | |
107 | |
108 | |
109 /** | |
110 * Nothing is done in this method. It returns null, because we serve the | |
111 * Data another way! | |
112 * | |
113 * @return always null! | |
114 */ | |
31 @Override | 115 @Override |
32 protected Data[] getData() { | 116 protected Data[] getData() { |
33 String value = "TODO:FIND VALUE"; | 117 // do nothing here, the Data is fetched on another way in this panel. |
118 return null; | |
119 } | |
120 | |
121 | |
122 protected Data[] getData(Recommendation r, Artifact newArtifact) { | |
123 String uuid = newArtifact.getUuid(); | |
124 r.setMasterArtifact(uuid); | |
125 | |
126 String value = createDataString(uuid, r.getFilter()); | |
127 | |
34 DataItem item = new DefaultDataItem(dataName, dataName, value); | 128 DataItem item = new DefaultDataItem(dataName, dataName, value); |
35 return new Data[] { new DefaultData( | 129 return new Data[] { new DefaultData( |
36 dataName, null, null, new DataItem[] { item }) }; | 130 dataName, null, null, new DataItem[] { item }) }; |
37 } | 131 } |
132 | |
133 | |
134 protected String createDataString(String artifact, Filter filter) { | |
135 Facet f = null; | |
136 | |
137 Map<String, List<Facet>> outs = filter.getOuts(); | |
138 Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); | |
139 | |
140 for (Map.Entry<String, List<Facet>> entry: entries) { | |
141 List<Facet> fs = entry.getValue(); | |
142 | |
143 f = fs.get(0); | |
144 if (f != null) { | |
145 break; | |
146 } | |
147 } | |
148 | |
149 return "[" + artifact + ";" + f.getName() + ";" + f.getIndex() + "]"; | |
150 } | |
38 } | 151 } |
39 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 152 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |