Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WspDatacagePanel.java @ 9220:e3c2ae1887e8
Allow to filter contents of datacage on client side.
Allow to override column label of datacage
Some code cleanup
author | gernotbelger |
---|---|
date | Wed, 04 Jul 2018 12:00:51 +0200 |
parents | 5e38e2924c07 |
children |
comparison
equal
deleted
inserted
replaced
9219:8642a76f22be | 9220:e3c2ae1887e8 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.client.client.ui; | 9 package org.dive4elements.river.client.client.ui; |
10 | 10 |
11 import com.google.gwt.core.client.GWT; | 11 import java.util.List; |
12 import com.google.gwt.user.client.rpc.AsyncCallback; | 12 import java.util.Map; |
13 | 13 import java.util.Set; |
14 import com.smartgwt.client.util.SC; | |
15 import com.smartgwt.client.widgets.events.ClickEvent; | |
16 | 14 |
17 import org.dive4elements.river.client.client.Config; | 15 import org.dive4elements.river.client.client.Config; |
18 import org.dive4elements.river.client.client.FLYS; | 16 import org.dive4elements.river.client.client.FLYS; |
19 import org.dive4elements.river.client.client.FLYSConstants; | |
20 import org.dive4elements.river.client.client.event.StepForwardEvent; | 17 import org.dive4elements.river.client.client.event.StepForwardEvent; |
21 import org.dive4elements.river.client.client.services.LoadArtifactService; | 18 import org.dive4elements.river.client.client.services.LoadArtifactService; |
22 import org.dive4elements.river.client.client.services.LoadArtifactServiceAsync; | 19 import org.dive4elements.river.client.client.services.LoadArtifactServiceAsync; |
23 import org.dive4elements.river.client.shared.model.Artifact; | 20 import org.dive4elements.river.client.shared.model.Artifact; |
24 import org.dive4elements.river.client.shared.model.Collection; | 21 import org.dive4elements.river.client.shared.model.Collection; |
30 import org.dive4elements.river.client.shared.model.Recommendation.Facet; | 27 import org.dive4elements.river.client.shared.model.Recommendation.Facet; |
31 import org.dive4elements.river.client.shared.model.Recommendation.Filter; | 28 import org.dive4elements.river.client.shared.model.Recommendation.Filter; |
32 import org.dive4elements.river.client.shared.model.ToLoad; | 29 import org.dive4elements.river.client.shared.model.ToLoad; |
33 import org.dive4elements.river.client.shared.model.User; | 30 import org.dive4elements.river.client.shared.model.User; |
34 | 31 |
35 import java.util.List; | 32 import com.google.gwt.core.client.GWT; |
36 import java.util.Map; | 33 import com.google.gwt.user.client.rpc.AsyncCallback; |
37 import java.util.Set; | 34 import com.smartgwt.client.util.SC; |
38 | 35 import com.smartgwt.client.widgets.events.ClickEvent; |
39 | 36 |
40 public class WspDatacagePanel extends DatacagePanel { | 37 public class WspDatacagePanel extends DatacagePanel { |
41 | 38 |
42 private static final long serialVersionUID = 2494432743877141135L; | 39 private static final long serialVersionUID = 2494432743877141135L; |
43 | 40 |
44 public static final String WATERLEVEL_OUTS = "waterlevels_panel"; | 41 private static final String WATERLEVEL_OUTS = "waterlevels_panel"; |
45 | 42 |
46 public static final FLYSConstants MSG = GWT.create(FLYSConstants.class); | 43 private final LoadArtifactServiceAsync loadService = GWT.create(LoadArtifactService.class); |
47 | 44 |
48 | 45 public WspDatacagePanel(final User user) { |
49 protected LoadArtifactServiceAsync loadService = | 46 super(user, WATERLEVEL_OUTS, null, false); |
50 GWT.create(LoadArtifactService.class); | |
51 | |
52 protected Recommendation recommendation; | |
53 protected Artifact artifact; | |
54 | |
55 | |
56 public WspDatacagePanel() { | |
57 super(); | |
58 } | 47 } |
59 | |
60 | |
61 public WspDatacagePanel(User user) { | |
62 super(user); | |
63 } | |
64 | |
65 | |
66 @Override | |
67 public String getOuts() { | |
68 return WATERLEVEL_OUTS; | |
69 } | |
70 | |
71 | |
72 @Override | |
73 protected void createWidget() { | |
74 super.createWidget(); | |
75 widget.setIsMutliSelectable(false); | |
76 } | |
77 | |
78 | 48 |
79 /** | 49 /** |
80 * We need to override this method (defined in AbstractUIProvider) because | 50 * We need to override this method (defined in AbstractUIProvider) because |
81 * we have to create a new Artifact specified by the Datacage selection via | 51 * we have to create a new Artifact specified by the Datacage selection via |
82 * Async request. | 52 * Async request. |
83 * | 53 * |
84 * @param e The ClickEvent. | 54 * @param e |
55 * The ClickEvent. | |
85 */ | 56 */ |
86 @Override | 57 @Override |
87 public void onClick(ClickEvent e) { | 58 public void onClick(final ClickEvent e) { |
88 List<String> errors = validate(); | 59 final List<String> errors = validate(); |
89 if (errors == null || errors.isEmpty()) { | 60 if (errors == null || errors.isEmpty()) { |
90 // 1) Fetch selected recommendation. | 61 // 1) Fetch selected recommendation. |
91 Config config = Config.getInstance(); | 62 final Config config = Config.getInstance(); |
92 final String locale = config.getLocale(); | 63 final String locale = config.getLocale(); |
93 final Collection c = this.collection; | 64 final Collection c = this.collection; |
94 final Recommendation r = getSelectedRecommendation(); | 65 final Recommendation r = getSelectedRecommendation(); |
95 | |
96 | 66 |
97 if (r == null) { | 67 if (r == null) { |
98 SC.warn(MSG.warning_no_wsp_selected()); | 68 SC.warn(MSG.warning_no_wsp_selected()); |
99 return; | 69 return; |
100 } | 70 } |
101 | 71 |
102 // TODO: This could eventually be handled server-side. | 72 // TODO: This could eventually be handled server-side. |
103 // 2) Create, load Artifact and fire event. | 73 // 2) Create, load Artifact and fire event. |
104 loadService.load( | 74 this.loadService.load(c, r, r.getFactory(), locale, new AsyncCallback<Artifact>() { |
105 c, r, r.getFactory(), locale, | 75 @Override |
106 new AsyncCallback<Artifact>() { | 76 public void onFailure(final Throwable caught) { |
107 @Override | 77 GWT.log("WspDatacagePanel", caught); |
108 public void onFailure(Throwable caught) { | 78 SC.warn(FLYS.getExceptionString(MSG, caught)); |
109 GWT.log("WspDatacagePanel", caught); | 79 } |
110 SC.warn(FLYS.getExceptionString(MSG, caught)); | |
111 } | |
112 | 80 |
113 @Override | 81 @Override |
114 public void onSuccess(Artifact newArtifact) { | 82 public void onSuccess(final Artifact newArtifact) { |
115 GWT.log("Created new artifact."); | 83 GWT.log("Created new artifact."); |
116 fireStepForwardEvent(new StepForwardEvent( | 84 fireStepForwardEvent(new StepForwardEvent(getData(r, newArtifact))); |
117 getData(r, newArtifact))); | |
118 } | |
119 } | 85 } |
120 ); | 86 }); |
121 } | 87 } else { |
122 else { | |
123 showErrors(errors); | 88 showErrors(errors); |
124 } | 89 } |
125 } | 90 } |
126 | 91 |
127 | |
128 protected Recommendation getSelectedRecommendation() { | 92 protected Recommendation getSelectedRecommendation() { |
129 ToLoad toLoad = widget.getSelection(); | 93 final ToLoad toLoad = getSelection(); |
130 List<Recommendation> recoms = toLoad.toRecommendations(); | 94 final List<Recommendation> recoms = toLoad.toRecommendations(); |
131 | 95 |
132 return recoms.size() > 0 ? recoms.get(0) : null; | 96 return recoms.size() > 0 ? recoms.get(0) : null; |
133 } | 97 } |
134 | |
135 | 98 |
136 /** | 99 /** |
137 * Nothing is done in this method. It returns null, because we serve the | 100 * Nothing is done in this method. It returns null, because we serve the |
138 * Data another way! | 101 * Data another way! |
139 * | 102 * |
143 protected Data[] getData() { | 106 protected Data[] getData() { |
144 // do nothing here, the Data is fetched on another way in this panel. | 107 // do nothing here, the Data is fetched on another way in this panel. |
145 return null; | 108 return null; |
146 } | 109 } |
147 | 110 |
148 | |
149 /** Returns a Data Array with one default item. */ | 111 /** Returns a Data Array with one default item. */ |
150 protected Data[] getData(Recommendation r, Artifact newArtifact) { | 112 protected final Data[] getData(final Recommendation r, final Artifact newArtifact) { |
151 String uuid = newArtifact.getUuid(); | 113 final String uuid = newArtifact.getUuid(); |
152 r.setMasterArtifact(uuid); | 114 r.setMasterArtifact(uuid); |
153 | 115 |
154 String value = createDataString(uuid, r); | 116 final String value = createDataString(uuid, r); |
155 | 117 |
156 DataItem item = new DefaultDataItem(dataName, dataName, value); | 118 final String dataName = getMyDataName(); |
157 return new Data[] { new DefaultData( | 119 |
158 dataName, null, null, new DataItem[] { item }) }; | 120 final DataItem item = new DefaultDataItem(dataName, dataName, value); |
121 return new Data[] { new DefaultData(dataName, null, null, new DataItem[] { item }) }; | |
159 } | 122 } |
160 | 123 |
161 | 124 private String createDataString(final String artifactId, final Recommendation recommendation) { |
162 protected String createDataString( | |
163 String artifact, | |
164 Recommendation recommendation | |
165 ) { | |
166 Facet f = null; | |
167 | 125 |
168 // The filter will only be available or previous calculation artifacts. | 126 // The filter will only be available or previous calculation artifacts. |
169 Filter filter = recommendation.getFilter(); | 127 final Filter filter = recommendation.getFilter(); |
170 | 128 |
171 if (filter != null) { | 129 if (filter != null) { |
172 Map<String, List<Facet>> outs = filter.getOuts(); | 130 Facet f = null; |
173 Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); | |
174 | 131 |
175 for (Map.Entry<String, List<Facet>> entry: entries) { | 132 final Map<String, List<Facet>> outs = filter.getOuts(); |
176 List<Facet> fs = entry.getValue(); | 133 final Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); |
134 | |
135 for (final Map.Entry<String, List<Facet>> entry : entries) { | |
136 final List<Facet> fs = entry.getValue(); | |
177 | 137 |
178 f = fs.get(0); | 138 f = fs.get(0); |
179 if (f != null) { | 139 if (f != null) { |
180 break; | 140 break; |
181 } | 141 } |
182 } | 142 } |
183 | 143 |
184 return "[" + artifact + ";" + f.getName() + ";" | 144 return "[" + artifactId + ";" + f.getName() + ";" + f.getIndex() + "]"; |
185 + f.getIndex() + "]"; | |
186 } | 145 } |
187 else { | 146 |
188 return "[" + artifact + ";" | 147 return "[" + artifactId + ";" + recommendation.getFactory() + ";" + 0 + "]"; |
189 + recommendation.getFactory() + ";" + 0 + "]"; | |
190 } | |
191 } | 148 } |
192 } | 149 } |
193 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |