changeset 1457:3d9f81c3f00d

Refactored to use existing code. flys-client/trunk@3487 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 20 Dec 2011 11:14:47 +0000
parents 1c2cd46d526d
children 61521bc0ced3
files flys-client/ChangeLog 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 3 files changed, 41 insertions(+), 240 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Dec 20 10:54:55 2011 +0000
+++ b/flys-client/ChangeLog	Tue Dec 20 11:14:47 2011 +0000
@@ -1,3 +1,9 @@
+2011-12-20	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java,
+	  src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java:
+	  Minor refactoring to reuse existing code.
+
 2011-12-20	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java	Tue Dec 20 10:54:55 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java	Tue Dec 20 11:14:47 2011 +0000
@@ -130,6 +130,12 @@
     }
 
 
+    /** Returns name of longitudinal section area facets. */
+    protected String getAreaFacetName() {
+        return "longitudinal_section.area";
+    }
+
+
     /**
      * Tell an area artifact where to get the upper and lower curve from.
      * @param over if null, something
@@ -147,7 +153,7 @@
                 DefaultData.createSimpleStringData("area.name",
                     over.getDescription() + " / " + under.getDescription()),
                 DefaultData.createSimpleStringData("area.facet",
-                    "longitudinal_section.area")
+                    getAreaFacetName())
             };
             GWT.log("Have over and under");
         }
@@ -158,7 +164,7 @@
                 DefaultData.createSimpleStringData("area.name",
                     under.getDescription() + " / " + MSG.getString("x_axis")),
                 DefaultData.createSimpleStringData("area.facet",
-                    "longitudinal_section.area")
+                    getAreaFacetName())
             };
             GWT.log("Have under only");
         }
@@ -169,7 +175,7 @@
                 DefaultData.createSimpleStringData("area.name",
                     MSG.getString("x_axis") + " / " + over.getDescription()),
                 DefaultData.createSimpleStringData("area.facet",
-                    "longitudinal_section.area")
+                    getAreaFacetName())
             };
             GWT.log("Have over only");
         }
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java	Tue Dec 20 10:54:55 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java	Tue Dec 20 11:14:47 2011 +0000
@@ -54,8 +54,9 @@
 
 /**
  * ThemePanel much like ChartThemePanel, but shows an "Actions" column,
- * needed for interaction in the CrossSection Charts and a selctor to
+ * needed for interaction in the CrossSection Charts and a selector to
  * declare which cross section profile is "master".
+ * Also can show 'area creation' context menus.
  */
 public class CrossSectionChartThemePanel
 extends      ChartThemePanel {
@@ -113,78 +114,9 @@
     }
 
 
-    /**
-     * Tell an area artifact where to get the upper and lower curve from.
-     * @param over if null, something
-     */
-    public void feedTellArea(final String artifact, Theme under, Theme over) {
-
-        Data[] feedData;
-
-        if (over != null && under != null) {
-            feedData = new Data[] {
-                DefaultData.createSimpleStringData("area.curve_under",
-                    under.getArtifact() + under.getIndex()),
-                DefaultData.createSimpleStringData("area.curve_over",
-                    over.getArtifact() + over.getIndex()),
-                DefaultData.createSimpleStringData("area.name",
-                    over.getDescription() + " / " + under.getDescription()),
-                DefaultData.createSimpleStringData("area.facet",
-                    "cross_section.area")
-            };
-            GWT.log("Have over and under");
-        }
-        else if (over == null && under != null) {
-            feedData = new Data[] {
-                DefaultData.createSimpleStringData("area.curve_under",
-                    under.getArtifact() + under.getIndex()),
-                DefaultData.createSimpleStringData("area.name",
-                    under.getDescription() + " / " + MSG.getString("x_axis")),
-                DefaultData.createSimpleStringData("area.facet",
-                    "cross_section.area")
-            };
-            GWT.log("Have under only");
-        }
-        else if (over != null && under == null) {
-            feedData = new Data[] {
-                DefaultData.createSimpleStringData("area.curve_over",
-                    over.getArtifact() + over.getIndex()),
-                DefaultData.createSimpleStringData("area.name",
-                    MSG.getString("x_axis") + " / " + over.getDescription()),
-                DefaultData.createSimpleStringData("area.facet",
-                    "cross_section.area")
-            };
-            GWT.log("Have over only");
-        }
-        else {
-            GWT.log("Missing Data for area painting.");
-            return;
-        }
-
-
-        feedService.feed(
-            Config.getInstance().getLocale(),
-            new DefaultArtifact(artifact, "TODO:hash"),
-            feedData,
-            new AsyncCallback<Artifact>() {
-                public void onFailure(Throwable caught) {
-                    GWT.log("Could not feed artifact (" + artifact
-                            + ") with area info: " + caught.getMessage());
-                    SC.warn(MSG.getString(caught.getMessage()));
-                    enable();
-                }
-                public void onSuccess(Artifact artifact) {
-                    GWT.log("Successfully set area params to " + artifact);
-                    requestRedraw();
-                    updateCollection();
-                    updateGrid();
-                    enable();
-                }
-            });
-    }
 
     /**
-     * sets currentMasterUUID.
+     * Sets currentMasterUUID.
      */
     public String findCurrentMaster() {
         ThemeList themeList = getThemeList();
@@ -431,28 +363,6 @@
 
 
     /**
-     * Get the chosen km for given cross-section.
-     */
-    final public double getKmForCrossSectionIdx(final int index) {
-        double km   = 0d;
-        int collIdx = 0;
-        while (km == 0d) {
-            CollectionItem item = collection.getItem(collIdx++);
-            if (item == null) {
-                break;
-            }
-            if (item.getData() == null) continue;
-            String d = item.getData().get("cross_section" + index + ".km");
-            if (d == null) {
-                continue;
-            }
-            km = Double.valueOf(d);
-        }
-        return km;
-    }
-
-
-    /**
      * Create a "kilometer spinner" for CrossSection Facets.
      * @param facetRecord The respective Facet/Theme.
      * @return label, intialized SpinnerItem.
@@ -569,157 +479,36 @@
     }
 
 
-    /**
-     * Create and parameterize a new area artifact.
-     * @param under
-     * @param over if null, something.
-     */
-    public void createAreaArtifact(
-        final Theme under,
-        final Theme over,
-        boolean between
-    ) {
-        Config config = Config.getInstance();
-        String locale = config.getLocale();
-
-        Recommendation area = new Recommendation(
-            "area",
-            "",
-            "",
-            null);
-        Recommendation[] recommendations = new Recommendation[] {area};
+    /** Returns name of cross section area facets. */
+    protected String getAreaFacetName() {
+        return "cross_section.area";
+    }
 
-        loadService.loadMany(
-            this.collection,
-            recommendations,
-            null, //use individual factories.
-            locale,
-            new AsyncCallback<Artifact[]>() {
-                public void onFailure(Throwable caught) {
-                    GWT.log("Failed, no area artifact: " + caught.getMessage());
-                    enable();
-                    // TODO SC.warn
-                }
-                public void onSuccess(Artifact[] artifacts) {
-                    GWT.log("Success, created area artifact: "
-                        + artifacts[0].getUuid());
-                    // Now, feed the artifact with the relevant data.
-                    feedTellArea(artifacts[0].getUuid(), under, over);
-                }
-            }
-            );
-    }
 
     /**
-     * Include area specific menu items.
+     * Return true if two themes are canditates for an area being
+     * rendered between them.
+     * TODO join with canArea, generalize to allow easier modification
+     *      in subclasses.
      */
-    protected Menu getSingleContextMenu(final ListGridRecord[] records) {
-        Menu menu = super.getSingleContextMenu(records);
-
-        final Theme facetTheme = ((FacetRecord)records[0]).getTheme();
-        String thisItem = facetTheme.getDescription();
-        if (facetTheme.getFacet().equals("area") ||
-            facetTheme.getFacet().equals("cross_section.area")
-        ) {
-            return menu;
+    protected boolean areAreaCompatible(Theme a, Theme b) {
+        if (a.equals(b)) {
+            return false;
         }
-        
-        menu.addItem(createSeparator());
-
-        // TODO i18n
-        //MenuItem properties = new MenuItem(MSG.properties());
-        MenuItem areaMenuItem = new MenuItem("New Area...");
-        Menu areaMenu         = new Menu();
-
-        ThemeList themes = getThemeList();
-        int nThemes      = themes.getThemeCount();
-
-        MenuItem underMenuItem = new MenuItem("Under ...");
-        Menu underMenu = new Menu();
-        for (int i = 0; i < nThemes; i++)  {
-            final Theme theme = themes.getThemeAt(i+1);
-            if (theme.getDescription().equals(thisItem)
-                || theme.getFacet().equals("area")
-                || theme.getFacet().equals("cross_section.area")
-            ) {
-                continue;
-            }
-            MenuItem againster = new MenuItem(theme.getDescription());
-            underMenu.addItem(againster);
-
-            againster.addClickHandler(new ClickHandler() {
-                public void onClick(MenuItemClickEvent evt) {
-                    disable();
-                    createAreaArtifact(theme, facetTheme, false);
-                }
-            });
-        }
+        return (a.getFacet().equals("cross_section")
+                || a.getFacet().equals("cross_section_water_line"))
+            && (b.getFacet().equals("cross_section")
+                || b.getFacet().equals("cross_section_water_line"));
+    }
 
-        MenuItem overMenuItem = new MenuItem("Over ...");
-        Menu overMenu = new Menu();
-        for (int i = 0; i < nThemes; i++)  {
-            final Theme theme = themes.getThemeAt(i+1);
-            if (theme.getDescription().equals(thisItem)
-                || theme.getFacet().equals("area")
-                || theme.getFacet().equals("cross_section.area")
-            ) {
-                continue;
-            }
-            MenuItem againster = new MenuItem(theme.getDescription());
-            overMenu.addItem(againster);
-
-            againster.addClickHandler(new ClickHandler() {
-                public void onClick(MenuItemClickEvent evt) {
-                    disable();
-                    createAreaArtifact(facetTheme, theme, false);
-                }
-            });
-        }
-        overMenu.addItem(createSeparator());
-        MenuItem againstAxis = new MenuItem(MSG.getString("x_axis"));
-        againstAxis.addClickHandler(new ClickHandler() {
-            public void onClick(MenuItemClickEvent evt) {
-                disable();
-                createAreaArtifact(facetTheme, null, false);
-            }
-        });
-        overMenu.addItem(againstAxis);
 
-        MenuItem betweenMenuItem = new MenuItem("Between ...");
-        Menu betweenMenu = new Menu();
-        for (int i = 0; i < nThemes; i++)  {
-            final Theme theme = themes.getThemeAt(i+1);
-            if (theme.getDescription().equals(thisItem)
-                || theme.getFacet().equals("area")
-                || theme.getFacet().equals("cross_section.area")
-            ) {
-                continue;
-            }
-            MenuItem againster = new MenuItem(theme.getDescription());
-            betweenMenu.addItem(againster);
-
-            againster.addClickHandler(new ClickHandler() {
-                public void onClick(MenuItemClickEvent evt) {
-                    disable();
-                    createAreaArtifact(facetTheme, theme, true);
-                }
-            });
-        }
-        betweenMenu.addItem(createSeparator());
-        betweenMenu.addItem(againstAxis);
-
-        overMenuItem.setSubmenu(overMenu);
-        underMenuItem.setSubmenu(underMenu);
-        betweenMenuItem.setSubmenu(betweenMenu);
-
-        areaMenu.addItem(overMenuItem);
-        areaMenu.addItem(underMenuItem);
-        areaMenu.addItem(betweenMenuItem);
-
-        areaMenuItem.setSubmenu(areaMenu);
-        menu.addItem(areaMenuItem);
-
-        return menu;
+    /**
+     * True if context menu should contain 'create area' submenu on
+     * this theme.
+     */
+    protected boolean canArea(Theme a) {
+        return a.getFacet().equals("cross_section")
+            || a.getFacet().equals("cross_section_water_line");
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org