changeset 858:9f07f67f60a5

Subclassed ChartThemePanel, trigger redraws of Chart when interaction with "Action" widgets in ThemePanel occured (but will still crash). flys-client/trunk@2651 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 06 Sep 2011 11:09:13 +0000
parents fa8efe5b8aee
children 6b047887855b
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemePanel.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 flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java
diffstat 5 files changed, 236 insertions(+), 97 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Sep 06 10:58:32 2011 +0000
+++ b/flys-client/ChangeLog	Tue Sep 06 11:09:13 2011 +0000
@@ -1,3 +1,23 @@
+2011-09-06	Felix Wolfsteller	<felix.wolfsteller@intevation.de> 
+
+	Subclassed ChartThemePanel, trigger redraws of Chart when interaction with
+	"Action" widgets in ThemePanel occured (but will still crash).
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java:
+	  Extracted CrossSection-specific stuff to own subclass.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java:
+	  New, contains specific parts that were extracted from ChartThemePanel.
+	  After interaction via the "Actions" Widgets (currently only a spinner),
+	  request a chart redraw.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java:
+	  Depending on the outputmode, create a CrossSectionChartThemePanel, register
+	  as redrawRequestHandler.
+
+	* src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java:
+	  Implement HasRedrawRequestHandlers interface.
+
 2011-09-06	Felix Wolfsteller	<felix.wolfsteller@intevation.de> 
 
 	Added concept of a RedrawRequestHandler to allow e.g. ChartThemePanel to
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java	Tue Sep 06 10:58:32 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java	Tue Sep 06 11:09:13 2011 +0000
@@ -22,10 +22,12 @@
 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.HasRedrawRequestHandlers;
 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.event.RedrawRequestHandler;
 import de.intevation.flys.client.client.services.CollectionAttributeService;
 import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync;
 
@@ -34,14 +36,18 @@
 extends               Canvas
 implements            OnMoveHandler,
                       EditCompleteHandler,
-                      HasOutputParameterChangeHandlers
+                      HasOutputParameterChangeHandlers,
+                      HasRedrawRequestHandlers
 {
     protected CollectionAttributeServiceAsync updater =
         GWT.create(CollectionAttributeService.class);
 
     private FLYSConstants MSG = GWT.create(FLYSConstants.class);
 
+    /** List of OutParameterChangedHandler. */
     protected List<OutputParameterChangeHandler> outHandlers;
+    /** List of ChartShallRedrawHandler. */
+    protected List<RedrawRequestHandler> redrawRequestHandlers;
 
     protected Collection collection;
     protected OutputMode mode;
@@ -57,9 +63,9 @@
     public ThemePanel(Collection collection, OutputMode mode) {
         this.collection  = collection;
         this.mode        = mode;
-
         this.list        = createGrid();
 
+        this.redrawRequestHandlers = new ArrayList<RedrawRequestHandler>();
         this.outHandlers = new ArrayList<OutputParameterChangeHandler>();
         this.navigation  = new ThemeNavigationPanel();
         this.navigation.addOnMoveHandler(this);
@@ -105,6 +111,28 @@
 
 
     /**
+     * Registers a RedrawRequestHandler.
+     *
+     * @param h The new handler.
+     */
+    public void addRedrawRequestHandler(RedrawRequestHandler h){
+        if (h != null) {
+            redrawRequestHandlers.add(h);
+        }
+    }
+
+
+    /**
+     * Request a redraw of e.g. a Chart.
+     */
+    protected void requestRedraw() {
+        for (RedrawRequestHandler handler: redrawRequestHandlers) {
+            handler.onRedrawRequest();
+        }
+    }
+
+
+    /**
      * Called when the attribution of an output changed. It informs the
      * registered handlers about the changes.
      */
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java	Tue Sep 06 10:58:32 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java	Tue Sep 06 11:09:13 2011 +0000
@@ -28,6 +28,7 @@
 import de.intevation.flys.client.client.event.OutputParameterChangeHandler;
 import de.intevation.flys.client.client.event.PanEvent;
 import de.intevation.flys.client.client.event.PanHandler;
+import de.intevation.flys.client.client.event.RedrawRequestHandler;
 import de.intevation.flys.client.client.event.ZoomEvent;
 import de.intevation.flys.client.client.event.ZoomHandler;
 import de.intevation.flys.client.client.services.ChartInfoService;
@@ -44,7 +45,8 @@
 implements   ResizedHandler,
              OutputParameterChangeHandler,
              ZoomHandler,
-             PanHandler
+             PanHandler,
+             RedrawRequestHandler
 {
     public static final int DEFAULT_CHART_WIDTH  = 600;
     public static final int DEFAULT_CHART_HEIGHT = 500;
@@ -92,7 +94,7 @@
      * @param title The title of this tab.
      * @param collection The Collection which this chart belongs to.
      * @param mode The OutputMode.
-     * @param collvetionView The shown collection.
+     * @param collectionView The shown collection.
      */
     public ChartOutputTab(
         String         title,
@@ -125,9 +127,17 @@
         hLayout.addMember(left);
         hLayout.addMember(right);
 
-        // TODO Spawn a specific ThemePanel subclass (e.g. "actions" column is
-        //      not needed in all cases.
-        ChartThemePanel ctp = new ChartThemePanel(collection, mode);
+        // Output "cross_section" needs slightly modified ThemePanel
+        // (with action buttons).
+        ChartThemePanel ctp = null;
+        if (mode.getName().equals("cross_section")) {
+            ctp = new CrossSectionChartThemePanel(collection, mode);
+        }
+        else {
+            ctp = new ChartThemePanel(collection, mode);
+        }
+
+        ctp.addChartShallRedrawHandler(this);
         ctp.addOutputParameterChangeHandler(this);
 
         chart = createChartImg();
@@ -158,6 +168,11 @@
     }
 
 
+    public void onRedrawRequest() {
+        resetRanges();
+    }
+
+
     /**
      * Listens to change event in the chart them panel and updates chart after
      * receiving such an event.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java	Tue Sep 06 10:58:32 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java	Tue Sep 06 11:09:13 2011 +0000
@@ -2,22 +2,10 @@
 
 import com.google.gwt.core.client.GWT;
 
-import com.smartgwt.client.types.Alignment; 
-import com.smartgwt.client.widgets.Canvas;
-import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.smartgwt.client.types.ListGridFieldType;
-import com.smartgwt.client.widgets.grid.ListGrid;
 import com.smartgwt.client.widgets.grid.ListGridField;
-import com.smartgwt.client.widgets.grid.ListGridRecord;
 import com.smartgwt.client.widgets.layout.VLayout;
-import com.smartgwt.client.widgets.layout.HLayout;
-import com.smartgwt.client.widgets.form.fields.SpinnerItem;
-import com.smartgwt.client.widgets.form.DynamicForm;
-import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
-import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
 
-import de.intevation.flys.client.client.Config;
-import de.intevation.flys.client.shared.model.Artifact;
 import de.intevation.flys.client.shared.model.Collection;
 import de.intevation.flys.client.shared.model.Theme;
 import de.intevation.flys.client.shared.model.OutputMode;
@@ -35,8 +23,7 @@
 public class ChartThemePanel extends ThemePanel {
 
     /** The interface that provides i18n messages. */
-    private FLYSConstants MSG = GWT.create(FLYSConstants.class);
-
+    protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
 
     public static final String GRID_FIELD_ACTIVE  = "active";
     public static final String GRID_FIELD_NAME    = "name";
@@ -56,75 +43,6 @@
 
 
     /**
-     * Create and configure the Grid to display.
-     */
-    protected ListGrid createGrid() {
-        ListGrid list = new ListGrid() {
-            @Override
-            protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum) {
-                    GWT.log("createRecordComponent! " + this.getFieldName(colNum));
-
-                    String fieldName = this.getFieldName(colNum);
-
-                    if (fieldName.equals("actions")) {
-                        GWT.log("GG UU II: Put actopms");
-                        HLayout recordCanvas = new HLayout(3);
-                        recordCanvas.setHeight(22);
-                        recordCanvas.setAlign(Alignment.CENTER);
-                        // Grid Cell Widgets example
-                        SpinnerItem spinnerItem = new SpinnerItem();
-                        spinnerItem.setShowTitle(false);
-                        spinnerItem.setTitle("Waterlevel-Spinner");
-                        spinnerItem.setWidth(50);
-                        spinnerItem.setDefaultValue(5);
-                        spinnerItem.setMin(130);
-                        spinnerItem.setMax(1000);
-                        spinnerItem.setStep(5f);
-                        Config config = Config.getInstance();
-                        final String serverUrl = config.getServerUrl();
-                        final String locale = config.getLocale();
-
-                        spinnerItem.addChangedHandler(new ChangedHandler() {
-                                @Override
-                                public void onChanged(ChangedEvent ce) {
-                                    // artifact instead of null
-                                    // data[] instead of null
-                                    feedService.feed(serverUrl, locale, null, null,
-                                        new AsyncCallback<Artifact>() {
-                                            public void onFailure(Throwable caught) {
-                                                GWT.log("Could not feed artifact");
-                                                // TODO SC.warn 
-                                            }
-                                            public void onSuccess(Artifact artifact) {
-                                                GWT.log("Successfully fed");
-                                                //TODO and now?
-                                            }
-                                        });
-                                }
-                            }
-                        );
-
-                        DynamicForm formWrap = new DynamicForm();
-                        formWrap.setFields(spinnerItem);
-                        formWrap.setTitlePrefix("");
-                        formWrap.setTitleSuffix("");
-                        recordCanvas.addMember(formWrap);
-                        return recordCanvas;
-                    }
-                    else {
-                        return null;
-                    }
-                }
-            };
-        list.setCanResizeFields(true);
-        list.setShowRecordComponents(true);
-        list.setShowRecordComponentsByCell(true);
-        list.setShowAllRecords(true);
-        return list;
-    }
-
-
-    /**
      * Initializes the layout of this panel.
      */
     protected void initLayout() {
@@ -148,7 +66,7 @@
     protected void initGrid() {
         list.setCanEdit(true);
         list.setCanSort(false);
-        //list.setShowRecordComponents(false);
+        list.setShowRecordComponents(false);
         list.setShowRecordComponentsByCell(true);
         list.setShowHeader(true);
         list.setShowHeaderContextMenu(false);
@@ -164,12 +82,7 @@
             GRID_FIELD_NAME, MSG.chart_themepanel_header_themes());
         name.setType(ListGridFieldType.TEXT);
 
-        // TODO Visibility of this Field (~"column") shall depend on
-        // availability of facets allowing for actions.
-        ListGridField actions = new ListGridField(GRID_FIELD_ACTIONS,
-                GRID_FIELD_ACTIONS, 60);
-
-        list.setFields(active, name, actions);
+        list.setFields(active, name);
     }
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java	Tue Sep 06 11:09:13 2011 +0000
@@ -0,0 +1,163 @@
+package de.intevation.flys.client.client.ui.chart;
+
+import com.google.gwt.core.client.GWT;
+
+import com.smartgwt.client.types.Alignment; 
+import com.smartgwt.client.widgets.Canvas;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.types.ListGridFieldType;
+import com.smartgwt.client.widgets.grid.ListGrid;
+import com.smartgwt.client.widgets.grid.ListGridField;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+import com.smartgwt.client.widgets.layout.HLayout;
+import com.smartgwt.client.widgets.form.fields.SpinnerItem;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
+import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
+
+import de.intevation.flys.client.client.Config;
+import de.intevation.flys.client.shared.model.Artifact;
+import de.intevation.flys.client.shared.model.Collection;
+import de.intevation.flys.client.shared.model.OutputMode;
+
+import de.intevation.flys.client.shared.model.Data;
+import de.intevation.flys.client.shared.model.DataItem;
+import de.intevation.flys.client.shared.model.DefaultArtifact;
+import de.intevation.flys.client.shared.model.DefaultData;
+import de.intevation.flys.client.shared.model.DefaultDataItem;
+import de.intevation.flys.client.shared.model.FacetRecord;
+
+
+
+/**
+ * ThemePanel much like ChartThemePanel, but shows an "Actions" column,
+ * needed for interaction in the CrossSection Charts.
+ */
+public class CrossSectionChartThemePanel
+extends      ChartThemePanel {
+
+    /**
+     * Trivial constructor.
+     */
+    public CrossSectionChartThemePanel(
+            Collection collection,
+            OutputMode mode)
+    {
+        super(collection, mode);
+    }
+
+
+    /**
+     * Create and configure the Grid to display.
+     */
+    @Override
+    protected ListGrid createGrid() {
+        ListGrid list = new ListGrid() {
+            @Override
+            protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum) {
+
+                    String fieldName = this.getFieldName(colNum);
+
+                    if (fieldName.equals("actions")) {
+                        GWT.log("Gui: Put Actions");
+                        HLayout recordCanvas = new HLayout(3);
+                        recordCanvas.setHeight(22);
+                        recordCanvas.setAlign(Alignment.CENTER);
+                        // TODO decide on per case basis if to put an action
+                        // widget or not.
+                        // TODO Refactor in createSpinner(data, artifact)
+                        SpinnerItem spinnerItem = new SpinnerItem();
+                        spinnerItem.setShowTitle(false);
+                        spinnerItem.setTitle("Waterlevel-Spinner");
+                        spinnerItem.setWidth(50);
+                        // TODO actually get the value from artifact
+                        // TODO actually get the range from artifact (or river?)
+                        spinnerItem.setDefaultValue(0);
+                        spinnerItem.setMin(0);
+                        spinnerItem.setMax(1000);
+                        spinnerItem.setStep(5f);
+
+                        Config config = Config.getInstance();
+                        final String serverUrl = config.getServerUrl();
+                        final String locale    = config.getLocale();
+
+                        spinnerItem.addChangedHandler(new ChangedHandler() {
+                                @Override
+                                public void onChanged(ChangedEvent ce) {
+                                    FacetRecord facetRecord = (FacetRecord) record;
+                                    DefaultDataItem kmItem = new DefaultDataItem("cross_section.km",
+                                        "cross_section.km", ce.getValue().toString());
+                                    DefaultData km = new DefaultData("cross_section.km",
+                                        null, null, new DataItem[] {kmItem});
+                                    Data[] feedData = new Data[] {km};
+                                    feedService.feed(serverUrl,
+                                        locale,
+                                        new DefaultArtifact(facetRecord.getTheme().getArtifact(), "TODO:hash"),
+                                        feedData,
+                                        new AsyncCallback<Artifact>() {
+                                            public void onFailure(Throwable caught) {
+                                                GWT.log("Could not feed artifact " + caught.getMessage());
+                                                // TODO SC.warn 
+                                            }
+                                            public void onSuccess(Artifact artifact) {
+                                                GWT.log("Successfully fed");
+                                                //TODO and now?
+                                                // fireOutputParameterChanged();
+                                                // Also update content of spinnerbox
+                                                requestRedraw();
+                                            }
+                                        });
+                                }
+                            }
+                        );
+
+                        DynamicForm formWrap = new DynamicForm();
+                        formWrap.setFields(spinnerItem);
+                        formWrap.setTitlePrefix("");
+                        formWrap.setTitleSuffix("");
+                        recordCanvas.addMember(formWrap);
+                        return recordCanvas;
+                    }
+                    else {
+                        return null;
+                    }
+                }
+            };
+        list.setCanResizeFields(true);
+        list.setShowRecordComponents(true);
+        list.setShowRecordComponentsByCell(true);
+        list.setShowAllRecords(true);
+        return list;
+    }
+
+
+    /**
+     * Initializes the components (columns) of the theme grid.
+     */
+    @Override
+    protected void initGrid() {
+        list.setCanEdit(true);
+        list.setCanSort(false);
+        list.setShowRecordComponents(true);
+        list.setShowRecordComponentsByCell(true);
+        list.setShowHeader(true);
+        //list.setShowHeaderContextMenu(false);
+        list.setWidth100();
+        list.setHeight100();
+
+        list.addEditCompleteHandler(this);
+
+        ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20);
+        active.setType(ListGridFieldType.BOOLEAN);
+
+        ListGridField name = new ListGridField(
+            GRID_FIELD_NAME, MSG.chart_themepanel_header_themes());
+        name.setType(ListGridFieldType.TEXT);
+
+        ListGridField actions = new ListGridField(GRID_FIELD_ACTIONS,
+                GRID_FIELD_ACTIONS, 60);
+
+        list.setFields(active, name, actions);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org