changeset 531:c17c593f8732

The chart in the ChartOutputTab is refreshed when there occur any changes in the chart theme panel. flys-client/trunk@2020 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 27 May 2011 09:50:57 +0000
parents 26e38b79658d
children 0ba7c43e7b62
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/event/HasOutputParameterChangeHandlers.java flys-client/src/main/java/de/intevation/flys/client/client/event/OutputParameterChangeEvent.java flys-client/src/main/java/de/intevation/flys/client/client/event/OutputParameterChangeHandler.java flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java
diffstat 6 files changed, 143 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri May 27 08:59:26 2011 +0000
+++ b/flys-client/ChangeLog	Fri May 27 09:50:57 2011 +0000
@@ -1,3 +1,23 @@
+2011-05-27  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/event/HasOutputParameterChangeHandlers.java,
+	  src/main/java/de/intevation/flys/client/client/event/OutputParameterChangeHandler.java,
+	  src/main/java/de/intevation/flys/client/client/event/OutputParameterChangeEvent.java:
+	  Interface and class to realize a listener mechanism for output parameter
+	  changes.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java:
+	  Implements the OutputParameterChangeHandler interface. After the output
+	  parameter of the chart have changed, the chart is refreshed.
+
+	  NOTE: The panel is disabled right before the RPC call to replace the
+	  collection's attribute is executed. It is enabled after the RPC call has
+	  finished.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java:
+	  Implements the HasOutputParameterChangeHanders interface. The event is
+	  fired if there are changes in the chart theme control panel.
+
 2011-05-27  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/server/CollectionAttributeServiceImpl.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/event/HasOutputParameterChangeHandlers.java	Fri May 27 09:50:57 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 HasOutputParameterChangeHandlers {
+
+    /**
+     * Registers a new OutputParameterChangeHandler.
+     *
+     * @param handler The new handler.
+     */
+    void addOutputParameterChangeHandler(OutputParameterChangeHandler 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/OutputParameterChangeEvent.java	Fri May 27 09:50:57 2011 +0000
@@ -0,0 +1,12 @@
+package de.intevation.flys.client.client.event;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class OutputParameterChangeEvent {
+
+    public OutputParameterChangeEvent() {
+    }
+}
+// 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/OutputParameterChangeHandler.java	Fri May 27 09:50:57 2011 +0000
@@ -0,0 +1,17 @@
+package de.intevation.flys.client.client.event;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface OutputParameterChangeHandler {
+
+    /**
+     * Called when the parameter of an output have changed. E.g. when the state
+     * of themes in a theme panel changed.
+     *
+     * @param event The event that is fired.
+     */
+    void onOutputParameterChanged(OutputParameterChangeEvent 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/chart/ChartOutputTab.java	Fri May 27 08:59:26 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java	Fri May 27 09:50:57 2011 +0000
@@ -24,6 +24,8 @@
 import de.intevation.flys.client.shared.model.Collection;
 import de.intevation.flys.client.shared.model.OutputMode;
 import de.intevation.flys.client.client.Config;
+import de.intevation.flys.client.client.event.OutputParameterChangeEvent;
+import de.intevation.flys.client.client.event.OutputParameterChangeHandler;
 import de.intevation.flys.client.client.ui.CollectionView;
 import de.intevation.flys.client.client.ui.DatacageWindow;
 import de.intevation.flys.client.client.ui.OutputTab;
@@ -32,8 +34,10 @@
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public class ChartOutputTab extends OutputTab implements ResizedHandler {
-
+public class ChartOutputTab
+extends      OutputTab
+implements   ResizedHandler, OutputParameterChangeHandler
+{
     public static final int DEFAULT_CHART_WIDTH  = 600;
     public static final int DEFAULT_CHART_HEIGHT = 500;
 
@@ -87,8 +91,11 @@
         hLayout.addMember(left);
         hLayout.addMember(right);
 
+        ChartThemePanel ctp = new ChartThemePanel(collection, mode);
+        ctp.addOutputParameterChangeHandler(this);
+
         right.addChild(createChartPanel());
-        left.addChild(new ChartThemePanel(collection, mode));
+        left.addChild(ctp);
         tbarPanel.addChild(
             createTBarPanel(collectionView));
 
@@ -108,6 +115,22 @@
      * @param event The resize event.
      */
     public void onResized(ResizedEvent event) {
+        updateChartPanel();
+    }
+
+
+    /**
+     * Listens to change event in the chart them panel and updates chart after
+     * receiving such an event.
+     *
+     * @param event The OutputParameterChangeEvent.
+     */
+    public void onOutputParameterChanged(OutputParameterChangeEvent event) {
+        updateChartPanel();
+    }
+
+
+    public void updateChartPanel() {
         Canvas[] children = right.getChildren();
         for (Canvas child: children) {
             right.removeChild(child);
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java	Fri May 27 08:59:26 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java	Fri May 27 09:50:57 2011 +0000
@@ -1,5 +1,8 @@
 package de.intevation.flys.client.client.ui.chart;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
@@ -21,8 +24,11 @@
 
 import de.intevation.flys.client.client.Config;
 import de.intevation.flys.client.client.FLYSConstants;
+import de.intevation.flys.client.client.event.HasOutputParameterChangeHandlers;
 import de.intevation.flys.client.client.event.OnMoveEvent;
 import de.intevation.flys.client.client.event.OnMoveHandler;
+import de.intevation.flys.client.client.event.OutputParameterChangeEvent;
+import de.intevation.flys.client.client.event.OutputParameterChangeHandler;
 import de.intevation.flys.client.client.services.CollectionAttributeService;
 import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync;
 
@@ -32,7 +38,8 @@
  */
 public class ChartThemePanel
 extends      Canvas
-implements   EditCompleteHandler, OnMoveHandler
+implements   EditCompleteHandler, OnMoveHandler,
+             HasOutputParameterChangeHandlers
 {
     /** The interface that provides i18n messages. */
     private FLYSConstants MSG = GWT.create(FLYSConstants.class);
@@ -51,17 +58,23 @@
 
     protected OutputMode mode;
 
+    protected List<OutputParameterChangeHandler> outHandlers;
+
     protected ListGrid list;
 
+    protected ChartOutputTab chartOut;
+
     protected ThemeNavigationPanel navigation;
 
 
 
     public ChartThemePanel(Collection collection, OutputMode mode) {
-        this.collection = collection;
-        this.mode       = mode;
-        this.list       = new ListGrid();
-        this.navigation = new ThemeNavigationPanel();
+        this.collection  = collection;
+        this.mode        = mode;
+        this.outHandlers = new ArrayList<OutputParameterChangeHandler>();
+        this.chartOut    = chartOut;
+        this.list        = new ListGrid();
+        this.navigation  = new ThemeNavigationPanel();
         this.navigation.addOnMoveHandler(this);
 
         initGrid();
@@ -129,6 +142,18 @@
 
 
     /**
+     * Registers a new OutputParameterChangeHandler.
+     *
+     * @param h The new handler.
+     */
+    public void addOutputParameterChangeHandler(OutputParameterChangeHandler h){
+        if (h != null) {
+            outHandlers.add(h);
+        }
+    }
+
+
+    /**
      * Returns the ThemeList of the current collection and output mode.
      *
      * @return the current ThemeList.
@@ -181,6 +206,21 @@
 
             list.addData(new FacetRecord(theme));
         }
+
+        fireOutputParameterChanged();
+    }
+
+
+    /**
+     * Called when the attribution of a chart changed. It informs the registered
+     * handlers about the changes.
+     */
+    protected void fireOutputParameterChanged() {
+        OutputParameterChangeEvent evt = new OutputParameterChangeEvent();
+
+        for (OutputParameterChangeHandler handler: outHandlers) {
+            handler.onOutputParameterChanged(evt);
+        }
     }
 
 
@@ -253,15 +293,22 @@
 
         GWT.log("ChartThemePanel.updateCollection via RPC now");
 
+        // don't forget to enable the panel after the request has finished!
+        disable();
+
         updater.update(collection, url, loc, new AsyncCallback<Collection>() {
             public void onFailure(Throwable caught) {
                 GWT.log("Could not update collection attributes.");
                 SC.warn(MSG.getString(caught.getMessage()));
+
+                enable();
             }
 
 
             public void onSuccess(Collection collection) {
                 setCollection(collection);
+
+                enable();
             }
         });
     }

http://dive4elements.wald.intevation.org