comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractPairRecommendationPanel.java @ 9580:839b2aa84dd0

minuend/subtrahend-UI-switch
author gernotbelger
date Tue, 08 Jan 2019 17:01:09 +0100
parents 84397da33d17
children
comparison
equal deleted inserted replaced
9579:67a42c9c46a7 9580:839b2aa84dd0
47 // TODO Merge with other datacage-widget impls. 47 // TODO Merge with other datacage-widget impls.
48 /** 48 /**
49 * 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
50 * DatacagePairWidget which is put in the input-helper area. 50 * DatacagePairWidget which is put in the input-helper area.
51 */ 51 */
52 public abstract class AbstractPairRecommendationPanel 52 public abstract class AbstractPairRecommendationPanel extends TextProvider {
53 extends TextProvider {
54 53
55 /** 54 /**
56 * Allows for abstraction on how to handle/serialize the recommendation and the used factories. 55 * 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... 56 * Basically this allows to tweak the factory that is delivered from the datacage to be replaced by a specific one...
58 * 57 *
59 * @author Gernot Belger 58 * @author Gernot Belger
60 */ 59 */
61 public static interface IRecommendationInfo { 60 public static interface IRecommendationInfo {
62 61
63 String getFactory(String originalFactory); 62 String getFactory(String originalFactory);
64 63
65 /** 64 /**
66 * Separate factory for the 'createDataString' method, because in the case of waterlevels. See HOTFIX/FIXME there. 65 * Separate factory for the 'createDataString' method, because in the case of waterlevels. See HOTFIX/FIXME there.
66 *
67 * @param recommendation 67 * @param recommendation
68 */ 68 */
69 String getDataStringFactory(Recommendation recommendation); 69 String getDataStringFactory(Recommendation recommendation);
70 70
71 /** 71 /**
73 * be cloned for difference calculations. 73 * be cloned for difference calculations.
74 */ 74 */
75 void adjustRecommendation(Recommendation recommendation); 75 void adjustRecommendation(Recommendation recommendation);
76 } 76 }
77 77
78 public static interface IValidator 78 public static interface IValidator {
79 {
80 List<String> validate(ListGrid differencesList, FLYSConstants msgProvider); 79 List<String> validate(ListGrid differencesList, FLYSConstants msgProvider);
81 } 80 }
82 81
83 private static final long serialVersionUID = 8906629596491827857L; 82 private static final long serialVersionUID = 8906629596491827857L;
84 83
91 90
92 /** 91 /**
93 * List to track previously selected but now removed pairs. (Needed to 92 * List to track previously selected but now removed pairs. (Needed to
94 * be able to identify artifacts that can be removed from the collection. 93 * be able to identify artifacts that can be removed from the collection.
95 */ 94 */
96 private final List<RecommendationPairRecord> removedPairs = 95 private final List<RecommendationPairRecord> removedPairs = new ArrayList<RecommendationPairRecord>();
97 new ArrayList<RecommendationPairRecord>();
98 96
99 /** Service handle to clone and add artifacts to collection. */ 97 /** Service handle to clone and add artifacts to collection. */
100 private final LoadArtifactServiceAsync loadArtifactService = GWT.create( 98 private final LoadArtifactServiceAsync loadArtifactService = GWT.create(org.dive4elements.river.client.client.services.LoadArtifactService.class);
101 org.dive4elements.river.client.client.services.LoadArtifactService.class);
102 99
103 /** Service to remove artifacts from collection. */ 100 /** Service to remove artifacts from collection. */
104 private final RemoveArtifactServiceAsync removeArtifactService = GWT.create( 101 private final RemoveArtifactServiceAsync removeArtifactService = GWT.create(org.dive4elements.river.client.client.services.RemoveArtifactService.class);
105 org.dive4elements.river.client.client.services.RemoveArtifactService.class);
106 102
107 private final IRecommendationInfo leftInfo; 103 private final IRecommendationInfo leftInfo;
108 104
109 private final IRecommendationInfo rightInfo; 105 private final IRecommendationInfo rightInfo;
110 106
111 private final IValidator validator; 107 private final IValidator validator;
112 108
113 /** 109 protected final boolean minuendSubtrahendUiReversed;
114 * @param Validates the content of this form when the user clicks 'apply' 110
115 * @param leftInfo Delegate for handling the left part of the recommendation-pair 111 /**
116 * @param rightInfo Delegate for handling the right part of the recommendation-pair 112 * @param Validates
117 */ 113 * the content of this form when the user clicks 'apply'
118 public AbstractPairRecommendationPanel(final User user, final IValidator validator, final IRecommendationInfo leftInfo, final IRecommendationInfo rightInfo ) { 114 * @param leftInfo
115 * Delegate for handling the left part of the recommendation-pair
116 * @param rightInfo
117 * Delegate for handling the right part of the recommendation-pair
118 */
119 public AbstractPairRecommendationPanel(final User user, final IValidator validator, final IRecommendationInfo leftInfo, final IRecommendationInfo rightInfo,
120 final boolean minuendSubtrahendUiReversed) {
121 this.minuendSubtrahendUiReversed = minuendSubtrahendUiReversed;
119 this.user = user; 122 this.user = user;
120 this.validator = validator; 123 this.validator = validator;
121 this.leftInfo = leftInfo; 124 this.leftInfo = leftInfo;
122 this.rightInfo = rightInfo; 125 this.rightInfo = rightInfo;
123 } 126 }
127 return MSG; 130 return MSG;
128 } 131 }
129 132
130 /** 133 /**
131 * Remove first occurrence of "[" and "]" (if both do occur). 134 * Remove first occurrence of "[" and "]" (if both do occur).
132 * @param value String to be stripped of [] (might be null). 135 *
136 * @param value
137 * String to be stripped of [] (might be null).
133 * @return input string but with [ and ] removed, or input string if no 138 * @return input string but with [ and ] removed, or input string if no
134 * brackets were found. 139 * brackets were found.
135 * @see StringUtil.unbracket 140 * @see StringUtil.unbracket
136 */ 141 */
137 // FIXME: check if this is the same as STringUItils#unbracket 142 // FIXME: check if this is the same as STringUItils#unbracket
138 private static final String unbracket(final String value) { 143 private static final String unbracket(final String value) {
139 // null- guard. 144 // null- guard.
140 if (value == null) return value; 145 if (value == null)
146 return value;
141 147
142 final int start = value.indexOf("["); 148 final int start = value.indexOf("[");
143 final int end = value.indexOf("]"); 149 final int end = value.indexOf("]");
144 150
145 if (start < 0 || end < 0) { 151 if (start < 0 || end < 0) {
146 return value; 152 return value;
147 } 153 }
148 154
149 return value.substring(start + 1, end); 155 return value.substring(start + 1, end);
150 } 156 }
151 157
152 /** 158 /**
153 * Create a recommendation from a string representation of it. 159 * Create a recommendation from a string representation of it.
154 * @param from string in format as shown above. 160 *
161 * @param from
162 * string in format as shown above.
155 * @param leftInfo2 163 * @param leftInfo2
156 * @return recommendation from input string. 164 * @return recommendation from input string.
157 */ 165 */
158 private Recommendation createRecommendationFromString(final String from, final IRecommendationInfo info) { 166 private Recommendation createRecommendationFromString(final String from, final IRecommendationInfo info) {
159 // TODO Construct "real" filter. 167 // TODO Construct "real" filter.
160 final String[] parts = unbracket(from).split(";"); 168 final String[] parts = unbracket(from).split(";");
161 final Recommendation.Filter filter = new Recommendation.Filter(); 169 final Recommendation.Filter filter = new Recommendation.Filter();
162 final Recommendation.Facet facet = new Recommendation.Facet( 170 final Recommendation.Facet facet = new Recommendation.Facet(parts[1], parts[2]);
163 parts[1],
164 parts[2]);
165 171
166 final List<Recommendation.Facet> facets = new ArrayList<Recommendation.Facet>(); 172 final List<Recommendation.Facet> facets = new ArrayList<Recommendation.Facet>();
167 facets.add(facet); 173 facets.add(facet);
168 filter.add("longitudinal_section", facets); 174 filter.add("longitudinal_section", facets);
169 175
170 final String factory = info.getFactory( parts[1] ); 176 final String factory = info.getFactory(parts[1]);
171 177
172 final Recommendation r = new Recommendation(factory, parts[0], this.artifact.getUuid(), filter); 178 final Recommendation r = new Recommendation(factory, parts[0], this.artifact.getUuid(), filter);
173 r.setDisplayName(parts[3]); 179 r.setDisplayName(parts[3]);
174 return r; 180 return r;
175 } 181 }
176 182
177
178 /** 183 /**
179 * Add RecomendationPairRecords from input String to the ListGrid. 184 * Add RecomendationPairRecords from input String to the ListGrid.
180 */ 185 */
181 private void populateGridFromString(final String from){ 186 private void populateGridFromString(final String from) {
182 // Split this string. 187 // Split this string.
183 // Create according recommendations and display strings. 188 // Create according recommendations and display strings.
184 final String[] recs = from.split("#"); 189 final String[] recs = from.split("#");
185 if (recs.length % 2 != 0) return; 190 if (recs.length % 2 != 0)
186 for (int i = 0; i < recs.length; i+=2) { 191 return;
187 final Recommendation minuend = 192 for (int i = 0; i < recs.length; i += 2) {
188 createRecommendationFromString(recs[i+0], this.leftInfo); 193 final Recommendation minuend = createRecommendationFromString(recs[i + 0], this.leftInfo);
189 final Recommendation subtrahend = 194 final Recommendation subtrahend = createRecommendationFromString(recs[i + 1], this.rightInfo);
190 createRecommendationFromString(recs[i+1], this.rightInfo); 195
191 196 final RecommendationPairRecord pr = new RecommendationPairRecord(minuend, subtrahend);
192 final RecommendationPairRecord pr = new RecommendationPairRecord(
193 minuend, subtrahend);
194 // This Recommendation Pair comes from the data string and was thus 197 // This Recommendation Pair comes from the data string and was thus
195 // already cloned. 198 // already cloned.
196 pr.setIsAlreadyLoaded(true); 199 pr.setIsAlreadyLoaded(true);
197 this.differencesList.addData(pr); 200 this.differencesList.addData(pr);
198 } 201 }
199 } 202 }
200 203
201 /** 204 /**
202 * Creates the graphical representation and interaction widgets for the data. 205 * Creates the graphical representation and interaction widgets for the data.
203 * @param dataList the data. 206 *
207 * @param dataList
208 * the data.
204 * @return graphical representation and interaction widgets for data. 209 * @return graphical representation and interaction widgets for data.
205 */ 210 */
206 @Override 211 @Override
207 public final Canvas create(final DataList dataList) { 212 public final Canvas create(final DataList dataList) {
208 213
214 219
215 return canvas; 220 return canvas;
216 } 221 }
217 222
218 /** 223 /**
219 * Creates the individual parts of the input-helper area ('Eingabeunterstützung') for choosing the content of this widget. 224 * Creates the individual parts of the input-helper area ('Eingabeunterstützung') for choosing the content of this
225 * widget.
220 */ 226 */
221 protected abstract Canvas createChooserWidgets(final Canvas widget, final DataList dataList, final User auser, final ListGrid diffList); 227 protected abstract Canvas createChooserWidgets(final Canvas widget, final DataList dataList, final User auser, final ListGrid diffList);
222 228
223 private void populateGrid(final DataList dataList) { 229 private void populateGrid(final DataList dataList) {
224 final Data data = dataList.get(0); 230 final Data data = dataList.get(0);
225 this.dataName = data.getLabel(); 231 this.dataName = data.getLabel();
226 for (int i = 0; i < dataList.size(); i++) { 232 for (int i = 0; i < dataList.size(); i++) {
227 if (dataList.get(i) != null && dataList.get(i).getItems() != null) { 233 if (dataList.get(i) != null && dataList.get(i).getItems() != null) {
228 if (dataList.get(i).getItems() != null) { 234 if (dataList.get(i).getItems() != null) {
229 populateGridFromString( 235 populateGridFromString(dataList.get(i).getItems()[0].getStringValue());
230 dataList.get(i).getItems()[0].getStringValue());
231 } 236 }
232 } 237 }
233 } 238 }
234 } 239 }
235 240
240 245
241 /** 246 /**
242 * Creates layout with grid that displays selection inside. 247 * Creates layout with grid that displays selection inside.
243 */ 248 */
244 protected final Canvas createWidget() { 249 protected final Canvas createWidget() {
245 final VLayout layout = new VLayout(); 250 final VLayout layout = new VLayout();
246 this.differencesList = new ListGrid(); 251 this.differencesList = new ListGrid();
247 252
248 this.differencesList.setCanEdit(false); 253 this.differencesList.setCanEdit(false);
249 this.differencesList.setCanSort(false); 254 this.differencesList.setCanSort(false);
250 this.differencesList.setShowHeaderContextMenu(false); 255 this.differencesList.setShowHeaderContextMenu(false);
251 this.differencesList.setHeight(150); 256 this.differencesList.setHeight(150);
252 this.differencesList.setShowAllRecords(true); 257 this.differencesList.setShowAllRecords(true);
253 258
254 final ListGridField nameField = new ListGridField("first", "Minuend"); 259 final ListGridField nameField = new ListGridField(this.minuendSubtrahendUiReversed ? "second" : "first", "Minuend");
255 final ListGridField capitalField = new ListGridField("second", "Subtrahend"); 260 final ListGridField capitalField = new ListGridField(this.minuendSubtrahendUiReversed ? "first" : "second", "Subtrahend");
256 // Track removed rows, therefore more or less reimplement 261 // Track removed rows, therefore more or less reimplement
257 // setCanRecomeRecords. 262 // setCanRecomeRecords.
258 final ListGridField removeField = 263 final ListGridField removeField = new ListGridField("_removeRecord", "Remove Record") {
259 new ListGridField("_removeRecord", "Remove Record"){{ 264 {
260 setType(ListGridFieldType.ICON); 265 setType(ListGridFieldType.ICON);
261 setIcon(GWT.getHostPageBaseURL() + msg().removeFeature()); 266 setIcon(GWT.getHostPageBaseURL() + msg().removeFeature());
262 setCanEdit(false); 267 setCanEdit(false);
263 setCanFilter(false); 268 setCanFilter(false);
264 setCanSort(false); 269 setCanSort(false);
265 setCanGroupBy(false); 270 setCanGroupBy(false);
266 setCanFreeze(false); 271 setCanFreeze(false);
267 setWidth(25); 272 setWidth(25);
268 }}; 273 }
269 274 };
270 this.differencesList.setFields(new ListGridField[] {nameField, 275 this.differencesList.setFields(new ListGridField[] { nameField, capitalField, removeField });
271 capitalField, removeField}); 276
272 277 this.differencesList.addRecordClickHandler(new RecordClickHandler() {
273 this.differencesList.addRecordClickHandler(new RecordClickHandler() { 278 @Override
274 @Override 279 public void onRecordClick(final RecordClickEvent event) {
275 public void onRecordClick(final RecordClickEvent event) { 280 // Just handle remove-clicks
276 // Just handle remove-clicks 281 if (!event.getField().getName().equals(removeField.getName())) {
277 if(!event.getField().getName().equals(removeField.getName())) { 282 return;
278 return; 283 }
279 } 284 trackRemoved(event.getRecord());
280 trackRemoved(event.getRecord()); 285 event.getViewer().removeData(event.getRecord());
281 event.getViewer().removeData(event.getRecord()); 286 }
282 } 287 });
283 }); 288 layout.addMember(this.differencesList);
284 layout.addMember(this.differencesList); 289
285 290 return layout;
286 return layout; 291 }
287 }
288
289 292
290 /** 293 /**
291 * Add record to list of removed records. 294 * Add record to list of removed records.
292 */ 295 */
293 protected final void trackRemoved(final Record r) { 296 protected final void trackRemoved(final Record r) {
312 final Config config = Config.getInstance(); 315 final Config config = Config.getInstance();
313 final String locale = config.getLocale(); 316 final String locale = config.getLocale();
314 317
315 final ListGridRecord[] records = this.differencesList.getRecords(); 318 final ListGridRecord[] records = this.differencesList.getRecords();
316 319
317 final List<Recommendation> ar = new ArrayList<Recommendation>(); 320 final List<Recommendation> ar = new ArrayList<Recommendation>();
318 final List<Recommendation> all = new ArrayList<Recommendation>(); 321 final List<Recommendation> all = new ArrayList<Recommendation>();
319 322
320 for (final ListGridRecord record : records) { 323 for (final ListGridRecord record : records) {
321 final RecommendationPairRecord r = 324 final RecommendationPairRecord r = (RecommendationPairRecord) record;
322 (RecommendationPairRecord) record;
323 // Do not add "old" recommendations. 325 // Do not add "old" recommendations.
324 if (!r.isAlreadyLoaded()) { 326 if (!r.isAlreadyLoaded()) {
325 // Check whether one of those is a dike or similar. 327 // Check whether one of those is a dike or similar.
326 // TODO differentiate and merge: new clones, new, old. 328 // TODO differentiate and merge: new clones, new, old.
327 final Recommendation firstR = r.getFirst(); 329 final Recommendation firstR = r.getFirst();
328 this.leftInfo.adjustRecommendation(firstR); 330 this.leftInfo.adjustRecommendation(firstR);
329
330 final Recommendation secondR = r.getSecond(); 331 final Recommendation secondR = r.getSecond();
331 this.rightInfo.adjustRecommendation(secondR); 332 this.rightInfo.adjustRecommendation(secondR);
333
332 ar.add(firstR); 334 ar.add(firstR);
333 ar.add(secondR); 335 ar.add(secondR);
334 } 336 } else {
335 else {
336 all.add(r.getFirst()); 337 all.add(r.getFirst());
337 all.add(r.getSecond()); 338 all.add(r.getSecond());
338 } 339 }
339 } 340 }
340 341
341 final Recommendation[] toClone = ar.toArray(new Recommendation[ar.size()]); 342 final Recommendation[] toClone = ar.toArray(new Recommendation[ar.size()]);
342 final Recommendation[] toUse = all.toArray(new Recommendation[all.size()]); 343 final Recommendation[] toUse = all.toArray(new Recommendation[all.size()]);
343 344
344 // Find out whether "old" artifacts have to be removed. 345 // Find out whether "old" artifacts have to be removed.
345 final List<String> artifactIdsToRemove = new ArrayList<String>(); 346 final List<String> artifactIdsToRemove = new ArrayList<String>();
346 for (final RecommendationPairRecord rp: this.removedPairs) { 347 for (final RecommendationPairRecord rp : this.removedPairs) {
347 Recommendation first = rp.getFirst(); 348 Recommendation first = rp.getFirst();
348 Recommendation second = rp.getSecond(); 349 Recommendation second = rp.getSecond();
349 350
350 for (final Recommendation recommendation: toUse) { 351 for (final Recommendation recommendation : toUse) {
351 if (first != null && first.getIDs().equals(recommendation.getIDs())) { 352 if (first != null && first.getIDs().equals(recommendation.getIDs())) {
352 first = null; 353 first = null;
353 } 354 }
354 if (second != null && second.getIDs().equals(recommendation.getIDs())) { 355 if (second != null && second.getIDs().equals(recommendation.getIDs())) {
355 second = null; 356 second = null;
367 } 368 }
368 } 369 }
369 370
370 // Remove old artifacts, if any. Do this asychronously without much 371 // Remove old artifacts, if any. Do this asychronously without much
371 // feedback. 372 // feedback.
372 for(final String uuid: artifactIdsToRemove) { 373 for (final String uuid : artifactIdsToRemove) {
373 this.removeArtifactService.remove(this.collection, 374 this.removeArtifactService.remove(this.collection, uuid, locale, new AsyncCallback<Collection>() {
374 uuid,
375 locale,
376 new AsyncCallback<Collection>() {
377 @Override 375 @Override
378 public void onFailure(final Throwable caught) { 376 public void onFailure(final Throwable caught) {
379 GWT.log("RemoveArtifact (" + uuid + ") failed."); 377 GWT.log("RemoveArtifact (" + uuid + ") failed.");
380 } 378 }
379
381 @Override 380 @Override
382 public void onSuccess(final Collection coll) { 381 public void onSuccess(final Collection coll) {
383 GWT.log("RemoveArtifact succeeded"); 382 GWT.log("RemoveArtifact succeeded");
384 } 383 }
385 }); 384 });
386 } 385 }
387 386
388 // Clone new ones (and spawn statics), go forward. 387 // Clone new ones (and spawn statics), go forward.
389 this.parameterList.lockUI(); 388 this.parameterList.lockUI();
390 this.loadArtifactService.loadMany( 389 this.loadArtifactService.loadMany(this.collection, toClone,
391 this.collection, 390 // "staticwkms" and "waterlevel"
392 toClone, 391 null, locale, new AsyncCallback<Artifact[]>() {
393 //"staticwkms" and "waterlevel" 392
394 null,
395 locale,
396 new AsyncCallback<Artifact[]>() {
397 @Override 393 @Override
398 public void onFailure(final Throwable caught) { 394 public void onFailure(final Throwable caught) {
399 caught.printStackTrace(); 395 caught.printStackTrace();
400 GWT.log("Failure of cloning with factories!"); 396 GWT.log("Failure of cloning with factories!");
401 AbstractPairRecommendationPanel.this.parameterList.unlockUI(); 397 AbstractPairRecommendationPanel.this.parameterList.unlockUI();
402 } 398 }
399
403 @Override 400 @Override
404 public void onSuccess(final Artifact[] artifacts) { 401 public void onSuccess(final Artifact[] artifacts) {
405 GWT.log("Successfully cloned " + toClone.length + 402 GWT.log("Successfully cloned " + toClone.length + " with factories.");
406 " with factories."); 403
407 404 fireStepForwardEvent(new StepForwardEvent(getData(toClone, artifacts, toUse)));
408 fireStepForwardEvent(new StepForwardEvent(
409 getData(toClone, artifacts, toUse)));
410 AbstractPairRecommendationPanel.this.parameterList.unlockUI(); 405 AbstractPairRecommendationPanel.this.parameterList.unlockUI();
411 } 406 }
407
412 }); 408 });
413 } 409 }
414 410
415 /** 411 /**
416 * Create Data and DataItem from selection (a long string with identifiers 412 * Create Data and DataItem from selection (a long string with identifiers
417 * to construct diff-pairs). 413 * to construct diff-pairs).
418 * 414 *
419 * @param newRecommendations "new" recommendations (did not survive a 415 * @param newRecommendations
420 * backjump). 416 * "new" recommendations (did not survive a
421 * @param newArtifacts artifacts cloned from newRecommendations. 417 * backjump).
422 * @param oldRecommendations old recommendations that survived a backjump. 418 * @param newArtifacts
419 * artifacts cloned from newRecommendations.
420 * @param oldRecommendations
421 * old recommendations that survived a backjump.
423 * 422 *
424 * @return dataitem with a long string with identifiers to construct 423 * @return dataitem with a long string with identifiers to construct
425 * diff-pairs. 424 * diff-pairs.
426 */ 425 */
427 protected final Data[] getData( 426 protected final Data[] getData(final Recommendation[] newRecommendations, final Artifact[] newArtifacts, final Recommendation[] oldRecommendations) {
428 final Recommendation[] newRecommendations,
429 final Artifact[] newArtifacts,
430 final Recommendation[] oldRecommendations)
431 {
432 // Construct string with info about selections. 427 // Construct string with info about selections.
433 String dataItemString = ""; 428 String dataItemString = "";
434 for (int i = 0; i < newRecommendations.length; i++) { 429 for (int i = 0; i < newRecommendations.length; i++) {
435 final Recommendation r = newRecommendations[i]; 430 final Recommendation r = newRecommendations[i];
436 final Artifact newArtifact = newArtifacts[i]; 431 final Artifact newArtifact = newArtifacts[i];
437 final String uuid = newArtifact.getUuid(); 432 final String uuid = newArtifact.getUuid();
438 r.setMasterArtifact(uuid); 433 r.setMasterArtifact(uuid);
439 434
440 if (i>0) 435 if (i > 0)
441 dataItemString += "#"; 436 dataItemString += "#";
442 437
443 // REMARK: ugly, but we know that the recommandations comes in left/right pairs. 438 // REMARK: ugly, but we know that the recommandations comes in left/right pairs.
444 final IRecommendationInfo info = i % 2 == 0 ? this.leftInfo : this.rightInfo; 439 final IRecommendationInfo info = i % 2 == 0 ? this.leftInfo : this.rightInfo;
445 440
460 } 455 }
461 456
462 // TODO some hassle could be resolved by using multiple DataItems 457 // TODO some hassle could be resolved by using multiple DataItems
463 // (e.g. one per pair). 458 // (e.g. one per pair).
464 final DataItem item = new DefaultDataItem(this.dataName, this.dataName, dataItemString); 459 final DataItem item = new DefaultDataItem(this.dataName, this.dataName, dataItemString);
465 return new Data[] { new DefaultData( 460 return new Data[] { new DefaultData(this.dataName, null, null, new DataItem[] { item }) };
466 this.dataName, null, null, new DataItem[] {item}) };
467 } 461 }
468 462
469 /** 463 /**
470 * Creates part of the String that encodes minuend or subtrahend. 464 * Creates part of the String that encodes minuend or subtrahend.
471 * @param recommendation Recommendation to wrap in string. 465 *
472 * @param info Provides the factory to encode. 466 * @param recommendation
467 * Recommendation to wrap in string.
468 * @param info
469 * Provides the factory to encode.
473 */ 470 */
474 protected static final String createDataString(final String artifactUuid, final Recommendation recommendation, final IRecommendationInfo info) { 471 protected static final String createDataString(final String artifactUuid, final Recommendation recommendation, final IRecommendationInfo info) {
475 final String factory = info.getDataStringFactory( recommendation ); 472 final String factory = info.getDataStringFactory(recommendation);
476 473
477 final Filter filter = recommendation.getFilter(); 474 final Filter filter = recommendation.getFilter();
478 Facet f = null; 475 Facet f = null;
479 476
480 if(filter != null) { 477 if (filter != null) {
481 final Map<String, List<Facet>> outs = filter.getOuts(); 478 final Map<String, List<Facet>> outs = filter.getOuts();
482 final Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet(); 479 final Set<Map.Entry<String, List<Facet>>> entries = outs.entrySet();
483 480
484 for (final Map.Entry<String, List<Facet>> entry: entries) { 481 for (final Map.Entry<String, List<Facet>> entry : entries) {
485 final List<Facet> fs = entry.getValue(); 482 final List<Facet> fs = entry.getValue();
486 483
487 f = fs.get(0); 484 f = fs.get(0);
488 if (f != null) { 485 if (f != null) {
489 break; 486 break;
490 } 487 }
491 } 488 }
492 489
493 return "[" + artifactUuid + ";" 490 return "[" + artifactUuid + ";" + f.getName() + ";" + f.getIndex() + ";" + recommendation.getDisplayName() + "]";
494 + f.getName() 491 }
495 + ";" 492
496 + f.getIndex() 493 return "[" + artifactUuid + ";" + factory + ";0;" + recommendation.getDisplayName() + "]";
497 + ";"
498 + recommendation.getDisplayName() + "]";
499 }
500
501 return "["
502 + artifactUuid
503 + ";" + factory + ";0;"
504 + recommendation.getDisplayName() + "]";
505 } 494 }
506 } 495 }

http://dive4elements.wald.intevation.org