changeset 1379:546f7f890ffa

Cosmetics, refactoring. flys-client/trunk@3130 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 01 Nov 2011 14:29:27 +0000
parents ebba8a8618e6
children 2d617c48ca5f
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/CrossSectionChartThemePanel.java
diffstat 3 files changed, 80 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Nov 01 12:08:09 2011 +0000
+++ b/flys-client/ChangeLog	Tue Nov 01 14:29:27 2011 +0000
@@ -1,3 +1,14 @@
+2011-11-01	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Cosmetics, Refactoring.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java
+	  (createSpinnerHandler): Extracetd, to improve readability.
+
+	* src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java
+	  (requestRedraw): Made final to be accessible from extracted handler
+	   construction in CrossSectionChartThemePanel.
+
 2011-11-01	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	Fix flys/issue306 (CrossSections: Remove functionality from table
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java	Tue Nov 01 12:08:09 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java	Tue Nov 01 14:29:27 2011 +0000
@@ -167,7 +167,7 @@
     /**
      * Request a redraw of e.g. a Chart.
      */
-    public void requestRedraw() {
+    final public void requestRedraw() {
         for (RedrawRequestHandler handler: redrawRequestHandlers) {
             handler.onRedrawRequest(new RedrawRequestEvent(Type.RESET));
         }
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java	Tue Nov 01 12:08:09 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java	Tue Nov 01 14:29:27 2011 +0000
@@ -27,6 +27,8 @@
 import de.intevation.flys.client.shared.model.DefaultDataItem;
 import de.intevation.flys.client.shared.model.FacetRecord;
 
+import de.intevation.flys.client.client.services.FeedServiceAsync;
+
 
 /**
  * ThemePanel much like ChartThemePanel, but shows an "Actions" column,
@@ -47,17 +49,77 @@
 
 
     /**
+     * Create the handler for ChangeEvents on the Spinner in the
+     * facets that control km of cross section.
+     *
+     * @param feedService The FeedService to send (changed) data to.
+     * @param facetRecord The FacetRecord (~row in table) where this
+     *                    handler is added to (to a child, to be exact).
+     */
+    public final ChangedHandler createSpinnerHandler(
+        final FeedServiceAsync feedService,
+        final FacetRecord      facetRecord)
+    {
+        Config config          = Config.getInstance();
+        final String serverUrl = config.getServerUrl();
+        final String locale    = config.getLocale();
+
+        ChangedHandler handler = new ChangedHandler()
+            {
+                @Override
+                public void onChanged(ChangedEvent ce) {
+                    if (ce.getValue() == null) {
+                        return;
+                    }
+                    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: Also update content of spinnerbox
+                                requestRedraw();
+                            }
+                    });
+                }
+            };
+        return handler;
+    }
+
+
+    /**
      * Create and configure the Grid to display.
      */
     @Override
     protected ListGrid createGrid() {
         ListGrid list = new ListGrid() {
             @Override
-            protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum) {
+            protected Canvas createRecordComponent(
+                final ListGridRecord record,
+                Integer colNum)
+            {
                     // Only cross_section Facets display an action widget.
                     final FacetRecord facetRecord = (FacetRecord) record;
                     if (!facetRecord.getTheme().getFacet().equals(
-                                "cross_section")) {
+                        "cross_section"))
+                    {
                         return null;
                     }
 
@@ -80,41 +142,10 @@
                         spinnerItem.setStep(5f);
                         spinnerItem.setChangeOnKeypress(true);
 
-                        Config config = Config.getInstance();
-                        final String serverUrl = config.getServerUrl();
-                        final String locale    = config.getLocale();
-
-                        spinnerItem.addChangedHandler(new ChangedHandler() {
-                                @Override
-                                public void onChanged(ChangedEvent ce) {
-                                    if (ce.getValue() == null) {
-                                        return;
-                                    }
-                                    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();
-                                            }
-                                        });
-                                }
-                            }
-                        );
+                        spinnerItem.addChangedHandler(
+                            createSpinnerHandler(
+                                feedService,
+                                facetRecord));
 
                         DynamicForm formWrap = new DynamicForm();
                         formWrap.setFields(spinnerItem);

http://dive4elements.wald.intevation.org