changeset 513:e090fbd5a535

Added a mechanism to listen to changes relating to output modes of collections and artifacts. Solves a part of ISSUE-62. flys-client/trunk@1979 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 23 May 2011 14:30:54 +0000
parents e35de49f942f
children b9127f876a6a
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/event/HasOutputModesChangeHandlers.java flys-client/src/main/java/de/intevation/flys/client/client/event/OutputModesChangeEvent.java flys-client/src/main/java/de/intevation/flys/client/client/event/OutputModesChangeHandler.java flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java
diffstat 6 files changed, 171 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri May 20 10:15:10 2011 +0000
+++ b/flys-client/ChangeLog	Mon May 23 14:30:54 2011 +0000
@@ -1,3 +1,23 @@
+2011-05-23  Ingo Weinzierl <ingo@intevation.de>
+
+	  ISSUE-62 (part I/II)
+
+	* src/main/java/de/intevation/flys/client/client/event/OutputModesChangeEvent.java,
+	  src/main/java/de/intevation/flys/client/client/event/HasOutputModesChangeHandlers.java,
+	  src/main/java/de/intevation/flys/client/client/event/OutputModesChangeHandler.java:
+	  Classes and interfaces that are necessary to build up a listener
+	  mechanism for output mode changes.
+
+	* src/main/java/de/intevation/flys/client/client/ui/CollectionView.java::
+	  Implements the HasOutputModesChangeHandlers and OutputModesChangeHandler
+	  interfaces.
+
+	* src/main/java/de/intevation/flys/client/client/ui/ParameterList.java:
+	  Implements the OutputModesChangeHandler interface which enables us to
+	  update the export panel even after the outs of an artifact have changed.
+
+
+
 2011-05-20  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/config.xml:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/event/HasOutputModesChangeHandlers.java	Mon May 23 14:30:54 2011 +0000
@@ -0,0 +1,16 @@
+package de.intevation.flys.client.client.event;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface HasOutputModesChangeHandlers {
+
+    /**
+     * Adds a new OutputModesChangeHandler.
+     *
+     * @param handler The new OutputModesChangeHandler.
+     */
+    public void addOutputModesChangeHandler(OutputModesChangeHandler handler);
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/event/OutputModesChangeEvent.java	Mon May 23 14:30:54 2011 +0000
@@ -0,0 +1,26 @@
+package de.intevation.flys.client.client.event;
+
+import de.intevation.flys.client.shared.model.OutputMode;
+
+
+/**
+ * An event that is thrown if the output modes of a collection or an artifact
+ * have changed.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class OutputModesChangeEvent {
+
+    protected OutputMode[] outs;
+
+
+    public OutputModesChangeEvent(OutputMode[] outs) {
+        this.outs = outs;
+    }
+
+
+    public OutputMode[] getOutputModes() {
+        return outs;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/event/OutputModesChangeHandler.java	Mon May 23 14:30:54 2011 +0000
@@ -0,0 +1,18 @@
+package de.intevation.flys.client.client.event;
+
+
+/**
+ * Handler interface for OutputModesChangeEvent events.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface OutputModesChangeHandler {
+
+    /**
+     * Called when a OutputModesChangeEvent is fired.
+     *
+     * @param event The OutputModesChangeEvent.
+     */
+    public void onOutputModesChange(OutputModesChangeEvent event);
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java	Fri May 20 10:15:10 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java	Mon May 23 14:30:54 2011 +0000
@@ -26,8 +26,11 @@
 import de.intevation.flys.client.client.FLYS;
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.client.event.HasCollectionChangeHandlers;
+import de.intevation.flys.client.client.event.HasOutputModesChangeHandlers;
 import de.intevation.flys.client.client.event.CollectionChangeEvent;
 import de.intevation.flys.client.client.event.CollectionChangeHandler;
+import de.intevation.flys.client.client.event.OutputModesChangeEvent;
+import de.intevation.flys.client.client.event.OutputModesChangeHandler;
 import de.intevation.flys.client.client.event.ParameterChangeEvent;
 import de.intevation.flys.client.client.event.ParameterChangeHandler;
 import de.intevation.flys.client.client.services.AddArtifactService;
@@ -44,6 +47,7 @@
 public class CollectionView
 extends      Window
 implements   CollectionChangeHandler, HasCollectionChangeHandlers,
+             OutputModesChangeHandler, HasOutputModesChangeHandlers,
              ParameterChangeHandler
 {
     /** The ArtifactService used to communicate with the Artifact server. */
@@ -70,6 +74,9 @@
     /** The list of ValueChangeHandlers.*/
     protected List<CollectionChangeHandler> handlers;
 
+    /** The list of ValueChangeHandlers.*/
+    protected List<OutputModesChangeHandler> outHandlers;
+
     /** The collection to be displayed.*/
     protected Collection collection;
 
@@ -96,12 +103,15 @@
         this.tabs          = new TabSet();
         this.outputTabs    = new HashMap<String, OutputTab>();
         this.handlers      = new ArrayList<CollectionChangeHandler>();
+        this.outHandlers   = new ArrayList<OutputModesChangeHandler>();
         this.layout        = new VLayout();
         this.parameterList = new ParameterList(
             flys, this, messages.new_project());
 
         addCollectionChangeHandler(this);
         addCollectionChangeHandler(parameterList);
+        addOutputModesChangeHandler(this);
+        addOutputModesChangeHandler(parameterList);
 
         parameterList.addParameterChangeHandler(this);
 
@@ -114,6 +124,7 @@
         this.tabs          = new TabSet();
         this.outputTabs    = new HashMap<String, OutputTab>();
         this.handlers      = new ArrayList<CollectionChangeHandler>();
+        this.outHandlers   = new ArrayList<OutputModesChangeHandler>();
         this.layout        = new VLayout();
         this.parameterList = new ParameterList(
             flys,
@@ -123,6 +134,8 @@
 
         addCollectionChangeHandler(this);
         addCollectionChangeHandler(parameterList);
+        addOutputModesChangeHandler(this);
+        addOutputModesChangeHandler(parameterList);
 
         parameterList.addParameterChangeHandler(this);
 
@@ -218,6 +231,18 @@
     }
 
 
+    /**
+     * This method registers a new OutputModesChangeHandler.
+     *
+     * @param handler The new OutputModesChangeHandler.
+     */
+    public void addOutputModesChangeHandler(OutputModesChangeHandler handler) {
+        if (handler != null) {
+            outHandlers.add(handler);
+        }
+    }
+
+
 
     /**
      * This method calls the <code>onValueChange()</code> method of all
@@ -232,6 +257,17 @@
     }
 
 
+    protected void fireOutputModesChangeEvent(OutputMode[] outputs) {
+        if (collection == null) {
+            return;
+        }
+
+        for (OutputModesChangeHandler handler: outHandlers) {
+            handler.onOutputModesChange(new OutputModesChangeEvent(outputs));
+        }
+    }
+
+
     /**
      * This method returns true, if the Collection is new and no plugins has
      * been chosen.
@@ -276,6 +312,8 @@
         ArtifactDescription desc = art.getArtifactDescription();
         OutputMode[] outs        = desc.getOutputModes();
 
+        fireOutputModesChangeEvent(outs);
+
         setArtifact(art);
         clearOutputTabs();
 
@@ -342,15 +380,33 @@
 
         Map<String, OutputMode> outs = newCol.getOutputModes();
 
-        Set<String> keys = outs.keySet();
+        Set<String>  keys     = outs.keySet();
+        OutputMode[] prepared = new OutputMode[outs.size()];
+
+        int idx = 0;
         for (String outname: keys) {
-            addOutputTab(outname, outs.get(outname));
+            prepared[idx++] = outs.get(outname);
         }
 
+        fireOutputModesChangeEvent(prepared);
+
         updateView();
     }
 
 
+    public void onOutputModesChange(OutputModesChangeEvent event) {
+        OutputMode[] outs = event.getOutputModes();
+
+        if (outs == null) {
+            return;
+        }
+
+        for (OutputMode out: outs) {
+            addOutputTab(out.getName(), out);
+        }
+    }
+
+
     /**
      * Adds a new tab for the OutputMode <i>out</i>.
      *
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java	Fri May 20 10:15:10 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java	Mon May 23 14:30:54 2011 +0000
@@ -34,6 +34,8 @@
 import de.intevation.flys.client.client.event.HasParameterChangeHandler;
 import de.intevation.flys.client.client.event.HasStepBackHandlers;
 import de.intevation.flys.client.client.event.HasStepForwardHandlers;
+import de.intevation.flys.client.client.event.OutputModesChangeEvent;
+import de.intevation.flys.client.client.event.OutputModesChangeHandler;
 import de.intevation.flys.client.client.event.ParameterChangeEvent;
 import de.intevation.flys.client.client.event.ParameterChangeHandler;
 import de.intevation.flys.client.client.event.StepBackEvent;
@@ -51,7 +53,8 @@
 public class ParameterList
 extends      Tab
 implements   StepBackHandler, StepForwardHandler, ParameterChangeHandler,
-             HasParameterChangeHandler, CollectionChangeHandler
+             HasParameterChangeHandler, CollectionChangeHandler,
+             OutputModesChangeHandler
 {
     /** The message class that provides i18n strings.*/
     protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
@@ -491,22 +494,46 @@
 
 
     public void onCollectionChange(CollectionChangeEvent event) {
-        Collection c = event.getNewValue();
-
+        Collection                 c = event.getNewValue();
         Map<String, OutputMode> outs = c.getOutputModes();
         Set<String>             keys = outs.keySet();
 
+        OutputMode[] outputs = new OutputMode[outs.size()];
+
+        int idx = 0;
+        for (String outname: keys) {
+            outputs[idx++] = outs.get(outname);
+        }
+
+        updateExportModes(c, getExportModes(outputs));
+    }
+
+
+    public void onOutputModesChange(OutputModesChangeEvent event) {
+        List<ExportMode> exports = getExportModes(event.getOutputModes());
+
+        Collection c = cView.getCollection();
+
+        if (c != null) {
+            updateExportModes(c, exports);
+        }
+    }
+
+
+    protected List<ExportMode> getExportModes(OutputMode[] outs) {
         List<ExportMode> exports = new ArrayList<ExportMode>();
 
-        for (String outname: keys) {
-            OutputMode out = outs.get(outname);
+        if (outs == null || outs.length == 0) {
+            return exports;
+        }
 
+        for (OutputMode out: outs) {
             if (out instanceof ExportMode) {
                 exports.add((ExportMode) out);
             }
         }
 
-        updateExportModes(c, exports);
+        return exports;
     }
 
 

http://dive4elements.wald.intevation.org