changeset 528:39d9291513cc

Connected the actions in the navigation panel with the theme list in the ChartThemePanel - themes can be moved now. flys-client/trunk@2009 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 26 May 2011 13:53:36 +0000
parents 902609b5cc79
children a1048d310829
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/shared/model/DefaultTheme.java flys-client/src/main/java/de/intevation/flys/client/shared/model/Theme.java flys-client/src/main/java/de/intevation/flys/client/shared/model/ThemeList.java
diffstat 5 files changed, 201 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed May 25 16:23:16 2011 +0000
+++ b/flys-client/ChangeLog	Thu May 26 13:53:36 2011 +0000
@@ -1,3 +1,21 @@
+2011-05-26  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/model/Theme.java,
+	  src/main/java/de/intevation/flys/client/shared/model/DefaultTheme.java:
+	  Added further methods to set the position of a theme to a new value and
+	  to compare two theme objects.
+
+	* src/main/java/de/intevation/flys/client/shared/model/ThemeList.java:
+	  Added a method to set the position of a theme to a new value. Based on
+	  the new position, all other themes in this list are moved up or down.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java:
+	  The actions in the navigation panel have now an effect on the order of
+	  the themes in the theme list. The selected theme/s is/are moved to
+	  top/bottom or just a single field up/down.
+
+	  NOTE: The order still have no effect on the chart rendering process.
+
 2011-05-25  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/event/OnMoveHandler.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java	Wed May 25 16:23:16 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java	Thu May 26 13:53:36 2011 +0000
@@ -3,7 +3,6 @@
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
-import com.smartgwt.client.types.Alignment;
 import com.smartgwt.client.types.ListGridFieldType;
 import com.smartgwt.client.util.SC;
 import com.smartgwt.client.widgets.Canvas;
@@ -130,6 +129,16 @@
 
 
     /**
+     * Returns the ThemeList of the current collection and output mode.
+     *
+     * @return the current ThemeList.
+     */
+    public ThemeList getThemeList() {
+        return collection.getThemeList(mode.getName());
+    }
+
+
+    /**
      * A method that removes all records from theme grid.
      */
     protected void clearGrid() {
@@ -154,7 +163,7 @@
 
         clearGrid();
 
-        ThemeList themeList = collection.getThemeList(mode.getName());
+        ThemeList themeList = getThemeList();
 
         if (themeList == null) {
             GWT.log("ERROR: No theme list.");
@@ -200,7 +209,7 @@
     protected void updateThemeList(Theme theme) {
         GWT.log("Update theme: " + theme.getFacet());
 
-        ThemeList themeList = collection.getThemeList(mode.getName());
+        ThemeList themeList = getThemeList();
 
         String a = theme.getArtifact();
         String f = theme.getFacet();
@@ -256,9 +265,109 @@
 
 
     public void onMove(OnMoveEvent event) {
-        GWT.log("ChartThemePanel.onMove: " + event.getType());
+        int type = event.getType();
 
-        // TODO IMPLEMENT ME
+        GWT.log("ChartThemePanel.onMove: " + type);
+
+        ListGridRecord[] records = list.getSelection();
+
+        if (records == null || records.length == 0) {
+            GWT.log("ChartThemePanel.onMove: No records selected.");
+            return;
+        }
+
+        switch (type) {
+            case 0: moveRecordsTop(records); break;
+            case 1: moveRecordsUp(records); break;
+            case 2: moveRecordsDown(records); break;
+            case 3: moveRecordsBottom(records); break;
+        }
+    }
+
+
+    /**
+     * Moves the selected grid records (themes) to the top of the grid.
+     *
+     * @param records The selected themes in the list. Null not permitted.
+     */
+    protected void moveRecordsTop(ListGridRecord[] records) {
+        ThemeList themeList = getThemeList();
+
+        int idx = 1;
+
+        for (ListGridRecord record: records) {
+            Theme theme = ((FacetRecord) record).getTheme();
+            themeList.setThemePosition(theme, idx++);
+        }
+
+        updateGrid();
+    }
+
+
+    /**
+     * Moves the selected grid records (themes) one step up.
+     *
+     * @param records The selected themes in the list. Null not permitted.
+     */
+    protected void moveRecordsUp(ListGridRecord[] records) {
+        ThemeList themeList = getThemeList();
+
+        int[] newPos = new int[records.length];
+
+        for (int i = 0; i < records.length ; i++) {
+            Theme theme = ((FacetRecord) records[i]).getTheme();
+            newPos[i]   = theme.getPosition() - 1;
+        }
+
+        for (int i = 0; i < records.length ; i++) {
+            Theme theme = ((FacetRecord) records[i]).getTheme();
+            themeList.setThemePosition(theme, newPos[i]);
+        }
+
+        updateGrid();
+    }
+
+
+    /**
+     * Moves the selected grid records (themes) one step down.
+     *
+     * @param records The selected themes in the list. Null not permitted.
+     */
+    protected void moveRecordsDown(ListGridRecord[] records) {
+        ThemeList themeList = getThemeList();
+
+        int[] newPos = new int[records.length];
+
+        for (int i = records.length-1; i >= 0; i--) {
+            Theme theme = ((FacetRecord) records[i]).getTheme();
+            newPos[i] = theme.getPosition()+1;
+        }
+
+        for (int i = records.length-1; i >= 0; i--) {
+            Theme theme = ((FacetRecord) records[i]).getTheme();
+            themeList.setThemePosition(theme, newPos[i]);
+        }
+
+        updateGrid();
+    }
+
+
+    /**
+     * Moves the selected grid records (themes) to the bottom of the grid.
+     *
+     * @param records The selected themes in the list. Null not permitted.
+     */
+    protected void moveRecordsBottom(ListGridRecord[] records) {
+        ThemeList themeList = getThemeList();
+
+        int idx = themeList.getThemeCount();
+
+        for (int i = records.length-1; i >= 0; i--) {
+            Theme theme = ((FacetRecord) records[i]).getTheme();
+            themeList.setThemePosition(theme, idx--);
+        }
+
+        updateGrid();
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultTheme.java	Wed May 25 16:23:16 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultTheme.java	Thu May 26 13:53:36 2011 +0000
@@ -32,6 +32,11 @@
     }
 
 
+    public void setPosition(int pos) {
+        this.position = pos;
+    }
+
+
     public boolean isActive() {
         return active;
     }
@@ -45,5 +50,32 @@
     public String getFacet() {
         return facet;
     }
+
+
+    public boolean equals(Object o) {
+        if (!(o instanceof DefaultTheme)) {
+            return false;
+        }
+
+        DefaultTheme other = (DefaultTheme) o;
+
+        if (other.position != position) {
+            return false;
+        }
+
+        if (!other.artifact.equals(artifact)) {
+            return false;
+        }
+
+        if (other.active != active) {
+            return false;
+        }
+
+        if (!other.facet.equals(facet)) {
+            return false;
+        }
+
+        return true;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Theme.java	Wed May 25 16:23:16 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Theme.java	Thu May 26 13:53:36 2011 +0000
@@ -10,10 +10,14 @@
 
     int getPosition();
 
+    void setPosition(int pos);
+
     boolean isActive();
 
     String getArtifact();
 
     String getFacet();
+
+    boolean equals(Object o);
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ThemeList.java	Wed May 25 16:23:16 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/ThemeList.java	Thu May 26 13:53:36 2011 +0000
@@ -63,5 +63,38 @@
             themes.add(theme);
         }
     }
+
+
+    /**
+     * Modifies the order of themes in this list and the position of the
+     * <i>theme</i> itself.
+     *
+     * @param theme The theme which position has to be modified.
+     * @param newPos The new position.
+     */
+    public void setThemePosition(Theme theme, int newPos) {
+        int count  = getThemeCount();
+        int oldPos = theme.getPosition();
+
+        if (newPos == oldPos || newPos > count || newPos < 1) {
+            return;
+        }
+
+        boolean moveUp = newPos < oldPos;
+
+        for (Theme aTheme: themes) {
+            int tmpPos = aTheme.getPosition();
+
+            if (theme.equals(aTheme)) {
+                theme.setPosition(newPos);
+            }
+            else if (tmpPos >= newPos && tmpPos < oldPos && moveUp) {
+                aTheme.setPosition(tmpPos+1);
+            }
+            else if (tmpPos <= newPos && tmpPos > oldPos && !moveUp) {
+                aTheme.setPosition(tmpPos-1);
+            }
+        }
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org