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:
ingo@6: import com.google.gwt.core.client.GWT;
teichmann@5566:
ingo@13: import com.google.gwt.user.client.rpc.AsyncCallback;
christian@4127:
ingo@215: import com.smartgwt.client.util.SC;
teichmann@5566:
ingo@6: import com.smartgwt.client.widgets.Window;
teichmann@5566:
raimund@1619: import com.smartgwt.client.widgets.events.CloseClickEvent;
ingo@557: import com.smartgwt.client.widgets.events.CloseClickHandler;
teichmann@5566:
ingo@23: import com.smartgwt.client.widgets.layout.Layout;
ingo@7: import com.smartgwt.client.widgets.layout.VLayout;
teichmann@5566:
ingo@23: import com.smartgwt.client.widgets.tab.TabSet;
teichmann@5566:
raimund@915: import com.smartgwt.client.widgets.tab.events.TabSelectedHandler;
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@5566:
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@5566:
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.ArtifactService;
teichmann@5835: import org.dive4elements.river.client.client.services.ArtifactServiceAsync;
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@5566:
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:
christian@2983: import java.util.ArrayList;
christian@2983: import java.util.HashMap;
christian@2983: import java.util.List;
christian@2983: import java.util.Map;
christian@2983: import java.util.Set;
christian@2983: import java.util.Stack;
ingo@6:
ingo@6:
ingo@6: /**
ingo@6: * @author Ingo Weinzierl
ingo@6: */
ingo@19: public class CollectionView
ingo@19: extends Window
ingo@23: implements CollectionChangeHandler, HasCollectionChangeHandlers,
ingo@513: OutputModesChangeHandler, HasOutputModesChangeHandlers,
ingo@557: ParameterChangeHandler, CloseClickHandler
ingo@23: {
ingo@13: /** The ArtifactService used to communicate with the Artifact server. */
ingo@26: protected CreateCollectionServiceAsync createCollectionService =
ingo@26: GWT.create(CreateCollectionService.class);
ingo@26:
ingo@803: /** The ArtifactService used to communicate with the Artifact server. */
ingo@803: protected ArtifactServiceAsync createArtifactService =
ingo@803: GWT.create(ArtifactService.class);
ingo@803:
ingo@71: /** The AddArtifactService used to add an artifact to a collection. */
ingo@71: protected AddArtifactServiceAsync addArtifactService =
ingo@71: GWT.create(AddArtifactService.class);
ingo@71:
ingo@100: /** The DescribeCollectionService used to update the existing collection. */
ingo@100: protected DescribeCollectionServiceAsync describeCollectionService =
ingo@100: GWT.create(DescribeCollectionService.class);
ingo@100:
ingo@809: protected CollectionAttributeServiceAsync updater =
ingo@809: GWT.create(CollectionAttributeService.class);
ingo@809:
raimund@1515: /** The LoadArtifactService used to load recommendations*/
raimund@1515: protected LoadArtifactServiceAsync loadArtifactService =
raimund@1515: GWT.create(LoadArtifactService.class);
raimund@1515:
felix@864: /** The message class that provides i18n strings. */
ingo@211: protected FLYSConstants messages = GWT.create(FLYSConstants.class);
ingo@6:
felix@864: /** The FLYS instance used to call services. */
ingo@13: protected FLYS flys;
ingo@13:
felix@864: /** The ParameterList. */
ingo@23: protected ParameterList parameterList;
ingo@23:
felix@864: /** The list of CollectionChangeHandlers. */
ingo@19: protected List handlers;
ingo@19:
felix@864: /** The list of OutputModesChangeHandlers. */
ingo@513: protected List outHandlers;
ingo@513:
felix@864: /** The collection to be displayed. */
ingo@6: protected Collection collection;
ingo@6:
felix@864: /** The artifact that handles the parameterization. */
ingo@30: protected Artifact artifact;
ingo@30:
ingo@23: protected TabSet tabs;
ingo@23:
felix@864: /** The output tab. */
ingo@74: protected Map outputTabs;
ingo@7:
felix@864: /** The layout. */
ingo@23: protected Layout layout;
sascha@3366:
felix@5487: /** Layout to show spinning wheel of joy. */
ingo@3353: protected VLayout lockScreen;
ingo@23:
ingo@809: protected int artifactsQueue;
raimund@1512: protected int recommendationQueue;
ingo@809: protected Stack newRecommendations;
ingo@809:
raimund@2906: /** Values for fix analysis charts*/
raimund@2906: protected double currentKm;
raimund@2906: protected double minKm;
raimund@2906: protected double maxKm;
raimund@2906: protected double steps;
ingo@6:
ingo@6: /**
ingo@6: * This constructor creates a new CollectionView that is used to display the
ingo@6: * collection.
ingo@6: */
ingo@100: public CollectionView(FLYS flys) {
ingo@100: this.flys = flys;
ingo@100: this.tabs = new TabSet();
ingo@100: this.outputTabs = new HashMap();
ingo@100: this.handlers = new ArrayList();
ingo@513: this.outHandlers = new ArrayList();
ingo@100: this.layout = new VLayout();
ingo@100: this.parameterList = new ParameterList(
raimund@92: flys, this, messages.new_project());
felix@3363: this.artifactsQueue = 0;
raimund@1512: this.recommendationQueue = 0;
felix@3363: this.newRecommendations = new Stack();
ingo@19:
raimund@2906: this.currentKm = -1d;
raimund@2906: this.minKm = -1d;
raimund@2906: this.maxKm = -1d;
raimund@2906: this.steps = -1d;
raimund@2906:
ingo@19: addCollectionChangeHandler(this);
ingo@275: addCollectionChangeHandler(parameterList);
ingo@611: addCollectionChangeHandler(flys);
ingo@513: addOutputModesChangeHandler(this);
ingo@513: addOutputModesChangeHandler(parameterList);
ingo@557: addCloseClickHandler(this);
ingo@73:
ingo@73: parameterList.addParameterChangeHandler(this);
ingo@19:
ingo@6: init();
ingo@6: }
ingo@6:
felix@1557: /**
felix@1557: * @param collection The collection to be displayed.
felix@1557: */
ingo@224: public CollectionView(FLYS flys, Collection collection, Artifact artifact) {
ingo@224: this.flys = flys;
ingo@825: this.artifact = artifact;
ingo@825: this.collection = collection;
ingo@224: this.tabs = new TabSet();
ingo@224: this.outputTabs = new HashMap();
ingo@224: this.handlers = new ArrayList();
ingo@513: this.outHandlers = new ArrayList();
ingo@224: this.layout = new VLayout();
ingo@1294:
raimund@2906: this.currentKm = -1d;
raimund@2906: this.minKm = -1d;
raimund@2906: this.maxKm = -1d;
raimund@2906: this.steps = -1d;
raimund@2906:
ingo@1294: if (artifact != null) {
ingo@1294: this.parameterList = new ParameterList(
ingo@1294: flys,
ingo@1294: this,
gernotbelger@8853: // FIXME: literally every information about the artifact is transported from the server side
gernotbelger@8853: // but... the international name is resolved client-side.... Instead also transport the description of the artifact and use it!
gernotbelger@8853: // FIXME: the same holds for a very few other international strings (e.g. names of facets used in Tabs)
ingo@1294: messages.getString(artifact.getName()),
ingo@1294: artifact);
ingo@1294: }
ingo@1294: else {
ingo@1294: this.parameterList = new ParameterList(
ingo@1294: flys, this, messages.new_project());
ingo@1294: }
ingo@1294:
ingo@809: this.artifactsQueue = 0;
ingo@809: this.newRecommendations = new Stack();
ingo@224:
ingo@224: addCollectionChangeHandler(this);
ingo@275: addCollectionChangeHandler(parameterList);
ingo@611: addCollectionChangeHandler(flys);
ingo@513: addOutputModesChangeHandler(this);
ingo@513: addOutputModesChangeHandler(parameterList);
ingo@557: addCloseClickHandler(this);
ingo@224:
ingo@224: 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@224:
ingo@6: /**
ingo@6: * This method handles the initial layout stuff.
ingo@6: */
ingo@6: protected void init() {
christian@3347: setWidth(1010);
christian@3347: setHeight(700);
sascha@3547:
christian@3522: setMaximized(true);
sascha@3547:
ingo@23: 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:
ingo@7: addItem(layout);
ingo@7:
ingo@23: layout.addMember(tabs);
ingo@90: tabs.addTab(parameterList);
ingo@7: }
ingo@7:
ingo@26: protected FLYS getFlys() {
ingo@26: return flys;
ingo@26: }
ingo@26:
ingo@26:
ingo@26: /**
felix@864: * This method registers a new CollectionChangeHandler.
ingo@19: *
felix@864: * @param handler The new CollectionChangeHandler.
ingo@19: */
christian@2983: @Override
ingo@19: public void addCollectionChangeHandler(CollectionChangeHandler handler) {
ingo@19: if (handler != null) {
ingo@19: handlers.add(handler);
ingo@19: }
ingo@19: }
ingo@19:
ingo@19:
ingo@513: /**
ingo@513: * This method registers a new OutputModesChangeHandler.
ingo@513: *
ingo@513: * @param handler The new OutputModesChangeHandler.
ingo@513: */
christian@2983: @Override
ingo@513: public void addOutputModesChangeHandler(OutputModesChangeHandler handler) {
ingo@513: if (handler != null) {
ingo@513: outHandlers.add(handler);
ingo@513: }
ingo@513: }
ingo@513:
ingo@513:
ingo@36: /**
ingo@19: * This method calls the onValueChange()
method of all
ingo@19: * registered ValueChangeHanders.
ingo@19: */
ingo@19: protected void fireCollectionChangeEvent(
ingo@19: Collection old, Collection newCol)
ingo@19: {
ingo@19: for (CollectionChangeHandler handler: handlers) {
ingo@19: handler.onCollectionChange(new CollectionChangeEvent(old, newCol));
ingo@19: }
ingo@19: }
ingo@19:
ingo@19:
ingo@513: protected void fireOutputModesChangeEvent(OutputMode[] outputs) {
ingo@513: if (collection == null) {
ingo@513: return;
ingo@513: }
ingo@513:
ingo@513: for (OutputModesChangeHandler handler: outHandlers) {
ingo@513: handler.onOutputModesChange(new OutputModesChangeEvent(outputs));
ingo@513: }
ingo@513: }
sascha@3366:
sascha@3366:
ingo@3549: /** Disables input, grey out, show spinning wheel of joy. */
ingo@3353: public void lockUI() {
felix@5487: lockScreen = ScreenLock.lockUI(layout, lockScreen);
ingo@3353: }
sascha@3366:
sascha@3366:
ingo@3549: /** Enable input, remove grey, remove spinning wheel of joy. */
ingo@3353: public void unlockUI() {
felix@5487: ScreenLock.unlockUI(layout, lockScreen);
ingo@3353: }
ingo@513:
ingo@513:
ingo@19: /**
ingo@7: * This method returns true, if the Collection is new and no plugins has
ingo@7: * been chosen.
ingo@7: *
ingo@7: * @return true, if the Collection is new.
ingo@7: */
ingo@7: public boolean isNew() {
bjoern@4660: return collection.hasItems();
ingo@7: }
ingo@7:
ingo@7:
ingo@7: /**
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() {
ingo@71: return artifact;
ingo@71: }
ingo@71:
felix@864:
sascha@811: public User getUser() {
sascha@811: return getFlys().getCurrentUser();
sascha@811: }
sascha@811:
ingo@71:
ingo@71: /**
ingo@30: * Set the current artifact that is the master of the parameterization.
ingo@30: *
ingo@30: * @param artifact The new artifact.
ingo@30: */
ingo@521: public void setArtifact(Artifact artifact) {
ingo@30: this.artifact = artifact;
ingo@862:
ingo@862: onArtifactChanged(artifact);
ingo@862: }
ingo@862:
ingo@862:
ingo@862: public void onArtifactChanged(Artifact artifact) {
ingo@1270: artifactChanged();
ingo@1270:
ingo@862: if (artifact.isInBackground()) {
ingo@1432: LoadingPanel p = new LoadingPanel(this, artifact);
ingo@1432: p.addStepBackHandler(parameterList);
ingo@862: }
ingo@36: }
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: *
ingo@36: * @param event The ParameterChangeEvent.
ingo@36: */
christian@2983: @Override
ingo@36: public void onParameterChange(ParameterChangeEvent event) {
ingo@100: GWT.log("CollectionView.onParameterChange");
ingo@1270: setArtifact(event.getNewValue());
ingo@1270: }
ingo@100:
ingo@1270:
ingo@1270: protected void artifactChanged() {
ingo@229: Collection c = getCollection();
ingo@100:
ingo@908: if (c != null) {
bjoern@4661: loadCollection(c);
ingo@100: }
ingo@71: 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.
bjoern@4661: * @param c the Collection
bjoern@4661: */
bjoern@4661: private void loadCollection(Collection c) {
bjoern@4661: ArtifactDescription desc = getArtifact().getArtifactDescription();
bjoern@4661: final Recommendation[] recom = desc.getRecommendations();
bjoern@4661: Config config = Config.getInstance();
bjoern@4661: String locale = config.getLocale();
bjoern@4661:
bjoern@4661: describeCollectionService.describe(c.identifier(), locale,
bjoern@4661: new AsyncCallback() {
bjoern@4661: @Override
bjoern@4661: public void onFailure(Throwable caught) {
bjoern@4661: GWT.log("Could not DESCRIBE collection.");
bjoern@4661: SC.warn(FLYS.getExceptionString(messages, caught));
bjoern@4661: }
bjoern@4661:
bjoern@4661: @Override
bjoern@4661: public void onSuccess(Collection newCollection) {
bjoern@4661: GWT.log("Successfully DESCRIBED collection.");
bjoern@4661: boolean loaded = true;
bjoern@4661: for (Recommendation r: recom) {
bjoern@4661: if(!newCollection.loadedRecommendation(r)) {
bjoern@4661: loaded = false;
bjoern@4661: }
bjoern@4661: }
bjoern@4661: if (!loaded) {
bjoern@4661: loadRecommendedArtifacts(recom);
bjoern@4661: }
bjoern@4661: else {
bjoern@4661: setCollection(newCollection);
bjoern@4661: }
bjoern@4661: }
bjoern@4661: }
bjoern@4661: );
bjoern@4661: }
bjoern@4661:
ingo@13:
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() {
ingo@74: return collection;
ingo@74: }
ingo@74:
ingo@74:
ingo@908: protected void setCollection(Collection collection) {
ingo@908: setCollection(collection, false);
ingo@908: }
ingo@908:
ingo@908:
ingo@74: /**
ingo@19: * Set the current collection.
ingo@13: *
ingo@19: * @param collection The new collection.
felix@1557: * @param suppress Whether to fire a collectionchangeevent.
ingo@13: */
ingo@908: protected void setCollection(Collection collection, boolean suppress) {
ingo@601: if (collection != null && this.collection == null) {
ingo@601: flys.getWorkspace().addView(collection.identifier(), this);
ingo@601: }
ingo@601:
ingo@19: Collection tmp = this.collection;
ingo@19: this.collection = collection;
ingo@13:
bjoern@4690: setTitle(collection.getDisplayName());
ingo@908:
ingo@908: if (!suppress) {
ingo@908: fireCollectionChangeEvent(tmp, this.collection);
ingo@908: }
ingo@19: }
ingo@19:
ingo@19:
christian@2983: @Override
ingo@19: public void onCollectionChange(CollectionChangeEvent event) {
ingo@809: if (artifactsQueue > 0) {
ingo@809: GWT.log("Do not update UI because we are still loading Artifacts.");
ingo@809: return;
ingo@809: }
ingo@809:
ingo@74: Collection newCol = event.getNewValue();
ingo@74:
ingo@74: Map outs = newCol.getOutputModes();
ingo@74:
ingo@513: Set keys = outs.keySet();
ingo@513: OutputMode[] prepared = new OutputMode[outs.size()];
ingo@513:
ingo@513: int idx = 0;
ingo@74: for (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:
ingo@13:
christian@2983: @Override
ingo@513: public void onOutputModesChange(OutputModesChangeEvent event) {
ingo@788: clearOutputTabs();
ingo@513: 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:
ingo@513: for (OutputMode out: outs) {
ingo@513: addOutputTab(out.getName(), out);
ingo@788:
ingo@788: if (out instanceof ExportMode) {
ingo@788: 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) {
ingo@788: parameterList.removeTable();
ingo@513: }
ingo@513: }
ingo@513:
ingo@513:
ingo@36: /**
ingo@74: * Adds a new tab for the OutputMode out.
ingo@74: *
ingo@74: * @param name The name and title of the output.
ingo@74: */
ingo@74: protected void addOutputTab(String name, OutputMode out) {
ingo@270: if (out instanceof ExportMode) {
ingo@270: ExportMode export = (ExportMode) out;
raimund@256:
ingo@788: if (export.getFacet("csv") != null && !parameterList.hasTable()) {
ingo@270: TableDataPanel p = new TableDataPanel();
ingo@270: p.setUuid(collection.identifier());
ingo@270: p.setName(out.getName());
ingo@788: 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:
ingo@796: String title = messages.getString(name);
ingo@796: OutputTab tab = out.createOutputTab(title, getCollection(), this);
ingo@796:
ingo@796: if (tab != null) {
ingo@796: outputTabs.put(name, tab);
ingo@796: }
ingo@74: }
ingo@74:
ingo@74:
ingo@74: /**
ingo@74: * Removes all output mode tabs from tab bar.
ingo@74: */
ingo@74: protected void clearOutputTabs() {
ingo@74: GWT.log("Clear OutputTabs.");
ingo@74:
ingo@74: int num = tabs.getNumTabs();
ingo@74:
ingo@74: for (int i = num-1; i >= 1; i--) {
ingo@74: tabs.removeTab(i);
ingo@74: }
ingo@74:
ingo@74: outputTabs.clear();
ingo@74: }
ingo@74:
ingo@74:
ingo@74: /**
ingo@23: * Update the view (refresh the list of old and current data).
ingo@23: */
ingo@13: protected void updateView() {
ingo@36: GWT.log("CollectionView.updateView()");
ingo@74: updateOutputTabs();
ingo@74: }
ingo@23:
ingo@74:
ingo@74: /**
ingo@74: * This method is used to update the tabs to show specific output modes.
ingo@74: */
ingo@74: protected void updateOutputTabs() {
ingo@74: GWT.log("Update output tabs.");
ingo@74: if (outputTabs != null) {
ingo@74: Set keys = outputTabs.keySet();
ingo@74:
ingo@74: for (String key: keys) {
ingo@74: tabs.addTab(outputTabs.get(key));
ingo@74: }
ingo@74: }
ingo@13: }
ingo@557:
ingo@557:
christian@2983: @Override
raimund@1619: public void onCloseClick(CloseClickEvent event) {
ingo@611: if (collection != null) {
christian@3501: if(artifact != null) {
christian@3501: flys.closeProject(collection.identifier());
christian@3501: }
christian@3501: else {
christian@3501: flys.getProjectList().deleteCollection(collection);
christian@3501: }
ingo@611: }
ingo@611: else {
ingo@611: hide();
ingo@611: destroy();
ingo@611: }
ingo@557: }
ingo@803:
ingo@803:
raimund@1515: public void addArtifactToCollection(Artifact artifact) {
ingo@803: Config config = Config.getInstance();
ingo@803: final String locale = config.getLocale();
ingo@803: final Collection collection = getCollection();
ingo@803:
bjoern@4659: GWT.log("CollectionView.addArtifactToCollection " + collection);
bjoern@4659:
bjoern@4659: if (collection != null) {
bjoern@4659: addArtifactService.add(
bjoern@4659: collection, artifact, locale,
bjoern@4659: new AsyncCallback() {
bjoern@4659: @Override
bjoern@4659: public void onFailure(Throwable caught) {
bjoern@4659: GWT.log("An error occured while adding artifact.");
bjoern@4659: SC.warn(FLYS.getExceptionString(messages, caught));
bjoern@4659: }
bjoern@4659:
bjoern@4659: @Override
bjoern@4659: public void onSuccess(Collection newCollection) {
bjoern@4659: GWT.log("Successfully added artifacts.");
rrenkert@8313: setCollection(newCollection);
bjoern@4659: }
ingo@803: }
bjoern@4659: );
bjoern@4659: }
bjoern@4659: else {
felix@6578: // Create new collection and add artifact.
bjoern@4659: final Artifact art = artifact;
bjoern@4659: createCollectionService.create(
bjoern@4659: locale,
bjoern@4659: flys.getCurrentUser().identifier(),
bjoern@4659: new AsyncCallback() {
bjoern@4659: @Override
bjoern@4659: public void onFailure(Throwable caught) {
bjoern@4659: GWT.log("Could not create the new collection.");
bjoern@4659: SC.warn(FLYS.getExceptionString(messages, caught));
bjoern@4659: }
ingo@803:
bjoern@4659: @Override
bjoern@4659: public void onSuccess(Collection collection) {
bjoern@4659: GWT.log("Successfully created a new collection.");
bjoern@4659: addArtifactService.add(
bjoern@4659: collection, art, locale,
bjoern@4659: new AsyncCallback() {
bjoern@4659: @Override
bjoern@4659: public void onFailure(Throwable caught) {
tom@8856: GWT.log("An error occured while "
tom@8856: + "adding artifact.");
tom@8856: SC.warn(FLYS.getExceptionString(
tom@8856: messages, caught));
bjoern@4659: }
bjoern@4659:
bjoern@4659: @Override
tom@8856: public void onSuccess(
tom@8856: Collection newCollection) {
bjoern@4659: GWT.log("Successfully added artifacts.");
bjoern@4659: setCollection(newCollection);
bjoern@4659: }
bjoern@4659: }
bjoern@4659: );
bjoern@4659: }
ingo@809: }
bjoern@4659: );
bjoern@4659: }
ingo@809: }
ingo@809:
ingo@809:
ingo@809: protected void addRecommendationsToCollection() {
ingo@809: Config config = Config.getInstance();
ingo@809: final String locale = config.getLocale();
ingo@809: final Collection collection = getCollection();
ingo@809:
ingo@809: collection.addRecommendations(newRecommendations);
ingo@809:
raimund@1425: updater.update(collection, locale,
ingo@809: new AsyncCallback() {
christian@2983: @Override
ingo@809: public void onFailure(Throwable caught) {
ingo@809: newRecommendations.removeAllElements();
ingo@809: setCollection(collection);
ingo@809:
ingo@809: GWT.log("An error occured while saving recommendations.");
christian@4127: SC.warn(FLYS.getExceptionString(messages, caught));
ingo@809: }
ingo@809:
christian@2983: @Override
ingo@809: public void onSuccess(Collection newCol) {
ingo@809: GWT.log("Successfully saved recommendations.");
ingo@809: newRecommendations.removeAllElements();
raimund@1515: setCollection(newCol);
ingo@803: }
ingo@803: }
ingo@803: );
ingo@803: }
ingo@803:
ingo@803:
ingo@807: protected void loadRecommendedArtifacts(Recommendation[] recommendations) {
ingo@803: Config config = Config.getInstance();
ingo@803: final String locale = config.getLocale();
ingo@803: final Collection collection = getCollection();
ingo@803:
sascha@847: 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:
ingo@809: for (final Recommendation recommendation: recommendations) {
andre@8717: if (collection.loadedRecommendation(recommendation)) {
andre@8717: continue;
andre@8717: }
andre@8717: newRecommendations.push(recommendation);
andre@8717:
sascha@847: // XXX: UGLY! If no reference artifact given use uuid of
sascha@2905: // current artifact as reference.
sascha@847: if (recommendation.getMasterArtifact() == null) {
sascha@847: recommendation.setMasterArtifact(masterArtifact.getUuid());
sascha@847: }
sascha@847:
raimund@1515: }
ingo@807:
raimund@1515: loadArtifactService.loadMany(
raimund@1515: collection,
andre@8718: recommendations,
raimund@1515: null,
raimund@1515: locale,
raimund@1515: new AsyncCallback() {
christian@2983: @Override
raimund@1515: public void onFailure(Throwable caught) {
raimund@1515: GWT.log("Error loading recommendations: " +
raimund@1515: caught.getMessage());
christian@4127: SC.warn(FLYS.getExceptionString(messages, caught));
raimund@1515: }
ingo@803:
christian@2983: @Override
raimund@1515: public void onSuccess(Artifact[] artifacts) {
raimund@1515: GWT.log("Loaded artifacts: " + artifacts.length);
raimund@1515: addRecommendationsToCollection();
raimund@1515: }
raimund@1515: });
ingo@803: }
raimund@915:
raimund@915:
raimund@915: public void registerTabHandler(TabSelectedHandler tse) {
raimund@915: tabs.addTabSelectedHandler(tse);
raimund@915: }
raimund@2906:
raimund@2906:
raimund@2906: public void setCurrentKm(double currentKm) {
raimund@2906: this.currentKm = currentKm;
raimund@2906: }
raimund@2906:
raimund@2906: public double getCurrentKm() {
raimund@2906: return this.currentKm;
raimund@2906: }
raimund@2906:
raimund@2906: public void setMinKm(double km) {
raimund@2906: this.minKm = km;
raimund@2906: }
raimund@2906:
raimund@2906: public double getMinKm() {
raimund@2906: return this.minKm;
raimund@2906: }
raimund@2906:
raimund@2906: public void setMaxKm(double km) {
raimund@2906: this.maxKm = km;
raimund@2906: }
raimund@2906:
raimund@2906: public double getMaxKm() {
raimund@2906: return this.maxKm;
raimund@2906: }
raimund@2906:
raimund@2906: public void setSteps(double step) {
raimund@2906: this.steps = step;
raimund@2906: }
raimund@2906:
raimund@2906: public double getSteps() {
raimund@2906: return this.steps;
raimund@2906: }
ingo@6: }
ingo@6: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :