comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractPairRecommendationPanel.java @ 8875:8d1df8639563

Fixed: strange tweak in w-diferences panel always returned staticwkms factory instead of the original one. In sinfo we need the original one though.
author gernotbelger
date Thu, 08 Feb 2018 18:46:34 +0100
parents 8f6d6d26e96f
children 84397da33d17
comparison
equal deleted inserted replaced
8874:7ebe5d463740 8875:8d1df8639563
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.ArrayList;
12 import com.google.gwt.user.client.rpc.AsyncCallback; 12 import java.util.List;
13 13 import java.util.Map;
14 import com.smartgwt.client.data.Record; 14 import java.util.Set;
15 import com.smartgwt.client.types.ListGridFieldType;
16 import com.smartgwt.client.widgets.Canvas;
17 import com.smartgwt.client.widgets.events.ClickEvent;
18 import com.smartgwt.client.widgets.grid.ListGrid;
19 import com.smartgwt.client.widgets.grid.ListGridField;
20 import com.smartgwt.client.widgets.grid.ListGridRecord;
21 import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
22 import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
23 import com.smartgwt.client.widgets.layout.VLayout;
24 15
25 import org.dive4elements.river.client.client.Config; 16 import org.dive4elements.river.client.client.Config;
26 import org.dive4elements.river.client.client.FLYSConstants; 17 import org.dive4elements.river.client.client.FLYSConstants;
27 import org.dive4elements.river.client.client.event.StepForwardEvent; 18 import org.dive4elements.river.client.client.event.StepForwardEvent;
28 import org.dive4elements.river.client.client.services.LoadArtifactServiceAsync; 19 import org.dive4elements.river.client.client.services.LoadArtifactServiceAsync;
37 import org.dive4elements.river.client.shared.model.Recommendation; 28 import org.dive4elements.river.client.shared.model.Recommendation;
38 import org.dive4elements.river.client.shared.model.Recommendation.Facet; 29 import org.dive4elements.river.client.shared.model.Recommendation.Facet;
39 import org.dive4elements.river.client.shared.model.Recommendation.Filter; 30 import org.dive4elements.river.client.shared.model.Recommendation.Filter;
40 import org.dive4elements.river.client.shared.model.User; 31 import org.dive4elements.river.client.shared.model.User;
41 32
42 import java.util.ArrayList; 33 import com.google.gwt.core.client.GWT;
43 import java.util.List; 34 import com.google.gwt.user.client.rpc.AsyncCallback;
44 import java.util.Map; 35 import com.smartgwt.client.data.Record;
45 import java.util.Set; 36 import com.smartgwt.client.types.ListGridFieldType;
37 import com.smartgwt.client.widgets.Canvas;
38 import com.smartgwt.client.widgets.events.ClickEvent;
39 import com.smartgwt.client.widgets.grid.ListGrid;
40 import com.smartgwt.client.widgets.grid.ListGridField;
41 import com.smartgwt.client.widgets.grid.ListGridRecord;
42 import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
43 import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
44 import com.smartgwt.client.widgets.layout.VLayout;
46 45
47 // TODO Probably better to branch off AbstractUIProvider. 46 // TODO Probably better to branch off AbstractUIProvider.
48 // TODO Merge with other datacage-widget impls. 47 // TODO Merge with other datacage-widget impls.
49 /** 48 /**
50 * Panel containing a Grid and a "next" button. The Grid is fed by a 49 * Panel containing a Grid and a "next" button. The Grid is fed by a
53 public abstract class AbstractPairRecommendationPanel 52 public abstract class AbstractPairRecommendationPanel
54 extends TextProvider { 53 extends TextProvider {
55 54
56 /** 55 /**
57 * Allows for abstraction on how to handle/serialize the recommendation and the used factories. 56 * Allows for abstraction on how to handle/serialize the recommendation and the used factories.
57 * Basically this allows to tweak the factory that is delivered from the datacage to be replaced by a specific one...
58 *
58 * @author Gernot Belger 59 * @author Gernot Belger
59 *
60 */ 60 */
61 public static interface IRecommendationInfo { 61 public static interface IRecommendationInfo {
62 62
63 String getFactory(); 63 String getFactory(String originalFactory);
64 64
65 /** 65 /**
66 * Separate factory for the 'createDataString' method, because in the case of waterlevels. See HOTFIX/FIXME there. 66 * Separate factory for the 'createDataString' method, because in the case of waterlevels. See HOTFIX/FIXME there.
67 * @param recommendation
67 */ 68 */
68 String getDataStringFactory(); 69 String getDataStringFactory(Recommendation recommendation);
69 70
70 /** 71 /**
71 * Set factory of recommendation such that the correct artifacts will 72 * Set factory of recommendation such that the correct artifacts will
72 * be cloned for difference calculations. 73 * be cloned for difference calculations.
73 */ 74 */
84 // FIXME: why? we hide the field of the super class with exactly the same thing... 85 // FIXME: why? we hide the field of the super class with exactly the same thing...
85 private static FLYSConstants MSG_PROVIDER = GWT.create(FLYSConstants.class); 86 private static FLYSConstants MSG_PROVIDER = GWT.create(FLYSConstants.class);
86 87
87 private String dataName; 88 private String dataName;
88 89
89 private User user; 90 private final User user;
90 91
91 /** ListGrid that displays user-selected pairs to build differences with. */ 92 /** ListGrid that displays user-selected pairs to build differences with. */
92 private ListGrid differencesList; 93 private ListGrid differencesList;
93 94
94 /** 95 /**
95 * List to track previously selected but now removed pairs. (Needed to 96 * List to track previously selected but now removed pairs. (Needed to
96 * be able to identify artifacts that can be removed from the collection. 97 * be able to identify artifacts that can be removed from the collection.
97 */ 98 */
98 private List<RecommendationPairRecord> removedPairs = 99 private final List<RecommendationPairRecord> removedPairs =
99 new ArrayList<RecommendationPairRecord>(); 100 new ArrayList<RecommendationPairRecord>();
100 101
101 /** Service handle to clone and add artifacts to collection. */ 102 /** Service handle to clone and add artifacts to collection. */
102 private LoadArtifactServiceAsync loadArtifactService = GWT.create( 103 private final LoadArtifactServiceAsync loadArtifactService = GWT.create(
103 org.dive4elements.river.client.client.services.LoadArtifactService.class); 104 org.dive4elements.river.client.client.services.LoadArtifactService.class);
104 105
105 /** Service to remove artifacts from collection. */ 106 /** Service to remove artifacts from collection. */
106 private RemoveArtifactServiceAsync removeArtifactService = GWT.create( 107 private final RemoveArtifactServiceAsync removeArtifactService = GWT.create(
107 org.dive4elements.river.client.client.services.RemoveArtifactService.class); 108 org.dive4elements.river.client.client.services.RemoveArtifactService.class);
108 109
109 private IRecommendationInfo leftInfo; 110 private final IRecommendationInfo leftInfo;
110 111
111 private IRecommendationInfo rightInfo; 112 private final IRecommendationInfo rightInfo;
112 113
113 private IValidator validator; 114 private final IValidator validator;
114 115
115 /** 116 /**
116 * @param Validates the content of this form when the user clicks 'apply' 117 * @param Validates the content of this form when the user clicks 'apply'
117 * @param leftInfo Delegate for handling the left part of the recommendation-pair 118 * @param leftInfo Delegate for handling the left part of the recommendation-pair
118 * @param rightInfo Delegate for handling the right part of the recommendation-pair 119 * @param rightInfo Delegate for handling the right part of the recommendation-pair
119 */ 120 */
120 public AbstractPairRecommendationPanel(final User user, IValidator validator, final IRecommendationInfo leftInfo, final IRecommendationInfo rightInfo ) { 121 public AbstractPairRecommendationPanel(final User user, final IValidator validator, final IRecommendationInfo leftInfo, final IRecommendationInfo rightInfo ) {
121 this.user = user; 122 this.user = user;
122 this.validator = validator; 123 this.validator = validator;
123 this.leftInfo = leftInfo; 124 this.leftInfo = leftInfo;
124 this.rightInfo = rightInfo; 125 this.rightInfo = rightInfo;
125 } 126 }
135 * @return input string but with [ and ] removed, or input string if no 136 * @return input string but with [ and ] removed, or input string if no
136 * brackets were found. 137 * brackets were found.
137 * @see StringUtil.unbracket 138 * @see StringUtil.unbracket
138 */ 139 */
139 // FIXME: check if this is the same as STringUItils#unbracket 140 // FIXME: check if this is the same as STringUItils#unbracket
140 private static final String unbracket(String value) { 141 private static final String unbracket(final String value) {
141 // null- guard. 142 // null- guard.
142 if (value == null) return value; 143 if (value == null) return value;
143 144
144 int start = value.indexOf("["); 145 final int start = value.indexOf("[");
145 int end = value.indexOf("]"); 146 final int end = value.indexOf("]");
146 147
147 if (start < 0 || end < 0) { 148 if (start < 0 || end < 0) {
148 return value; 149 return value;
149 } 150 }
150 151
157 * @param leftInfo2 158 * @param leftInfo2
158 * @return recommendation from input string. 159 * @return recommendation from input string.
159 */ 160 */
160 private Recommendation createRecommendationFromString(final String from, final IRecommendationInfo info) { 161 private Recommendation createRecommendationFromString(final String from, final IRecommendationInfo info) {
161 // TODO Construct "real" filter. 162 // TODO Construct "real" filter.
162 String[] parts = unbracket(from).split(";"); 163 final String[] parts = unbracket(from).split(";");
163 Recommendation.Filter filter = new Recommendation.Filter(); 164 final Recommendation.Filter filter = new Recommendation.Filter();
164 Recommendation.Facet facet = new Recommendation.Facet( 165 final Recommendation.Facet facet = new Recommendation.Facet(
165 parts[1], 166 parts[1],
166 parts[2]); 167 parts[2]);
167 168
168 List<Recommendation.Facet> facets = new ArrayList<Recommendation.Facet>(); 169 final List<Recommendation.Facet> facets = new ArrayList<Recommendation.Facet>();
169 facets.add(facet); 170 facets.add(facet);
170 filter.add("longitudinal_section", facets); 171 filter.add("longitudinal_section", facets);
171 172
172 final String factory = info.getFactory( ); 173 final String factory = info.getFactory( parts[1] );
173 174
174 final Recommendation r = new Recommendation(factory, parts[0], this.artifact.getUuid(), filter); 175 final Recommendation r = new Recommendation(factory, parts[0], this.artifact.getUuid(), filter);
175 r.setDisplayName(parts[3]); 176 r.setDisplayName(parts[3]);
176 return r; 177 return r;
177 } 178 }
178 179
179 180
180 /** 181 /**
181 * Add RecomendationPairRecords from input String to the ListGrid. 182 * Add RecomendationPairRecords from input String to the ListGrid.
182 */ 183 */
183 private void populateGridFromString(String from){ 184 private void populateGridFromString(final String from){
184 // Split this string. 185 // Split this string.
185 // Create according recommendations and display strings. 186 // Create according recommendations and display strings.
186 String[] recs = from.split("#"); 187 final String[] recs = from.split("#");
187 if (recs.length % 2 != 0) return; 188 if (recs.length % 2 != 0) return;
188 for (int i = 0; i < recs.length; i+=2) { 189 for (int i = 0; i < recs.length; i+=2) {
189 Recommendation minuend = 190 final Recommendation minuend =
190 createRecommendationFromString(recs[i+0], leftInfo); 191 createRecommendationFromString(recs[i+0], this.leftInfo);
191 Recommendation subtrahend = 192 final Recommendation subtrahend =
192 createRecommendationFromString(recs[i+1], rightInfo); 193 createRecommendationFromString(recs[i+1], this.rightInfo);
193 194
194 RecommendationPairRecord pr = new RecommendationPairRecord( 195 final RecommendationPairRecord pr = new RecommendationPairRecord(
195 minuend, subtrahend); 196 minuend, subtrahend);
196 // This Recommendation Pair comes from the data string and was thus 197 // This Recommendation Pair comes from the data string and was thus
197 // already cloned. 198 // already cloned.
198 pr.setIsAlreadyLoaded(true); 199 pr.setIsAlreadyLoaded(true);
199 this.differencesList.addData(pr); 200 this.differencesList.addData(pr);
204 * Creates the graphical representation and interaction widgets for the data. 205 * Creates the graphical representation and interaction widgets for the data.
205 * @param dataList the data. 206 * @param dataList the data.
206 * @return graphical representation and interaction widgets for data. 207 * @return graphical representation and interaction widgets for data.
207 */ 208 */
208 @Override 209 @Override
209 public final Canvas create(DataList dataList) { 210 public final Canvas create(final DataList dataList) {
210 211
211 final Canvas widget = createWidget(); 212 final Canvas widget = createWidget();
212 213
213 final Canvas canvas = createChooserWidgets(widget, dataList, user, differencesList); 214 final Canvas canvas = createChooserWidgets(widget, dataList, this.user, this.differencesList);
214 215
215 populateGrid(dataList); 216 populateGrid(dataList);
216 217
217 return canvas; 218 return canvas;
218 } 219 }
220 /** 221 /**
221 * Creates the individual parts of the input-helper area ('Eingabeunterstützung') for choosing the content of this widget. 222 * Creates the individual parts of the input-helper area ('Eingabeunterstützung') for choosing the content of this widget.
222 */ 223 */
223 protected abstract Canvas createChooserWidgets(final Canvas widget, final DataList dataList, final User auser, final ListGrid diffList); 224 protected abstract Canvas createChooserWidgets(final Canvas widget, final DataList dataList, final User auser, final ListGrid diffList);
224 225
225 private void populateGrid(DataList dataList) { 226 private void populateGrid(final DataList dataList) {
226 Data data = dataList.get(0); 227 final Data data = dataList.get(0);
227 this.dataName = data.getLabel(); 228 this.dataName = data.getLabel();
228 for (int i = 0; i < dataList.size(); i++) { 229 for (int i = 0; i < dataList.size(); i++) {
229 if (dataList.get(i) != null && dataList.get(i).getItems() != null) { 230 if (dataList.get(i) != null && dataList.get(i).getItems() != null) {
230 if (dataList.get(i).getItems() != null) { 231 if (dataList.get(i).getItems() != null) {
231 populateGridFromString( 232 populateGridFromString(
235 } 236 }
236 } 237 }
237 238
238 @Override 239 @Override
239 public final List<String> validate() { 240 public final List<String> validate() {
240 return validator.validate(differencesList, MSG_PROVIDER); 241 return this.validator.validate(this.differencesList, MSG_PROVIDER);
241 } 242 }
242 243
243 /** 244 /**
244 * Creates layout with grid that displays selection inside. 245 * Creates layout with grid that displays selection inside.
245 */ 246 */
246 protected final Canvas createWidget() { 247 protected final Canvas createWidget() {
247 VLayout layout = new VLayout(); 248 final VLayout layout = new VLayout();
248 differencesList = new ListGrid(); 249 this.differencesList = new ListGrid();
249 250
250 differencesList.setCanEdit(false); 251 this.differencesList.setCanEdit(false);
251 differencesList.setCanSort(false); 252 this.differencesList.setCanSort(false);
252 differencesList.setShowHeaderContextMenu(false); 253 this.differencesList.setShowHeaderContextMenu(false);
253 differencesList.setHeight(150); 254 this.differencesList.setHeight(150);
254 differencesList.setShowAllRecords(true); 255 this.differencesList.setShowAllRecords(true);
255 256
256 ListGridField nameField = new ListGridField("first", "Minuend"); 257 final ListGridField nameField = new ListGridField("first", "Minuend");
257 ListGridField capitalField = new ListGridField("second", "Subtrahend"); 258 final ListGridField capitalField = new ListGridField("second", "Subtrahend");
258 // Track removed rows, therefore more or less reimplement 259 // Track removed rows, therefore more or less reimplement
259 // setCanRecomeRecords. 260 // setCanRecomeRecords.
260 final ListGridField removeField = 261 final ListGridField removeField =
261 new ListGridField("_removeRecord", "Remove Record"){{ 262 new ListGridField("_removeRecord", "Remove Record"){{
262 setType(ListGridFieldType.ICON); 263 setType(ListGridFieldType.ICON);
267 setCanGroupBy(false); 268 setCanGroupBy(false);
268 setCanFreeze(false); 269 setCanFreeze(false);
269 setWidth(25); 270 setWidth(25);
270 }}; 271 }};
271 272
272 differencesList.setFields(new ListGridField[] {nameField, 273 this.differencesList.setFields(new ListGridField[] {nameField,
273 capitalField, removeField}); 274 capitalField, removeField});
274 275
275 differencesList.addRecordClickHandler(new RecordClickHandler() { 276 this.differencesList.addRecordClickHandler(new RecordClickHandler() {
276 @Override 277 @Override
277 public void onRecordClick(final RecordClickEvent event) { 278 public void onRecordClick(final RecordClickEvent event) {
278 // Just handle remove-clicks 279 // Just handle remove-clicks
279 if(!event.getField().getName().equals(removeField.getName())) { 280 if(!event.getField().getName().equals(removeField.getName())) {
280 return; 281 return;
281 } 282 }
282 trackRemoved(event.getRecord()); 283 trackRemoved(event.getRecord());
283 event.getViewer().removeData(event.getRecord()); 284 event.getViewer().removeData(event.getRecord());
284 } 285 }
285 }); 286 });
286 layout.addMember(differencesList); 287 layout.addMember(this.differencesList);
287 288
288 return layout; 289 return layout;
289 } 290 }
290 291
291 292
292 /** 293 /**
293 * Add record to list of removed records. 294 * Add record to list of removed records.
294 */ 295 */
295 protected final void trackRemoved(Record r) { 296 protected final void trackRemoved(final Record r) {
296 RecommendationPairRecord pr = (RecommendationPairRecord) r; 297 final RecommendationPairRecord pr = (RecommendationPairRecord) r;
297 this.removedPairs.add(pr); 298 this.removedPairs.add(pr);
298 } 299 }
299 300
300 /** 301 /**
301 * Validates data, does nothing if invalid, otherwise clones new selected 302 * Validates data, does nothing if invalid, otherwise clones new selected
302 * waterlevels and add them to collection, forward the artifact. 303 * waterlevels and add them to collection, forward the artifact.
303 */ 304 */
304 @Override 305 @Override
305 public void onClick(ClickEvent e) { 306 public void onClick(final ClickEvent e) {
306 GWT.log("AbstractPairRecommendationPanel.onClick"); 307 GWT.log("AbstractPairRecommendationPanel.onClick");
307 308
308 List<String> errors = validate(); 309 final List<String> errors = validate();
309 if (errors != null && !errors.isEmpty()) { 310 if (errors != null && !errors.isEmpty()) {
310 showErrors(errors); 311 showErrors(errors);
311 return; 312 return;
312 } 313 }
313 314
314 Config config = Config.getInstance(); 315 final Config config = Config.getInstance();
315 String locale = config.getLocale(); 316 final String locale = config.getLocale();
316 317
317 ListGridRecord[] records = differencesList.getRecords(); 318 final ListGridRecord[] records = this.differencesList.getRecords();
318 319
319 List<Recommendation> ar = new ArrayList<Recommendation>(); 320 final List<Recommendation> ar = new ArrayList<Recommendation>();
320 List<Recommendation> all = new ArrayList<Recommendation>(); 321 final List<Recommendation> all = new ArrayList<Recommendation>();
321 322
322 for (ListGridRecord record : records) { 323 for (final ListGridRecord record : records) {
323 RecommendationPairRecord r = 324 final RecommendationPairRecord r =
324 (RecommendationPairRecord) record; 325 (RecommendationPairRecord) record;
325 // Do not add "old" recommendations. 326 // Do not add "old" recommendations.
326 if (!r.isAlreadyLoaded()) { 327 if (!r.isAlreadyLoaded()) {
327 // Check whether one of those is a dike or similar. 328 // Check whether one of those is a dike or similar.
328 // TODO differentiate and merge: new clones, new, old. 329 // TODO differentiate and merge: new clones, new, old.
329 Recommendation firstR = r.getFirst(); 330 final Recommendation firstR = r.getFirst();
330 leftInfo.adjustRecommendation(firstR); 331 this.leftInfo.adjustRecommendation(firstR);
331 332
332 Recommendation secondR = r.getSecond(); 333 final Recommendation secondR = r.getSecond();
333 rightInfo.adjustRecommendation(secondR); 334 this.rightInfo.adjustRecommendation(secondR);
334 ar.add(firstR); 335 ar.add(firstR);
335 ar.add(secondR); 336 ar.add(secondR);
336 } 337 }
337 else { 338 else {
338 all.add(r.getFirst()); 339 all.add(r.getFirst());
342 343
343 final Recommendation[] toClone = ar.toArray(new Recommendation[ar.size()]); 344 final Recommendation[] toClone = ar.toArray(new Recommendation[ar.size()]);
344 final Recommendation[] toUse = all.toArray(new Recommendation[all.size()]); 345 final Recommendation[] toUse = all.toArray(new Recommendation[all.size()]);
345 346
346 // Find out whether "old" artifacts have to be removed. 347 // Find out whether "old" artifacts have to be removed.
347 List<String> artifactIdsToRemove = new ArrayList<String>(); 348 final List<String> artifactIdsToRemove = new ArrayList<String>();
348 for (RecommendationPairRecord rp: this.removedPairs) { 349 for (final RecommendationPairRecord rp: this.removedPairs) {
349 Recommendation first = rp.getFirst(); 350 Recommendation first = rp.getFirst();
350 Recommendation second = rp.getSecond(); 351 Recommendation second = rp.getSecond();
351 352
352 for (Recommendation recommendation: toUse) { 353 for (final Recommendation recommendation: toUse) {
353 if (first != null && first.getIDs().equals(recommendation.getIDs())) { 354 if (first != null && first.getIDs().equals(recommendation.getIDs())) {
354 first = null; 355 first = null;
355 } 356 }
356 if (second != null && second.getIDs().equals(recommendation.getIDs())) { 357 if (second != null && second.getIDs().equals(recommendation.getIDs())) {
357 second = null; 358 second = null;
370 } 371 }
371 372
372 // Remove old artifacts, if any. Do this asychronously without much 373 // Remove old artifacts, if any. Do this asychronously without much
373 // feedback. 374 // feedback.
374 for(final String uuid: artifactIdsToRemove) { 375 for(final String uuid: artifactIdsToRemove) {
375 removeArtifactService.remove(this.collection, 376 this.removeArtifactService.remove(this.collection,
376 uuid, 377 uuid,
377 locale, 378 locale,
378 new AsyncCallback<Collection>() { 379 new AsyncCallback<Collection>() {
379 @Override 380 @Override
380 public void onFailure(Throwable caught) { 381 public void onFailure(final Throwable caught) {
381 GWT.log("RemoveArtifact (" + uuid + ") failed."); 382 GWT.log("RemoveArtifact (" + uuid + ") failed.");
382 } 383 }
383 @Override 384 @Override
384 public void onSuccess(Collection coll) { 385 public void onSuccess(final Collection coll) {
385 GWT.log("RemoveArtifact succeeded"); 386 GWT.log("RemoveArtifact succeeded");
386 } 387 }
387 }); 388 });
388 } 389 }
389 390
390 // Clone new ones (and spawn statics), go forward. 391 // Clone new ones (and spawn statics), go forward.
391 parameterList.lockUI(); 392 this.parameterList.lockUI();
392 loadArtifactService.loadMany( 393 this.loadArtifactService.loadMany(
393 this.collection, 394 this.collection,
394 toClone, 395 toClone,
395 //"staticwkms" and "waterlevel" 396 //"staticwkms" and "waterlevel"
396 null, 397 null,
397 locale, 398 locale,
398 new AsyncCallback<Artifact[]>() { 399 new AsyncCallback<Artifact[]>() {
399 @Override 400 @Override
400 public void onFailure(Throwable caught) { 401 public void onFailure(final Throwable caught) {
401 caught.printStackTrace(); 402 caught.printStackTrace();
402 GWT.log("Failure of cloning with factories!"); 403 GWT.log("Failure of cloning with factories!");
403 parameterList.unlockUI(); 404 AbstractPairRecommendationPanel.this.parameterList.unlockUI();
404 } 405 }
405 @Override 406 @Override
406 public void onSuccess(Artifact[] artifacts) { 407 public void onSuccess(final Artifact[] artifacts) {
407 GWT.log("Successfully cloned " + toClone.length + 408 GWT.log("Successfully cloned " + toClone.length +
408 " with factories."); 409 " with factories.");
409 410
410 fireStepForwardEvent(new StepForwardEvent( 411 fireStepForwardEvent(new StepForwardEvent(
411 getData(toClone, artifacts, toUse))); 412 getData(toClone, artifacts, toUse)));
412 parameterList.unlockUI(); 413 AbstractPairRecommendationPanel.this.parameterList.unlockUI();
413 } 414 }
414 }); 415 });
415 } 416 }
416 417
417 /** 418 /**
425 * 426 *
426 * @return dataitem with a long string with identifiers to construct 427 * @return dataitem with a long string with identifiers to construct
427 * diff-pairs. 428 * diff-pairs.
428 */ 429 */
429 protected final Data[] getData( 430 protected final Data[] getData(
430 Recommendation[] newRecommendations, 431 final Recommendation[] newRecommendations,
431 Artifact[] newArtifacts, 432 final Artifact[] newArtifacts,
432 Recommendation[] oldRecommendations) 433 final Recommendation[] oldRecommendations)
433 { 434 {
434 // Construct string with info about selections. 435 // Construct string with info about selections.
435 String dataItemString = ""; 436 String dataItemString = "";
436 for (int i = 0; i < newRecommendations.length; i++) { 437 for (int i = 0; i < newRecommendations.length; i++) {
437 Recommendation r = newRecommendations[i]; 438 final Recommendation r = newRecommendations[i];
438 Artifact newArtifact = newArtifacts[i]; 439 final Artifact newArtifact = newArtifacts[i];
439 String uuid = newArtifact.getUuid(); 440 final String uuid = newArtifact.getUuid();
440 r.setMasterArtifact(uuid); 441 r.setMasterArtifact(uuid);
441 442
442 if (i>0) 443 if (i>0)
443 dataItemString += "#"; 444 dataItemString += "#";
444 445
445 // REMARK: ugly, but we know that the recommandations comes in left/right pairs. 446 // REMARK: ugly, but we know that the recommandations comes in left/right pairs.
446 final IRecommendationInfo info = i % 2 == 0 ? leftInfo : rightInfo; 447 final IRecommendationInfo info = i % 2 == 0 ? this.leftInfo : this.rightInfo;
447 448
448 dataItemString += createDataString(uuid, r, info); 449 dataItemString += createDataString(uuid, r, info);
449 } 450 }
450 451
451 for (int i = 0; i < oldRecommendations.length; i++) { 452 for (int i = 0; i < oldRecommendations.length; i++) {
452 Recommendation r = oldRecommendations[i]; 453 final Recommendation r = oldRecommendations[i];
453 String uuid = r.getIDs(); 454 final String uuid = r.getIDs();
454 455
455 if (dataItemString.length() > 0) 456 if (dataItemString.length() > 0)
456 dataItemString += "#"; 457 dataItemString += "#";
457 458
458 // REMARK: ugly, but we know that the recommandations comes in left/right pairs. 459 // REMARK: ugly, but we know that the recommandations comes in left/right pairs.
459 final IRecommendationInfo info = i % 2 == 0 ? leftInfo : rightInfo; 460 final IRecommendationInfo info = i % 2 == 0 ? this.leftInfo : this.rightInfo;
460 461
461 dataItemString += createDataString(uuid, r, info); 462 dataItemString += createDataString(uuid, r, info);
462 } 463 }
463 464
464 // TODO some hassle could be resolved by using multiple DataItems 465 // TODO some hassle could be resolved by using multiple DataItems
465 // (e.g. one per pair). 466 // (e.g. one per pair).
466 DataItem item = new DefaultDataItem(dataName, dataName, dataItemString); 467 final DataItem item = new DefaultDataItem(this.dataName, this.dataName, dataItemString);
467 return new Data[] { new DefaultData( 468 return new Data[] { new DefaultData(
468 dataName, null, null, new DataItem[] {item}) }; 469 this.dataName, null, null, new DataItem[] {item}) };
469 } 470 }
470 471
471 /** 472 /**
472 * Creates part of the String that encodes minuend or subtrahend. 473 * Creates part of the String that encodes minuend or subtrahend.
473 * @param recommendation Recommendation to wrap in string. 474 * @param recommendation Recommendation to wrap in string.
474 * @param info Provides the factory to encode. 475 * @param info Provides the factory to encode.
475 */ 476 */
476 protected static final String createDataString(final String artifactUuid, final Recommendation recommendation, final IRecommendationInfo info) { 477 protected static final String createDataString(final String artifactUuid, final Recommendation recommendation, final IRecommendationInfo info) {
477 final String factory = info.getDataStringFactory(); 478 final String factory = info.getDataStringFactory( recommendation );
478 479
479 Filter filter = recommendation.getFilter(); 480 final Filter filter = recommendation.getFilter();
480 Facet f = null; 481 Facet f = null;
481 482
482 if(filter != null) { 483 if(filter != null) {
483 Map<String, List<Facet>> outs = filter.getOuts(); 484 final Map<String, List<Facet>> outs = filter.getOuts();
484 Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); 485 final Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet();
485 486
486 for (Map.Entry<String, List<Facet>> entry: entries) { 487 for (final Map.Entry<String, List<Facet>> entry: entries) {
487 List<Facet> fs = entry.getValue(); 488 final List<Facet> fs = entry.getValue();
488 489
489 f = fs.get(0); 490 f = fs.get(0);
490 if (f != null) { 491 if (f != null) {
491 break; 492 break;
492 } 493 }

http://dive4elements.wald.intevation.org