teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5861: * Software engineering by Intevation GmbH teichmann@5861: * teichmann@5993: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5993: * documentation coming with Dive4Elements River for details. teichmann@5861: */ teichmann@5861: teichmann@5835: package org.dive4elements.river.client.client.ui; ingo@6: gernotbelger@9150: import java.util.ArrayList; gernotbelger@9150: import java.util.HashMap; gernotbelger@9150: import java.util.List; gernotbelger@9150: import java.util.Map; gernotbelger@9150: import java.util.Set; gernotbelger@9150: import java.util.Stack; ingo@6: teichmann@5835: import org.dive4elements.river.client.client.Config; teichmann@5835: import org.dive4elements.river.client.client.FLYS; teichmann@5835: import org.dive4elements.river.client.client.FLYSConstants; teichmann@5835: import org.dive4elements.river.client.client.event.CollectionChangeEvent; teichmann@5835: import org.dive4elements.river.client.client.event.CollectionChangeHandler; teichmann@5835: import org.dive4elements.river.client.client.event.HasCollectionChangeHandlers; teichmann@5835: import org.dive4elements.river.client.client.event.HasOutputModesChangeHandlers; teichmann@5835: import org.dive4elements.river.client.client.event.OutputModesChangeEvent; teichmann@5835: import org.dive4elements.river.client.client.event.OutputModesChangeHandler; teichmann@5835: import org.dive4elements.river.client.client.event.ParameterChangeEvent; teichmann@5835: import org.dive4elements.river.client.client.event.ParameterChangeHandler; teichmann@5835: import org.dive4elements.river.client.client.services.AddArtifactService; teichmann@5835: import org.dive4elements.river.client.client.services.AddArtifactServiceAsync; teichmann@5835: import org.dive4elements.river.client.client.services.CollectionAttributeService; teichmann@5835: import org.dive4elements.river.client.client.services.CollectionAttributeServiceAsync; teichmann@5835: import org.dive4elements.river.client.client.services.CreateCollectionService; teichmann@5835: import org.dive4elements.river.client.client.services.CreateCollectionServiceAsync; teichmann@5835: import org.dive4elements.river.client.client.services.DescribeCollectionService; teichmann@5835: import org.dive4elements.river.client.client.services.DescribeCollectionServiceAsync; teichmann@5835: import org.dive4elements.river.client.client.services.LoadArtifactService; teichmann@5835: import org.dive4elements.river.client.client.services.LoadArtifactServiceAsync; teichmann@5835: import org.dive4elements.river.client.shared.model.Artifact; teichmann@5835: import org.dive4elements.river.client.shared.model.ArtifactDescription; teichmann@5835: import org.dive4elements.river.client.shared.model.Collection; teichmann@5835: import org.dive4elements.river.client.shared.model.ExportMode; teichmann@5835: import org.dive4elements.river.client.shared.model.OutputMode; teichmann@5835: import org.dive4elements.river.client.shared.model.Recommendation; teichmann@5835: import org.dive4elements.river.client.shared.model.ReportMode; teichmann@5835: import org.dive4elements.river.client.shared.model.User; ingo@6: gernotbelger@9150: import com.google.gwt.core.client.GWT; gernotbelger@9150: import com.google.gwt.user.client.rpc.AsyncCallback; gernotbelger@9150: import com.smartgwt.client.util.SC; gernotbelger@9150: import com.smartgwt.client.widgets.Window; gernotbelger@9150: import com.smartgwt.client.widgets.events.CloseClickEvent; gernotbelger@9150: import com.smartgwt.client.widgets.events.CloseClickHandler; gernotbelger@9150: import com.smartgwt.client.widgets.layout.Layout; gernotbelger@9150: import com.smartgwt.client.widgets.layout.VLayout; gernotbelger@9150: import com.smartgwt.client.widgets.tab.TabSet; gernotbelger@9150: import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; ingo@6: ingo@6: /** ingo@6: * @author Ingo Weinzierl ingo@6: */ gernotbelger@9150: public class CollectionView extends Window implements CollectionChangeHandler, HasCollectionChangeHandlers, OutputModesChangeHandler, HasOutputModesChangeHandlers, ParameterChangeHandler, CloseClickHandler { gernotbelger@9263: gernotbelger@9263: /** The message class that provides i18n strings. */ gernotbelger@9263: private static final FLYSConstants messages = GWT.create(FLYSConstants.class); ingo@26: ingo@803: /** The ArtifactService used to communicate with the Artifact server. */ gernotbelger@9263: private final CreateCollectionServiceAsync createCollectionService = GWT.create(CreateCollectionService.class); ingo@803: ingo@71: /** The AddArtifactService used to add an artifact to a collection. */ gernotbelger@9263: private final AddArtifactServiceAsync addArtifactService = GWT.create(AddArtifactService.class); ingo@71: ingo@100: /** The DescribeCollectionService used to update the existing collection. */ gernotbelger@9263: private final DescribeCollectionServiceAsync describeCollectionService = GWT.create(DescribeCollectionService.class); ingo@100: gernotbelger@9263: private final CollectionAttributeServiceAsync updater = GWT.create(CollectionAttributeService.class); ingo@809: gernotbelger@9150: /** The LoadArtifactService used to load recommendations */ gernotbelger@9263: private final LoadArtifactServiceAsync loadArtifactService = GWT.create(LoadArtifactService.class); ingo@6: felix@864: /** The FLYS instance used to call services. */ gernotbelger@9263: private final FLYS flys; ingo@13: felix@864: /** The ParameterList. */ gernotbelger@9263: private ParameterList parameterList; ingo@23: felix@864: /** The list of CollectionChangeHandlers. */ gernotbelger@9263: private final List handlers; ingo@19: felix@864: /** The list of OutputModesChangeHandlers. */ gernotbelger@9263: private final List outHandlers; ingo@513: felix@864: /** The collection to be displayed. */ gernotbelger@9263: private Collection collection; ingo@6: felix@864: /** The artifact that handles the parameterization. */ gernotbelger@9263: private Artifact artifact; ingo@30: gernotbelger@9263: private final TabSet tabs; ingo@23: felix@864: /** The output tab. */ gernotbelger@9263: private final Map outputTabs; ingo@7: felix@864: /** The layout. */ gernotbelger@9263: private final Layout layout; sascha@3366: felix@5487: /** Layout to show spinning wheel of joy. */ gernotbelger@9263: private VLayout lockScreen; ingo@23: gernotbelger@9263: private final int artifactsQueue; gernotbelger@9263: private final Stack newRecommendations; ingo@809: gernotbelger@9150: /** Values for fix analysis charts */ gernotbelger@9263: private double currentKm; ingo@6: ingo@6: /** ingo@6: * This constructor creates a new CollectionView that is used to display the ingo@6: * collection. ingo@6: */ gernotbelger@9150: public CollectionView(final FLYS flys) { gernotbelger@9150: this.flys = flys; gernotbelger@9150: this.tabs = new TabSet(); gernotbelger@9150: this.outputTabs = new HashMap(); gernotbelger@9150: this.handlers = new ArrayList(); gernotbelger@9150: this.outHandlers = new ArrayList(); gernotbelger@9150: this.layout = new VLayout(); gernotbelger@9263: this.parameterList = new ParameterList(flys, this, CollectionView.messages.new_project()); gernotbelger@9150: this.artifactsQueue = 0; gernotbelger@9150: this.newRecommendations = new Stack(); ingo@19: raimund@2906: this.currentKm = -1d; raimund@2906: ingo@19: addCollectionChangeHandler(this); gernotbelger@9150: addCollectionChangeHandler(this.parameterList); ingo@611: addCollectionChangeHandler(flys); ingo@513: addOutputModesChangeHandler(this); gernotbelger@9150: addOutputModesChangeHandler(this.parameterList); ingo@557: addCloseClickHandler(this); ingo@73: gernotbelger@9150: this.parameterList.addParameterChangeHandler(this); ingo@19: ingo@6: init(); ingo@6: } ingo@6: felix@1557: /** gernotbelger@9150: * @param collection gernotbelger@9150: * The collection to be displayed. felix@1557: */ gernotbelger@9150: public CollectionView(final FLYS flys, final Collection collection, final Artifact artifact) { gernotbelger@9150: this.flys = flys; gernotbelger@9150: this.artifact = artifact; gernotbelger@9150: this.collection = collection; gernotbelger@9150: this.tabs = new TabSet(); gernotbelger@9150: this.outputTabs = new HashMap(); gernotbelger@9150: this.handlers = new ArrayList(); gernotbelger@9150: this.outHandlers = new ArrayList(); gernotbelger@9150: this.layout = new VLayout(); ingo@1294: raimund@2906: this.currentKm = -1d; raimund@2906: ingo@1294: if (artifact != null) { gernotbelger@9150: this.parameterList = new ParameterList(flys, this, gernotbelger@9150: // FIXME: literally every information about the artifact is transported from the server side gernotbelger@9150: // but... the international name is resolved client-side.... Instead also transport the description of the artifact and gernotbelger@9150: // use it! gernotbelger@9150: // FIXME: the same holds for a very few other international strings (e.g. names of facets used in Tabs) gernotbelger@9263: CollectionView.messages.getString(artifact.getName()), artifact); gernotbelger@9150: } else { gernotbelger@9263: this.parameterList = new ParameterList(flys, this, CollectionView.messages.new_project()); ingo@1294: } ingo@1294: gernotbelger@9150: this.artifactsQueue = 0; ingo@809: this.newRecommendations = new Stack(); ingo@224: ingo@224: addCollectionChangeHandler(this); gernotbelger@9150: addCollectionChangeHandler(this.parameterList); ingo@611: addCollectionChangeHandler(flys); ingo@513: addOutputModesChangeHandler(this); gernotbelger@9150: addOutputModesChangeHandler(this.parameterList); ingo@557: addCloseClickHandler(this); ingo@224: gernotbelger@9150: this.parameterList.addParameterChangeHandler(this); ingo@224: ingo@224: init(); ingo@224: ingo@224: setCollection(collection); ingo@1294: ingo@1294: if (artifact != null) { ingo@1294: setArtifact(artifact); ingo@1294: } ingo@224: } ingo@224: ingo@6: /** ingo@6: * This method handles the initial layout stuff. ingo@6: */ gernotbelger@9263: private void init() { christian@3347: setWidth(1010); christian@3347: setHeight(700); sascha@3547: christian@3522: setMaximized(true); sascha@3547: gernotbelger@9150: this.layout.setWidth100(); ingo@23: raimund@77: setCanDragReposition(true); ingo@6: setCanDragResize(true); ingo@437: setShowMaximizeButton(true); raimund@77: setKeepInParentRect(true); ingo@6: ingo@84: setTitle(""); ingo@7: gernotbelger@9150: addItem(this.layout); ingo@7: gernotbelger@9150: this.layout.addMember(this.tabs); gernotbelger@9150: this.tabs.addTab(this.parameterList); ingo@7: } ingo@7: gernotbelger@9263: private FLYS getFlys() { gernotbelger@9150: return this.flys; ingo@26: } ingo@26: ingo@26: /** felix@864: * This method registers a new CollectionChangeHandler. ingo@19: * gernotbelger@9150: * @param handler gernotbelger@9150: * The new CollectionChangeHandler. ingo@19: */ christian@2983: @Override gernotbelger@9150: public void addCollectionChangeHandler(final CollectionChangeHandler handler) { ingo@19: if (handler != null) { gernotbelger@9150: this.handlers.add(handler); ingo@19: } ingo@19: } ingo@19: ingo@513: /** ingo@513: * This method registers a new OutputModesChangeHandler. ingo@513: * gernotbelger@9150: * @param handler gernotbelger@9150: * The new OutputModesChangeHandler. ingo@513: */ christian@2983: @Override gernotbelger@9150: public void addOutputModesChangeHandler(final OutputModesChangeHandler handler) { ingo@513: if (handler != null) { gernotbelger@9150: this.outHandlers.add(handler); ingo@513: } ingo@513: } ingo@513: ingo@36: /** ingo@19: * This method calls the onValueChange() method of all ingo@19: * registered ValueChangeHanders. ingo@19: */ gernotbelger@9263: private void fireCollectionChangeEvent(final Collection old, final Collection newCol) { gernotbelger@9150: for (final CollectionChangeHandler handler : this.handlers) { ingo@19: handler.onCollectionChange(new CollectionChangeEvent(old, newCol)); ingo@19: } ingo@19: } ingo@19: gernotbelger@9263: private void fireOutputModesChangeEvent(final OutputMode[] outputs) { gernotbelger@9150: if (this.collection == null) { ingo@513: return; ingo@513: } ingo@513: gernotbelger@9150: for (final OutputModesChangeHandler handler : this.outHandlers) { ingo@513: handler.onOutputModesChange(new OutputModesChangeEvent(outputs)); ingo@513: } ingo@513: } sascha@3366: ingo@3549: /** Disables input, grey out, show spinning wheel of joy. */ ingo@3353: public void lockUI() { gernotbelger@9150: this.lockScreen = ScreenLock.lockUI(this.layout, this.lockScreen); ingo@3353: } sascha@3366: ingo@3549: /** Enable input, remove grey, remove spinning wheel of joy. */ ingo@3353: public void unlockUI() { gernotbelger@9150: ScreenLock.unlockUI(this.layout, this.lockScreen); ingo@3353: } ingo@513: ingo@19: /** ingo@71: * Returns the artifact that is used for the parameterization. ingo@71: * ingo@71: * @return the artifact that is used for the parameterization. ingo@71: */ ingo@521: public Artifact getArtifact() { gernotbelger@9150: return this.artifact; ingo@71: } ingo@71: sascha@811: public User getUser() { sascha@811: return getFlys().getCurrentUser(); sascha@811: } sascha@811: ingo@71: /** ingo@30: * Set the current artifact that is the master of the parameterization. ingo@30: * gernotbelger@9150: * @param artifact gernotbelger@9150: * The new artifact. ingo@30: */ gernotbelger@9150: public void setArtifact(final Artifact artifact) { ingo@30: this.artifact = artifact; ingo@862: ingo@1270: artifactChanged(); ingo@1270: ingo@862: if (artifact.isInBackground()) { gernotbelger@9150: final LoadingPanel p = new LoadingPanel(this, artifact); gernotbelger@9150: p.addStepBackHandler(this.parameterList); ingo@862: } ingo@36: } ingo@36: ingo@36: /** ingo@36: * Implements the onCollectionChange() method to do update the GUI after the ingo@36: * parameterization has changed. ingo@36: * gernotbelger@9150: * @param event gernotbelger@9150: * The ParameterChangeEvent. ingo@36: */ christian@2983: @Override gernotbelger@9150: public void onParameterChange(final ParameterChangeEvent event) { ingo@100: GWT.log("CollectionView.onParameterChange"); ingo@1270: setArtifact(event.getNewValue()); ingo@1270: } ingo@100: gernotbelger@9263: private void artifactChanged() { gernotbelger@9150: final Collection c = getCollection(); ingo@100: ingo@908: if (c != null) { bjoern@4661: loadCollection(c); gernotbelger@9150: } else { ingo@71: updateView(); ingo@71: } ingo@6: } ingo@13: bjoern@4661: /** felix@6578: * Loads all information of a collection. felix@6578: * If 'recommendations' present, load these. gernotbelger@9263: * gernotbelger@9150: * @param c gernotbelger@9150: * the Collection bjoern@4661: */ gernotbelger@9150: private void loadCollection(final Collection c) { gernotbelger@9150: final ArtifactDescription desc = getArtifact().getArtifactDescription(); bjoern@4661: final Recommendation[] recom = desc.getRecommendations(); gernotbelger@9263: final String locale = Config.getInstance().getLocale(); bjoern@4661: gernotbelger@9150: this.describeCollectionService.describe(c.identifier(), locale, new AsyncCallback() { gernotbelger@9150: @Override gernotbelger@9150: public void onFailure(final Throwable caught) { gernotbelger@9150: GWT.log("Could not DESCRIBE collection."); gernotbelger@9150: SC.warn(FLYS.getExceptionString(CollectionView.this.messages, caught)); gernotbelger@9150: } bjoern@4661: gernotbelger@9150: @Override gernotbelger@9150: public void onSuccess(final Collection newCollection) { gernotbelger@9150: GWT.log("Successfully DESCRIBED collection."); gernotbelger@9150: boolean loaded = true; gernotbelger@9150: for (final Recommendation r : recom) { gernotbelger@9150: if (!newCollection.loadedRecommendation(r)) { gernotbelger@9150: loaded = false; bjoern@4661: } bjoern@4661: } gernotbelger@9150: if (!loaded) { gernotbelger@9150: loadRecommendedArtifacts(recom); gernotbelger@9150: } else { gernotbelger@9150: setCollection(newCollection); gernotbelger@9150: } bjoern@4661: } gernotbelger@9150: }); bjoern@4661: } bjoern@4661: ingo@13: /** ingo@74: * Returns the collection of displayed by this view. ingo@74: * ingo@74: * @return the collection of this view. ingo@74: */ ingo@537: public Collection getCollection() { gernotbelger@9150: return this.collection; ingo@74: } ingo@74: gernotbelger@9263: private void setCollection(final Collection collection) { ingo@908: setCollection(collection, false); ingo@908: } ingo@908: ingo@74: /** ingo@19: * Set the current collection. ingo@13: * gernotbelger@9150: * @param collection gernotbelger@9150: * The new collection. gernotbelger@9150: * @param suppress gernotbelger@9150: * Whether to fire a collectionchangeevent. ingo@13: */ gernotbelger@9263: public void setCollection(final Collection collection, final boolean suppress) { ingo@601: if (collection != null && this.collection == null) { gernotbelger@9150: this.flys.getWorkspace().addView(collection.identifier(), this); ingo@601: } ingo@601: gernotbelger@9150: final Collection tmp = this.collection; ingo@19: this.collection = collection; ingo@13: gernotbelger@9263: if (collection != null) gernotbelger@9263: setTitle(collection.getDisplayName()); ingo@908: gernotbelger@9263: if (!suppress) ingo@908: fireCollectionChangeEvent(tmp, this.collection); ingo@19: } ingo@19: christian@2983: @Override gernotbelger@9150: public void onCollectionChange(final CollectionChangeEvent event) { gernotbelger@9150: if (this.artifactsQueue > 0) { ingo@809: GWT.log("Do not update UI because we are still loading Artifacts."); ingo@809: return; ingo@809: } ingo@809: gernotbelger@9150: final Collection newCol = event.getNewValue(); ingo@74: gernotbelger@9150: final Map outs = newCol.getOutputModes(); ingo@74: gernotbelger@9150: final Set keys = outs.keySet(); gernotbelger@9150: final OutputMode[] prepared = new OutputMode[outs.size()]; ingo@513: ingo@513: int idx = 0; gernotbelger@9150: for (final String outname : keys) { ingo@513: prepared[idx++] = outs.get(outname); ingo@74: } ingo@74: ingo@513: fireOutputModesChangeEvent(prepared); ingo@513: ingo@13: updateView(); ingo@13: } ingo@13: christian@2983: @Override gernotbelger@9150: public void onOutputModesChange(final OutputModesChangeEvent event) { ingo@788: clearOutputTabs(); gernotbelger@9150: final OutputMode[] outs = event.getOutputModes(); ingo@513: ingo@513: if (outs == null) { ingo@513: return; ingo@513: } ingo@513: ingo@788: boolean hasCSV = false; ingo@788: gernotbelger@9150: for (final OutputMode out : outs) { ingo@513: addOutputTab(out.getName(), out); ingo@788: ingo@788: if (out instanceof ExportMode) { gernotbelger@9150: final ExportMode export = (ExportMode) out; ingo@788: ingo@788: if (export.getFacet("csv") != null) { ingo@788: hasCSV = true; ingo@788: } ingo@788: } ingo@788: } ingo@788: ingo@788: if (!hasCSV) { gernotbelger@9150: this.parameterList.removeTable(); ingo@513: } ingo@513: } ingo@513: ingo@36: /** ingo@74: * Adds a new tab for the OutputMode out. ingo@74: * gernotbelger@9150: * @param name gernotbelger@9150: * The name and title of the output. ingo@74: */ gernotbelger@9263: private void addOutputTab(final String name, final OutputMode out) { ingo@270: if (out instanceof ExportMode) { gernotbelger@9150: final ExportMode export = (ExportMode) out; raimund@256: gernotbelger@9150: if (export.getFacet("csv") != null && !this.parameterList.hasTable()) { gernotbelger@9150: final TableDataPanel p = new TableDataPanel(); gernotbelger@9150: p.setUuid(this.collection.identifier()); ingo@270: p.setName(out.getName()); gernotbelger@9150: this.parameterList.setTable(p); ingo@270: } ingo@270: ingo@239: return; ingo@239: } ingo@239: ingo@593: if (out instanceof ReportMode) { ingo@593: // we don't want to display report modes at all ingo@593: return; ingo@593: } ingo@593: ingo@74: GWT.log("Add new output tab for '" + name + "'"); ingo@75: gernotbelger@9263: final String title = CollectionView.messages.getString(name); gernotbelger@9150: final OutputTab tab = out.createOutputTab(title, getCollection(), this); ingo@796: gernotbelger@9263: if (tab != null) gernotbelger@9150: this.outputTabs.put(name, tab); ingo@74: } ingo@74: ingo@74: /** ingo@74: * Removes all output mode tabs from tab bar. ingo@74: */ gernotbelger@9263: private void clearOutputTabs() { ingo@74: GWT.log("Clear OutputTabs."); ingo@74: gernotbelger@9150: final int num = this.tabs.getNumTabs(); ingo@74: gernotbelger@9150: for (int i = num - 1; i >= 1; i--) { gernotbelger@9150: this.tabs.removeTab(i); ingo@74: } ingo@74: gernotbelger@9150: this.outputTabs.clear(); ingo@74: } ingo@74: ingo@74: /** ingo@23: * Update the view (refresh the list of old and current data). ingo@23: */ gernotbelger@9263: private void updateView() { ingo@36: GWT.log("CollectionView.updateView()"); ingo@74: updateOutputTabs(); ingo@74: } ingo@23: ingo@74: /** ingo@74: * This method is used to update the tabs to show specific output modes. ingo@74: */ gernotbelger@9263: private void updateOutputTabs() { ingo@74: GWT.log("Update output tabs."); gernotbelger@9150: if (this.outputTabs != null) { gernotbelger@9150: final Set keys = this.outputTabs.keySet(); ingo@74: gernotbelger@9150: for (final String key : keys) { gernotbelger@9150: this.tabs.addTab(this.outputTabs.get(key)); ingo@74: } ingo@74: } ingo@13: } ingo@557: christian@2983: @Override gernotbelger@9150: public void onCloseClick(final CloseClickEvent event) { gernotbelger@9150: if (this.collection != null) { gernotbelger@9150: if (this.artifact != null) { gernotbelger@9150: this.flys.closeProject(this.collection.identifier()); gernotbelger@9150: } else { gernotbelger@9150: this.flys.getProjectList().deleteCollection(this.collection); christian@3501: } gernotbelger@9150: } else { ingo@611: hide(); ingo@611: destroy(); ingo@611: } ingo@557: } ingo@803: gernotbelger@9150: public void addArtifactToCollection(final Artifact artifact) { gernotbelger@9263: final String locale = Config.getInstance().getLocale(); ingo@803: gernotbelger@9263: GWT.log("CollectionView.addArtifactToCollection " + this.collection); bjoern@4659: gernotbelger@9263: if (this.collection != null) { gernotbelger@9263: this.addArtifactService.add(this.collection, artifact, locale, new AsyncCallback() { gernotbelger@9150: @Override gernotbelger@9150: public void onFailure(final Throwable caught) { gernotbelger@9150: GWT.log("An error occured while adding artifact."); gernotbelger@9150: SC.warn(FLYS.getExceptionString(CollectionView.this.messages, caught)); gernotbelger@9150: } bjoern@4659: gernotbelger@9150: @Override gernotbelger@9150: public void onSuccess(final Collection newCollection) { gernotbelger@9150: GWT.log("Successfully added artifacts."); gernotbelger@9150: setCollection(newCollection); ingo@803: } gernotbelger@9150: }); gernotbelger@9150: } else { felix@6578: // Create new collection and add artifact. bjoern@4659: final Artifact art = artifact; gernotbelger@9150: this.createCollectionService.create(locale, this.flys.getCurrentUser().identifier(), new AsyncCallback() { gernotbelger@9150: @Override gernotbelger@9150: public void onFailure(final Throwable caught) { gernotbelger@9150: GWT.log("Could not create the new collection."); gernotbelger@9263: SC.warn(FLYS.getExceptionString(CollectionView.messages, caught)); gernotbelger@9150: } ingo@803: gernotbelger@9150: @Override gernotbelger@9150: public void onSuccess(final Collection collection) { gernotbelger@9150: GWT.log("Successfully created a new collection."); gernotbelger@9150: CollectionView.this.addArtifactService.add(collection, art, locale, new AsyncCallback() { gernotbelger@9150: @Override gernotbelger@9150: public void onFailure(final Throwable caught) { gernotbelger@9150: GWT.log("An error occured while " + "adding artifact."); gernotbelger@9150: SC.warn(FLYS.getExceptionString(CollectionView.this.messages, caught)); gernotbelger@9150: } bjoern@4659: gernotbelger@9150: @Override gernotbelger@9150: public void onSuccess(final Collection newCollection) { gernotbelger@9150: GWT.log("Successfully added artifacts."); gernotbelger@9150: setCollection(newCollection); gernotbelger@9150: } gernotbelger@9150: }); ingo@809: } gernotbelger@9150: }); bjoern@4659: } ingo@809: } ingo@809: gernotbelger@9263: private void addRecommendationsToCollection() { gernotbelger@9263: final String locale = Config.getInstance().getLocale(); ingo@809: gernotbelger@9263: this.collection.addRecommendations(this.newRecommendations); ingo@809: gernotbelger@9263: this.updater.update(this.collection, locale, new AsyncCallback() { gernotbelger@9150: @Override gernotbelger@9150: public void onFailure(final Throwable caught) { gernotbelger@9150: CollectionView.this.newRecommendations.removeAllElements(); gernotbelger@9263: setCollection(CollectionView.this.collection); ingo@809: gernotbelger@9150: GWT.log("An error occured while saving recommendations."); gernotbelger@9150: SC.warn(FLYS.getExceptionString(CollectionView.this.messages, caught)); ingo@803: } gernotbelger@9150: gernotbelger@9150: @Override gernotbelger@9150: public void onSuccess(final Collection newCol) { gernotbelger@9150: GWT.log("Successfully saved recommendations."); gernotbelger@9150: CollectionView.this.newRecommendations.removeAllElements(); gernotbelger@9150: setCollection(newCol); gernotbelger@9150: } gernotbelger@9150: }); ingo@803: } ingo@803: gernotbelger@9263: private void loadRecommendedArtifacts(final Recommendation[] recommendations) { gernotbelger@9263: final String locale = Config.getInstance().getLocale(); ingo@803: gernotbelger@9150: final Artifact masterArtifact = getArtifact(); sascha@847: felix@819: if (recommendations == null) { felix@819: GWT.log("WARNING: Currently no recommendations."); felix@819: return; felix@819: } felix@819: gernotbelger@9150: for (final Recommendation recommendation : recommendations) { gernotbelger@9263: if (this.collection.loadedRecommendation(recommendation)) { andre@8717: continue; andre@8717: } gernotbelger@9150: this.newRecommendations.push(recommendation); andre@8717: sascha@847: // XXX: UGLY! If no reference artifact given use uuid of gernotbelger@9150: // current artifact as reference. sascha@847: if (recommendation.getMasterArtifact() == null) { sascha@847: recommendation.setMasterArtifact(masterArtifact.getUuid()); sascha@847: } sascha@847: raimund@1515: } ingo@807: gernotbelger@9263: this.loadArtifactService.loadMany(this.collection, recommendations, null, locale, new AsyncCallback() { gernotbelger@9150: @Override gernotbelger@9150: public void onFailure(final Throwable caught) { gernotbelger@9150: GWT.log("Error loading recommendations: " + caught.getMessage()); gernotbelger@9263: SC.warn(FLYS.getExceptionString(CollectionView.messages, caught)); gernotbelger@9150: } ingo@803: gernotbelger@9150: @Override gernotbelger@9150: public void onSuccess(final Artifact[] artifacts) { gernotbelger@9150: GWT.log("Loaded artifacts: " + artifacts.length); gernotbelger@9150: addRecommendationsToCollection(); gernotbelger@9150: } raimund@1515: }); ingo@803: } raimund@915: gernotbelger@9150: public void registerTabHandler(final TabSelectedHandler tse) { gernotbelger@9150: this.tabs.addTabSelectedHandler(tse); raimund@915: } raimund@2906: gernotbelger@9150: public void setCurrentKm(final double currentKm) { raimund@2906: this.currentKm = currentKm; raimund@2906: } raimund@2906: raimund@2906: public double getCurrentKm() { raimund@2906: return this.currentKm; raimund@2906: } gernotbelger@9263: }