diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/CollectionView.java @ 9263:abf14917be32

Moved stepping behaviour of NaviOutputChart into an exchangeable strategy. Allows for distinct values stepping of sinfo flood duration.
author gernotbelger
date Tue, 17 Jul 2018 19:48:18 +0200
parents 23945061daec
children c81cf7e2a770
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/CollectionView.java	Tue Jul 17 19:48:09 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/CollectionView.java	Tue Jul 17 19:48:18 2018 +0200
@@ -28,8 +28,6 @@
 import org.dive4elements.river.client.client.event.ParameterChangeHandler;
 import org.dive4elements.river.client.client.services.AddArtifactService;
 import org.dive4elements.river.client.client.services.AddArtifactServiceAsync;
-import org.dive4elements.river.client.client.services.ArtifactService;
-import org.dive4elements.river.client.client.services.ArtifactServiceAsync;
 import org.dive4elements.river.client.client.services.CollectionAttributeService;
 import org.dive4elements.river.client.client.services.CollectionAttributeServiceAsync;
 import org.dive4elements.river.client.client.services.CreateCollectionService;
@@ -62,64 +60,58 @@
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
 public class CollectionView extends Window implements CollectionChangeHandler, HasCollectionChangeHandlers, OutputModesChangeHandler, HasOutputModesChangeHandlers, ParameterChangeHandler, CloseClickHandler {
-    /** The ArtifactService used to communicate with the Artifact server. */
-    protected CreateCollectionServiceAsync createCollectionService = GWT.create(CreateCollectionService.class);
+
+    /** The message class that provides i18n strings. */
+    private static final FLYSConstants messages = GWT.create(FLYSConstants.class);
 
     /** The ArtifactService used to communicate with the Artifact server. */
-    protected ArtifactServiceAsync createArtifactService = GWT.create(ArtifactService.class);
+    private final CreateCollectionServiceAsync createCollectionService = GWT.create(CreateCollectionService.class);
 
     /** The AddArtifactService used to add an artifact to a collection. */
-    protected AddArtifactServiceAsync addArtifactService = GWT.create(AddArtifactService.class);
+    private final AddArtifactServiceAsync addArtifactService = GWT.create(AddArtifactService.class);
 
     /** The DescribeCollectionService used to update the existing collection. */
-    protected DescribeCollectionServiceAsync describeCollectionService = GWT.create(DescribeCollectionService.class);
+    private final DescribeCollectionServiceAsync describeCollectionService = GWT.create(DescribeCollectionService.class);
 
-    protected CollectionAttributeServiceAsync updater = GWT.create(CollectionAttributeService.class);
+    private final CollectionAttributeServiceAsync updater = GWT.create(CollectionAttributeService.class);
 
     /** The LoadArtifactService used to load recommendations */
-    protected LoadArtifactServiceAsync loadArtifactService = GWT.create(LoadArtifactService.class);
-
-    /** The message class that provides i18n strings. */
-    protected FLYSConstants messages = GWT.create(FLYSConstants.class);
+    private final LoadArtifactServiceAsync loadArtifactService = GWT.create(LoadArtifactService.class);
 
     /** The FLYS instance used to call services. */
-    protected FLYS flys;
+    private final FLYS flys;
 
     /** The ParameterList. */
-    protected ParameterList parameterList;
+    private ParameterList parameterList;
 
     /** The list of CollectionChangeHandlers. */
-    protected List<CollectionChangeHandler> handlers;
+    private final List<CollectionChangeHandler> handlers;
 
     /** The list of OutputModesChangeHandlers. */
-    protected List<OutputModesChangeHandler> outHandlers;
+    private final List<OutputModesChangeHandler> outHandlers;
 
     /** The collection to be displayed. */
-    protected Collection collection;
+    private Collection collection;
 
     /** The artifact that handles the parameterization. */
-    protected Artifact artifact;
+    private Artifact artifact;
 
-    protected TabSet tabs;
+    private final TabSet tabs;
 
     /** The output tab. */
-    protected Map<String, OutputTab> outputTabs;
+    private final Map<String, OutputTab> outputTabs;
 
     /** The layout. */
-    protected Layout layout;
+    private final Layout layout;
 
     /** Layout to show spinning wheel of joy. */
-    protected VLayout lockScreen;
+    private VLayout lockScreen;
 
-    protected int artifactsQueue;
-    protected int recommendationQueue;
-    protected Stack<Recommendation> newRecommendations;
+    private final int artifactsQueue;
+    private final Stack<Recommendation> newRecommendations;
 
     /** Values for fix analysis charts */
-    protected double currentKm;
-    protected double minKm;
-    protected double maxKm;
-    protected double steps;
+    private double currentKm;
 
     /**
      * This constructor creates a new CollectionView that is used to display the
@@ -132,15 +124,11 @@
         this.handlers = new ArrayList<CollectionChangeHandler>();
         this.outHandlers = new ArrayList<OutputModesChangeHandler>();
         this.layout = new VLayout();
-        this.parameterList = new ParameterList(flys, this, this.messages.new_project());
+        this.parameterList = new ParameterList(flys, this, CollectionView.messages.new_project());
         this.artifactsQueue = 0;
-        this.recommendationQueue = 0;
         this.newRecommendations = new Stack<Recommendation>();
 
         this.currentKm = -1d;
-        this.minKm = -1d;
-        this.maxKm = -1d;
-        this.steps = -1d;
 
         addCollectionChangeHandler(this);
         addCollectionChangeHandler(this.parameterList);
@@ -169,9 +157,6 @@
         this.layout = new VLayout();
 
         this.currentKm = -1d;
-        this.minKm = -1d;
-        this.maxKm = -1d;
-        this.steps = -1d;
 
         if (artifact != null) {
             this.parameterList = new ParameterList(flys, this,
@@ -179,9 +164,9 @@
                     // but... the international name is resolved client-side.... Instead also transport the description of the artifact and
                     // use it!
                     // FIXME: the same holds for a very few other international strings (e.g. names of facets used in Tabs)
-                    this.messages.getString(artifact.getName()), artifact);
+                    CollectionView.messages.getString(artifact.getName()), artifact);
         } else {
-            this.parameterList = new ParameterList(flys, this, this.messages.new_project());
+            this.parameterList = new ParameterList(flys, this, CollectionView.messages.new_project());
         }
 
         this.artifactsQueue = 0;
@@ -208,7 +193,7 @@
     /**
      * This method handles the initial layout stuff.
      */
-    protected void init() {
+    private void init() {
         setWidth(1010);
         setHeight(700);
 
@@ -229,7 +214,7 @@
         this.tabs.addTab(this.parameterList);
     }
 
-    protected FLYS getFlys() {
+    private FLYS getFlys() {
         return this.flys;
     }
 
@@ -263,13 +248,13 @@
      * This method calls the <code>onValueChange()</code> method of all
      * registered ValueChangeHanders.
      */
-    protected void fireCollectionChangeEvent(final Collection old, final Collection newCol) {
+    private void fireCollectionChangeEvent(final Collection old, final Collection newCol) {
         for (final CollectionChangeHandler handler : this.handlers) {
             handler.onCollectionChange(new CollectionChangeEvent(old, newCol));
         }
     }
 
-    protected void fireOutputModesChangeEvent(final OutputMode[] outputs) {
+    private void fireOutputModesChangeEvent(final OutputMode[] outputs) {
         if (this.collection == null) {
             return;
         }
@@ -290,16 +275,6 @@
     }
 
     /**
-     * This method returns true, if the Collection is new and no plugins has
-     * been chosen.
-     *
-     * @return true, if the Collection is new.
-     */
-    public boolean isNew() {
-        return this.collection.hasItems();
-    }
-
-    /**
      * Returns the artifact that is used for the parameterization.
      *
      * @return the artifact that is used for the parameterization.
@@ -321,10 +296,6 @@
     public void setArtifact(final Artifact artifact) {
         this.artifact = artifact;
 
-        onArtifactChanged(artifact);
-    }
-
-    public void onArtifactChanged(final Artifact artifact) {
         artifactChanged();
 
         if (artifact.isInBackground()) {
@@ -346,7 +317,7 @@
         setArtifact(event.getNewValue());
     }
 
-    protected void artifactChanged() {
+    private void artifactChanged() {
         final Collection c = getCollection();
 
         if (c != null) {
@@ -359,15 +330,14 @@
     /**
      * Loads all information of a collection.
      * If 'recommendations' present, load these.
-     * 
+     *
      * @param c
      *            the Collection
      */
     private void loadCollection(final Collection c) {
         final ArtifactDescription desc = getArtifact().getArtifactDescription();
         final Recommendation[] recom = desc.getRecommendations();
-        final Config config = Config.getInstance();
-        final String locale = config.getLocale();
+        final String locale = Config.getInstance().getLocale();
 
         this.describeCollectionService.describe(c.identifier(), locale, new AsyncCallback<Collection>() {
             @Override
@@ -403,7 +373,7 @@
         return this.collection;
     }
 
-    protected void setCollection(final Collection collection) {
+    private void setCollection(final Collection collection) {
         setCollection(collection, false);
     }
 
@@ -415,7 +385,7 @@
      * @param suppress
      *            Whether to fire a collectionchangeevent.
      */
-    protected void setCollection(final Collection collection, final boolean suppress) {
+    public void setCollection(final Collection collection, final boolean suppress) {
         if (collection != null && this.collection == null) {
             this.flys.getWorkspace().addView(collection.identifier(), this);
         }
@@ -423,11 +393,11 @@
         final Collection tmp = this.collection;
         this.collection = collection;
 
-        setTitle(collection.getDisplayName());
+        if (collection != null)
+            setTitle(collection.getDisplayName());
 
-        if (!suppress) {
+        if (!suppress)
             fireCollectionChangeEvent(tmp, this.collection);
-        }
     }
 
     @Override
@@ -488,7 +458,7 @@
      * @param name
      *            The name and title of the output.
      */
-    protected void addOutputTab(final String name, final OutputMode out) {
+    private void addOutputTab(final String name, final OutputMode out) {
         if (out instanceof ExportMode) {
             final ExportMode export = (ExportMode) out;
 
@@ -509,18 +479,17 @@
 
         GWT.log("Add new output tab for '" + name + "'");
 
-        final String title = this.messages.getString(name);
+        final String title = CollectionView.messages.getString(name);
         final OutputTab tab = out.createOutputTab(title, getCollection(), this);
 
-        if (tab != null) {
+        if (tab != null)
             this.outputTabs.put(name, tab);
-        }
     }
 
     /**
      * Removes all output mode tabs from tab bar.
      */
-    protected void clearOutputTabs() {
+    private void clearOutputTabs() {
         GWT.log("Clear OutputTabs.");
 
         final int num = this.tabs.getNumTabs();
@@ -535,7 +504,7 @@
     /**
      * Update the view (refresh the list of old and current data).
      */
-    protected void updateView() {
+    private void updateView() {
         GWT.log("CollectionView.updateView()");
         updateOutputTabs();
     }
@@ -543,7 +512,7 @@
     /**
      * This method is used to update the tabs to show specific output modes.
      */
-    protected void updateOutputTabs() {
+    private void updateOutputTabs() {
         GWT.log("Update output tabs.");
         if (this.outputTabs != null) {
             final Set<String> keys = this.outputTabs.keySet();
@@ -569,14 +538,12 @@
     }
 
     public void addArtifactToCollection(final Artifact artifact) {
-        final Config config = Config.getInstance();
-        final String locale = config.getLocale();
-        final Collection collection = getCollection();
+        final String locale = Config.getInstance().getLocale();
 
-        GWT.log("CollectionView.addArtifactToCollection " + collection);
+        GWT.log("CollectionView.addArtifactToCollection " + this.collection);
 
-        if (collection != null) {
-            this.addArtifactService.add(collection, artifact, locale, new AsyncCallback<Collection>() {
+        if (this.collection != null) {
+            this.addArtifactService.add(this.collection, artifact, locale, new AsyncCallback<Collection>() {
                 @Override
                 public void onFailure(final Throwable caught) {
                     GWT.log("An error occured while adding artifact.");
@@ -596,7 +563,7 @@
                 @Override
                 public void onFailure(final Throwable caught) {
                     GWT.log("Could not create the new collection.");
-                    SC.warn(FLYS.getExceptionString(CollectionView.this.messages, caught));
+                    SC.warn(FLYS.getExceptionString(CollectionView.messages, caught));
                 }
 
                 @Override
@@ -620,18 +587,16 @@
         }
     }
 
-    protected void addRecommendationsToCollection() {
-        final Config config = Config.getInstance();
-        final String locale = config.getLocale();
-        final Collection collection = getCollection();
+    private void addRecommendationsToCollection() {
+        final String locale = Config.getInstance().getLocale();
 
-        collection.addRecommendations(this.newRecommendations);
+        this.collection.addRecommendations(this.newRecommendations);
 
-        this.updater.update(collection, locale, new AsyncCallback<Collection>() {
+        this.updater.update(this.collection, locale, new AsyncCallback<Collection>() {
             @Override
             public void onFailure(final Throwable caught) {
                 CollectionView.this.newRecommendations.removeAllElements();
-                setCollection(collection);
+                setCollection(CollectionView.this.collection);
 
                 GWT.log("An error occured while saving recommendations.");
                 SC.warn(FLYS.getExceptionString(CollectionView.this.messages, caught));
@@ -646,10 +611,8 @@
         });
     }
 
-    protected void loadRecommendedArtifacts(final Recommendation[] recommendations) {
-        final Config config = Config.getInstance();
-        final String locale = config.getLocale();
-        final Collection collection = getCollection();
+    private void loadRecommendedArtifacts(final Recommendation[] recommendations) {
+        final String locale = Config.getInstance().getLocale();
 
         final Artifact masterArtifact = getArtifact();
 
@@ -659,7 +622,7 @@
         }
 
         for (final Recommendation recommendation : recommendations) {
-            if (collection.loadedRecommendation(recommendation)) {
+            if (this.collection.loadedRecommendation(recommendation)) {
                 continue;
             }
             this.newRecommendations.push(recommendation);
@@ -672,11 +635,11 @@
 
         }
 
-        this.loadArtifactService.loadMany(collection, recommendations, null, locale, new AsyncCallback<Artifact[]>() {
+        this.loadArtifactService.loadMany(this.collection, recommendations, null, locale, new AsyncCallback<Artifact[]>() {
             @Override
             public void onFailure(final Throwable caught) {
                 GWT.log("Error loading recommendations: " + caught.getMessage());
-                SC.warn(FLYS.getExceptionString(CollectionView.this.messages, caught));
+                SC.warn(FLYS.getExceptionString(CollectionView.messages, caught));
             }
 
             @Override
@@ -698,29 +661,4 @@
     public double getCurrentKm() {
         return this.currentKm;
     }
-
-    public void setMinKm(final double km) {
-        this.minKm = km;
-    }
-
-    public double getMinKm() {
-        return this.minKm;
-    }
-
-    public void setMaxKm(final double km) {
-        this.maxKm = km;
-    }
-
-    public double getMaxKm() {
-        return this.maxKm;
-    }
-
-    public void setSteps(final double step) {
-        this.steps = step;
-    }
-
-    public double getSteps() {
-        return this.steps;
-    }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org