Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/client/ui/CollectionView.java @ 5834:f507086aa94b
Repaired internal references.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:31:32 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java@adb6c0f14810 |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.client.ui; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 | |
5 import com.google.gwt.user.client.rpc.AsyncCallback; | |
6 | |
7 import com.smartgwt.client.util.SC; | |
8 | |
9 import com.smartgwt.client.widgets.Window; | |
10 | |
11 import com.smartgwt.client.widgets.events.CloseClickEvent; | |
12 import com.smartgwt.client.widgets.events.CloseClickHandler; | |
13 | |
14 import com.smartgwt.client.widgets.layout.Layout; | |
15 import com.smartgwt.client.widgets.layout.VLayout; | |
16 | |
17 import com.smartgwt.client.widgets.tab.TabSet; | |
18 | |
19 import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; | |
20 | |
21 import de.intevation.flys.client.client.Config; | |
22 import de.intevation.flys.client.client.FLYS; | |
23 import de.intevation.flys.client.client.FLYSConstants; | |
24 | |
25 import de.intevation.flys.client.client.event.CollectionChangeEvent; | |
26 import de.intevation.flys.client.client.event.CollectionChangeHandler; | |
27 import de.intevation.flys.client.client.event.HasCollectionChangeHandlers; | |
28 import de.intevation.flys.client.client.event.HasOutputModesChangeHandlers; | |
29 import de.intevation.flys.client.client.event.OutputModesChangeEvent; | |
30 import de.intevation.flys.client.client.event.OutputModesChangeHandler; | |
31 import de.intevation.flys.client.client.event.ParameterChangeEvent; | |
32 import de.intevation.flys.client.client.event.ParameterChangeHandler; | |
33 | |
34 import de.intevation.flys.client.client.services.AddArtifactService; | |
35 import de.intevation.flys.client.client.services.AddArtifactServiceAsync; | |
36 import de.intevation.flys.client.client.services.ArtifactService; | |
37 import de.intevation.flys.client.client.services.ArtifactServiceAsync; | |
38 import de.intevation.flys.client.client.services.CollectionAttributeService; | |
39 import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; | |
40 import de.intevation.flys.client.client.services.CreateCollectionService; | |
41 import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; | |
42 import de.intevation.flys.client.client.services.DescribeCollectionService; | |
43 import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync; | |
44 import de.intevation.flys.client.client.services.LoadArtifactService; | |
45 import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; | |
46 | |
47 import de.intevation.flys.client.client.ui.ScreenLock; | |
48 | |
49 import de.intevation.flys.client.shared.model.Artifact; | |
50 import de.intevation.flys.client.shared.model.ArtifactDescription; | |
51 import de.intevation.flys.client.shared.model.Collection; | |
52 import de.intevation.flys.client.shared.model.ExportMode; | |
53 import de.intevation.flys.client.shared.model.OutputMode; | |
54 import de.intevation.flys.client.shared.model.Recommendation; | |
55 import de.intevation.flys.client.shared.model.ReportMode; | |
56 import de.intevation.flys.client.shared.model.User; | |
57 | |
58 import java.util.ArrayList; | |
59 import java.util.HashMap; | |
60 import java.util.List; | |
61 import java.util.Map; | |
62 import java.util.Set; | |
63 import java.util.Stack; | |
64 | |
65 | |
66 /** | |
67 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
68 */ | |
69 public class CollectionView | |
70 extends Window | |
71 implements CollectionChangeHandler, HasCollectionChangeHandlers, | |
72 OutputModesChangeHandler, HasOutputModesChangeHandlers, | |
73 ParameterChangeHandler, CloseClickHandler | |
74 { | |
75 /** The ArtifactService used to communicate with the Artifact server. */ | |
76 protected CreateCollectionServiceAsync createCollectionService = | |
77 GWT.create(CreateCollectionService.class); | |
78 | |
79 /** The ArtifactService used to communicate with the Artifact server. */ | |
80 protected ArtifactServiceAsync createArtifactService = | |
81 GWT.create(ArtifactService.class); | |
82 | |
83 /** The AddArtifactService used to add an artifact to a collection. */ | |
84 protected AddArtifactServiceAsync addArtifactService = | |
85 GWT.create(AddArtifactService.class); | |
86 | |
87 /** The DescribeCollectionService used to update the existing collection. */ | |
88 protected DescribeCollectionServiceAsync describeCollectionService = | |
89 GWT.create(DescribeCollectionService.class); | |
90 | |
91 protected CollectionAttributeServiceAsync updater = | |
92 GWT.create(CollectionAttributeService.class); | |
93 | |
94 /** The LoadArtifactService used to load recommendations*/ | |
95 protected LoadArtifactServiceAsync loadArtifactService = | |
96 GWT.create(LoadArtifactService.class); | |
97 | |
98 /** The message class that provides i18n strings. */ | |
99 protected FLYSConstants messages = GWT.create(FLYSConstants.class); | |
100 | |
101 /** The FLYS instance used to call services. */ | |
102 protected FLYS flys; | |
103 | |
104 /** The ParameterList. */ | |
105 protected ParameterList parameterList; | |
106 | |
107 /** The list of CollectionChangeHandlers. */ | |
108 protected List<CollectionChangeHandler> handlers; | |
109 | |
110 /** The list of OutputModesChangeHandlers. */ | |
111 protected List<OutputModesChangeHandler> outHandlers; | |
112 | |
113 /** The collection to be displayed. */ | |
114 protected Collection collection; | |
115 | |
116 /** The artifact that handles the parameterization. */ | |
117 protected Artifact artifact; | |
118 | |
119 protected TabSet tabs; | |
120 | |
121 /** The output tab. */ | |
122 protected Map<String, OutputTab> outputTabs; | |
123 | |
124 /** The layout. */ | |
125 protected Layout layout; | |
126 | |
127 /** Layout to show spinning wheel of joy. */ | |
128 protected VLayout lockScreen; | |
129 | |
130 protected int artifactsQueue; | |
131 protected int recommendationQueue; | |
132 protected Stack<Recommendation> newRecommendations; | |
133 | |
134 /** Values for fix analysis charts*/ | |
135 protected double currentKm; | |
136 protected double minKm; | |
137 protected double maxKm; | |
138 protected double steps; | |
139 | |
140 /** | |
141 * This constructor creates a new CollectionView that is used to display the | |
142 * <i>collection</i>. | |
143 */ | |
144 public CollectionView(FLYS flys) { | |
145 this.flys = flys; | |
146 this.tabs = new TabSet(); | |
147 this.outputTabs = new HashMap<String, OutputTab>(); | |
148 this.handlers = new ArrayList<CollectionChangeHandler>(); | |
149 this.outHandlers = new ArrayList<OutputModesChangeHandler>(); | |
150 this.layout = new VLayout(); | |
151 this.parameterList = new ParameterList( | |
152 flys, this, messages.new_project()); | |
153 this.artifactsQueue = 0; | |
154 this.recommendationQueue = 0; | |
155 this.newRecommendations = new Stack<Recommendation>(); | |
156 | |
157 this.currentKm = -1d; | |
158 this.minKm = -1d; | |
159 this.maxKm = -1d; | |
160 this.steps = -1d; | |
161 | |
162 addCollectionChangeHandler(this); | |
163 addCollectionChangeHandler(parameterList); | |
164 addCollectionChangeHandler(flys); | |
165 addOutputModesChangeHandler(this); | |
166 addOutputModesChangeHandler(parameterList); | |
167 addCloseClickHandler(this); | |
168 | |
169 parameterList.addParameterChangeHandler(this); | |
170 | |
171 init(); | |
172 } | |
173 | |
174 /** | |
175 * @param collection The collection to be displayed. | |
176 */ | |
177 public CollectionView(FLYS flys, Collection collection, Artifact artifact) { | |
178 this.flys = flys; | |
179 this.artifact = artifact; | |
180 this.collection = collection; | |
181 this.tabs = new TabSet(); | |
182 this.outputTabs = new HashMap<String, OutputTab>(); | |
183 this.handlers = new ArrayList<CollectionChangeHandler>(); | |
184 this.outHandlers = new ArrayList<OutputModesChangeHandler>(); | |
185 this.layout = new VLayout(); | |
186 | |
187 this.currentKm = -1d; | |
188 this.minKm = -1d; | |
189 this.maxKm = -1d; | |
190 this.steps = -1d; | |
191 | |
192 if (artifact != null) { | |
193 this.parameterList = new ParameterList( | |
194 flys, | |
195 this, | |
196 messages.getString(artifact.getName()), | |
197 artifact); | |
198 } | |
199 else { | |
200 this.parameterList = new ParameterList( | |
201 flys, this, messages.new_project()); | |
202 } | |
203 | |
204 this.artifactsQueue = 0; | |
205 this.newRecommendations = new Stack<Recommendation>(); | |
206 | |
207 addCollectionChangeHandler(this); | |
208 addCollectionChangeHandler(parameterList); | |
209 addCollectionChangeHandler(flys); | |
210 addOutputModesChangeHandler(this); | |
211 addOutputModesChangeHandler(parameterList); | |
212 addCloseClickHandler(this); | |
213 | |
214 parameterList.addParameterChangeHandler(this); | |
215 | |
216 init(); | |
217 | |
218 setCollection(collection); | |
219 | |
220 if (artifact != null) { | |
221 setArtifact(artifact); | |
222 } | |
223 } | |
224 | |
225 | |
226 /** | |
227 * This method handles the initial layout stuff. | |
228 */ | |
229 protected void init() { | |
230 setWidth(1010); | |
231 setHeight(700); | |
232 | |
233 setMaximized(true); | |
234 | |
235 layout.setWidth100(); | |
236 | |
237 setCanDragReposition(true); | |
238 setCanDragResize(true); | |
239 setShowMaximizeButton(true); | |
240 setKeepInParentRect(true); | |
241 | |
242 setTitle(""); | |
243 | |
244 addItem(layout); | |
245 | |
246 layout.addMember(tabs); | |
247 tabs.addTab(parameterList); | |
248 } | |
249 | |
250 protected FLYS getFlys() { | |
251 return flys; | |
252 } | |
253 | |
254 | |
255 /** | |
256 * This method registers a new CollectionChangeHandler. | |
257 * | |
258 * @param handler The new CollectionChangeHandler. | |
259 */ | |
260 @Override | |
261 public void addCollectionChangeHandler(CollectionChangeHandler handler) { | |
262 if (handler != null) { | |
263 handlers.add(handler); | |
264 } | |
265 } | |
266 | |
267 | |
268 /** | |
269 * This method registers a new OutputModesChangeHandler. | |
270 * | |
271 * @param handler The new OutputModesChangeHandler. | |
272 */ | |
273 @Override | |
274 public void addOutputModesChangeHandler(OutputModesChangeHandler handler) { | |
275 if (handler != null) { | |
276 outHandlers.add(handler); | |
277 } | |
278 } | |
279 | |
280 | |
281 /** | |
282 * This method calls the <code>onValueChange()</code> method of all | |
283 * registered ValueChangeHanders. | |
284 */ | |
285 protected void fireCollectionChangeEvent( | |
286 Collection old, Collection newCol) | |
287 { | |
288 for (CollectionChangeHandler handler: handlers) { | |
289 handler.onCollectionChange(new CollectionChangeEvent(old, newCol)); | |
290 } | |
291 } | |
292 | |
293 | |
294 protected void fireOutputModesChangeEvent(OutputMode[] outputs) { | |
295 if (collection == null) { | |
296 return; | |
297 } | |
298 | |
299 for (OutputModesChangeHandler handler: outHandlers) { | |
300 handler.onOutputModesChange(new OutputModesChangeEvent(outputs)); | |
301 } | |
302 } | |
303 | |
304 | |
305 /** Disables input, grey out, show spinning wheel of joy. */ | |
306 public void lockUI() { | |
307 lockScreen = ScreenLock.lockUI(layout, lockScreen); | |
308 } | |
309 | |
310 | |
311 /** Enable input, remove grey, remove spinning wheel of joy. */ | |
312 public void unlockUI() { | |
313 ScreenLock.unlockUI(layout, lockScreen); | |
314 } | |
315 | |
316 | |
317 /** | |
318 * This method returns true, if the Collection is new and no plugins has | |
319 * been chosen. | |
320 * | |
321 * @return true, if the Collection is new. | |
322 */ | |
323 public boolean isNew() { | |
324 return collection.hasItems(); | |
325 } | |
326 | |
327 | |
328 /** | |
329 * Returns the artifact that is used for the parameterization. | |
330 * | |
331 * @return the artifact that is used for the parameterization. | |
332 */ | |
333 public Artifact getArtifact() { | |
334 return artifact; | |
335 } | |
336 | |
337 | |
338 public User getUser() { | |
339 return getFlys().getCurrentUser(); | |
340 } | |
341 | |
342 | |
343 /** | |
344 * Set the current artifact that is the master of the parameterization. | |
345 * | |
346 * @param artifact The new artifact. | |
347 */ | |
348 public void setArtifact(Artifact artifact) { | |
349 this.artifact = artifact; | |
350 | |
351 onArtifactChanged(artifact); | |
352 } | |
353 | |
354 | |
355 public void onArtifactChanged(Artifact artifact) { | |
356 artifactChanged(); | |
357 | |
358 if (artifact.isInBackground()) { | |
359 LoadingPanel p = new LoadingPanel(this, artifact); | |
360 p.addStepBackHandler(parameterList); | |
361 } | |
362 } | |
363 | |
364 | |
365 /** | |
366 * Implements the onCollectionChange() method to do update the GUI after the | |
367 * parameterization has changed. | |
368 * | |
369 * @param event The ParameterChangeEvent. | |
370 */ | |
371 @Override | |
372 public void onParameterChange(ParameterChangeEvent event) { | |
373 GWT.log("CollectionView.onParameterChange"); | |
374 setArtifact(event.getNewValue()); | |
375 } | |
376 | |
377 | |
378 protected void artifactChanged() { | |
379 Collection c = getCollection(); | |
380 | |
381 if (c != null) { | |
382 loadCollection(c); | |
383 } | |
384 else { | |
385 updateView(); | |
386 } | |
387 } | |
388 | |
389 /** | |
390 * Loads all information of a collection | |
391 * @param c the Collection | |
392 */ | |
393 private void loadCollection(Collection c) { | |
394 ArtifactDescription desc = getArtifact().getArtifactDescription(); | |
395 final Recommendation[] recom = desc.getRecommendations(); | |
396 Config config = Config.getInstance(); | |
397 String locale = config.getLocale(); | |
398 | |
399 describeCollectionService.describe(c.identifier(), locale, | |
400 new AsyncCallback<Collection>() { | |
401 @Override | |
402 public void onFailure(Throwable caught) { | |
403 GWT.log("Could not DESCRIBE collection."); | |
404 SC.warn(FLYS.getExceptionString(messages, caught)); | |
405 } | |
406 | |
407 @Override | |
408 public void onSuccess(Collection newCollection) { | |
409 GWT.log("Successfully DESCRIBED collection."); | |
410 boolean loaded = true; | |
411 for (Recommendation r: recom) { | |
412 if(!newCollection.loadedRecommendation(r)) { | |
413 loaded = false; | |
414 } | |
415 } | |
416 if (!loaded) { | |
417 loadRecommendedArtifacts(recom); | |
418 } | |
419 else { | |
420 setCollection(newCollection); | |
421 } | |
422 } | |
423 } | |
424 ); | |
425 } | |
426 | |
427 | |
428 /** | |
429 * Returns the collection of displayed by this view. | |
430 * | |
431 * @return the collection of this view. | |
432 */ | |
433 public Collection getCollection() { | |
434 return collection; | |
435 } | |
436 | |
437 | |
438 protected void setCollection(Collection collection) { | |
439 setCollection(collection, false); | |
440 } | |
441 | |
442 | |
443 /** | |
444 * Set the current collection. | |
445 * | |
446 * @param collection The new collection. | |
447 * @param suppress Whether to fire a collectionchangeevent. | |
448 */ | |
449 protected void setCollection(Collection collection, boolean suppress) { | |
450 if (collection != null && this.collection == null) { | |
451 flys.getWorkspace().addView(collection.identifier(), this); | |
452 } | |
453 | |
454 Collection tmp = this.collection; | |
455 this.collection = collection; | |
456 | |
457 setTitle(collection.getDisplayName()); | |
458 | |
459 if (!suppress) { | |
460 fireCollectionChangeEvent(tmp, this.collection); | |
461 } | |
462 } | |
463 | |
464 | |
465 @Override | |
466 public void onCollectionChange(CollectionChangeEvent event) { | |
467 if (artifactsQueue > 0) { | |
468 GWT.log("Do not update UI because we are still loading Artifacts."); | |
469 return; | |
470 } | |
471 | |
472 Collection newCol = event.getNewValue(); | |
473 | |
474 Map<String, OutputMode> outs = newCol.getOutputModes(); | |
475 | |
476 Set<String> keys = outs.keySet(); | |
477 OutputMode[] prepared = new OutputMode[outs.size()]; | |
478 | |
479 int idx = 0; | |
480 for (String outname: keys) { | |
481 prepared[idx++] = outs.get(outname); | |
482 } | |
483 | |
484 fireOutputModesChangeEvent(prepared); | |
485 | |
486 updateView(); | |
487 } | |
488 | |
489 | |
490 @Override | |
491 public void onOutputModesChange(OutputModesChangeEvent event) { | |
492 clearOutputTabs(); | |
493 OutputMode[] outs = event.getOutputModes(); | |
494 | |
495 if (outs == null) { | |
496 return; | |
497 } | |
498 | |
499 boolean hasCSV = false; | |
500 | |
501 for (OutputMode out: outs) { | |
502 addOutputTab(out.getName(), out); | |
503 | |
504 if (out instanceof ExportMode) { | |
505 ExportMode export = (ExportMode) out; | |
506 | |
507 if (export.getFacet("csv") != null) { | |
508 hasCSV = true; | |
509 parameterList.contractInfoPanel(); | |
510 } | |
511 } | |
512 } | |
513 | |
514 if (!hasCSV) { | |
515 parameterList.removeTable(); | |
516 } | |
517 } | |
518 | |
519 | |
520 /** | |
521 * Adds a new tab for the OutputMode <i>out</i>. | |
522 * | |
523 * @param name The name and title of the output. | |
524 */ | |
525 protected void addOutputTab(String name, OutputMode out) { | |
526 if (out instanceof ExportMode) { | |
527 ExportMode export = (ExportMode) out; | |
528 | |
529 if (export.getFacet("csv") != null && !parameterList.hasTable()) { | |
530 TableDataPanel p = new TableDataPanel(); | |
531 p.setUuid(collection.identifier()); | |
532 p.setName(out.getName()); | |
533 parameterList.setTable(p); | |
534 } | |
535 | |
536 return; | |
537 } | |
538 | |
539 if (out instanceof ReportMode) { | |
540 // we don't want to display report modes at all | |
541 return; | |
542 } | |
543 | |
544 GWT.log("Add new output tab for '" + name + "'"); | |
545 | |
546 String title = messages.getString(name); | |
547 OutputTab tab = out.createOutputTab(title, getCollection(), this); | |
548 | |
549 if (tab != null) { | |
550 outputTabs.put(name, tab); | |
551 } | |
552 } | |
553 | |
554 | |
555 /** | |
556 * Removes all output mode tabs from tab bar. | |
557 */ | |
558 protected void clearOutputTabs() { | |
559 GWT.log("Clear OutputTabs."); | |
560 | |
561 int num = tabs.getNumTabs(); | |
562 | |
563 for (int i = num-1; i >= 1; i--) { | |
564 tabs.removeTab(i); | |
565 } | |
566 | |
567 outputTabs.clear(); | |
568 } | |
569 | |
570 | |
571 /** | |
572 * Update the view (refresh the list of old and current data). | |
573 */ | |
574 protected void updateView() { | |
575 GWT.log("CollectionView.updateView()"); | |
576 updateOutputTabs(); | |
577 } | |
578 | |
579 | |
580 /** | |
581 * This method is used to update the tabs to show specific output modes. | |
582 */ | |
583 protected void updateOutputTabs() { | |
584 GWT.log("Update output tabs."); | |
585 if (outputTabs != null) { | |
586 Set<String> keys = outputTabs.keySet(); | |
587 | |
588 for (String key: keys) { | |
589 tabs.addTab(outputTabs.get(key)); | |
590 } | |
591 } | |
592 } | |
593 | |
594 | |
595 @Override | |
596 public void onCloseClick(CloseClickEvent event) { | |
597 if (collection != null) { | |
598 if(artifact != null) { | |
599 flys.closeProject(collection.identifier()); | |
600 } | |
601 else { | |
602 flys.getProjectList().deleteCollection(collection); | |
603 } | |
604 } | |
605 else { | |
606 hide(); | |
607 destroy(); | |
608 } | |
609 } | |
610 | |
611 | |
612 public void addArtifactToCollection(Artifact artifact) { | |
613 Config config = Config.getInstance(); | |
614 final String locale = config.getLocale(); | |
615 final Collection collection = getCollection(); | |
616 | |
617 GWT.log("CollectionView.addArtifactToCollection " + collection); | |
618 | |
619 if (collection != null) { | |
620 addArtifactService.add( | |
621 collection, artifact, locale, | |
622 new AsyncCallback<Collection>() { | |
623 @Override | |
624 public void onFailure(Throwable caught) { | |
625 GWT.log("An error occured while adding artifact."); | |
626 SC.warn(FLYS.getExceptionString(messages, caught)); | |
627 } | |
628 | |
629 @Override | |
630 public void onSuccess(Collection newCollection) { | |
631 GWT.log("Successfully added artifacts."); | |
632 setCollection(newCollection, true); | |
633 } | |
634 } | |
635 ); | |
636 } | |
637 else { | |
638 // Create new collection and add artifact | |
639 final Artifact art = artifact; | |
640 createCollectionService.create( | |
641 locale, | |
642 flys.getCurrentUser().identifier(), | |
643 new AsyncCallback<Collection>() { | |
644 @Override | |
645 public void onFailure(Throwable caught) { | |
646 GWT.log("Could not create the new collection."); | |
647 SC.warn(FLYS.getExceptionString(messages, caught)); | |
648 } | |
649 | |
650 @Override | |
651 public void onSuccess(Collection collection) { | |
652 GWT.log("Successfully created a new collection."); | |
653 addArtifactService.add( | |
654 collection, art, locale, | |
655 new AsyncCallback<Collection>() { | |
656 @Override | |
657 public void onFailure(Throwable caught) { | |
658 GWT.log("An error occured while adding artifact."); | |
659 SC.warn(FLYS.getExceptionString(messages, caught)); | |
660 } | |
661 | |
662 @Override | |
663 public void onSuccess(Collection newCollection) { | |
664 GWT.log("Successfully added artifacts."); | |
665 setCollection(newCollection); | |
666 } | |
667 } | |
668 ); | |
669 } | |
670 } | |
671 ); | |
672 } | |
673 } | |
674 | |
675 | |
676 protected void addRecommendationsToCollection() { | |
677 Config config = Config.getInstance(); | |
678 final String locale = config.getLocale(); | |
679 final Collection collection = getCollection(); | |
680 | |
681 collection.addRecommendations(newRecommendations); | |
682 | |
683 updater.update(collection, locale, | |
684 new AsyncCallback<Collection>() { | |
685 @Override | |
686 public void onFailure(Throwable caught) { | |
687 newRecommendations.removeAllElements(); | |
688 setCollection(collection); | |
689 | |
690 GWT.log("An error occured while saving recommendations."); | |
691 SC.warn(FLYS.getExceptionString(messages, caught)); | |
692 } | |
693 | |
694 @Override | |
695 public void onSuccess(Collection newCol) { | |
696 GWT.log("Successfully saved recommendations."); | |
697 newRecommendations.removeAllElements(); | |
698 setCollection(newCol); | |
699 } | |
700 } | |
701 ); | |
702 } | |
703 | |
704 | |
705 protected void loadRecommendedArtifacts(Recommendation[] recommendations) { | |
706 Config config = Config.getInstance(); | |
707 final String locale = config.getLocale(); | |
708 final Collection collection = getCollection(); | |
709 | |
710 Artifact masterArtifact = getArtifact(); | |
711 | |
712 if (recommendations == null) { | |
713 GWT.log("WARNING: Currently no recommendations."); | |
714 return; | |
715 } | |
716 | |
717 for (final Recommendation recommendation: recommendations) { | |
718 if (collection.loadedRecommendation(recommendation)) { | |
719 continue; | |
720 } | |
721 newRecommendations.push(recommendation); | |
722 | |
723 // XXX: UGLY! If no reference artifact given use uuid of | |
724 // current artifact as reference. | |
725 if (recommendation.getMasterArtifact() == null) { | |
726 recommendation.setMasterArtifact(masterArtifact.getUuid()); | |
727 } | |
728 | |
729 } | |
730 | |
731 loadArtifactService.loadMany( | |
732 collection, | |
733 recommendations, | |
734 null, | |
735 locale, | |
736 new AsyncCallback<Artifact[]>() { | |
737 @Override | |
738 public void onFailure(Throwable caught) { | |
739 GWT.log("Error loading recommendations: " + | |
740 caught.getMessage()); | |
741 SC.warn(FLYS.getExceptionString(messages, caught)); | |
742 } | |
743 | |
744 @Override | |
745 public void onSuccess(Artifact[] artifacts) { | |
746 GWT.log("Loaded artifacts: " + artifacts.length); | |
747 addRecommendationsToCollection(); | |
748 } | |
749 }); | |
750 } | |
751 | |
752 | |
753 public void registerTabHandler(TabSelectedHandler tse) { | |
754 tabs.addTabSelectedHandler(tse); | |
755 } | |
756 | |
757 | |
758 public void setCurrentKm(double currentKm) { | |
759 this.currentKm = currentKm; | |
760 } | |
761 | |
762 public double getCurrentKm() { | |
763 return this.currentKm; | |
764 } | |
765 | |
766 public void setMinKm(double km) { | |
767 this.minKm = km; | |
768 } | |
769 | |
770 public double getMinKm() { | |
771 return this.minKm; | |
772 } | |
773 | |
774 public void setMaxKm(double km) { | |
775 this.maxKm = km; | |
776 } | |
777 | |
778 public double getMaxKm() { | |
779 return this.maxKm; | |
780 } | |
781 | |
782 public void setSteps(double step) { | |
783 this.steps = step; | |
784 } | |
785 | |
786 public double getSteps() { | |
787 return this.steps; | |
788 } | |
789 } | |
790 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |