changeset 790:3fa8583434b2

Made stepping forward/backword much smoother in the parameter list. flys-client/trunk@2294 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 06 Jul 2011 15:34:38 +0000
parents e8be9a188e64
children 9b1499a65aaa
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/event/ParameterChangeEvent.java flys-client/src/main/java/de/intevation/flys/client/client/ui/AutoIntegerPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/ContinuePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java
diffstat 5 files changed, 151 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Jul 06 13:06:04 2011 +0000
+++ b/flys-client/ChangeLog	Wed Jul 06 15:34:38 2011 +0000
@@ -1,3 +1,26 @@
+2011-07-06  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/event/ParameterChangeEvent.java:
+	  This event now supports a further member variable "type". Type is an
+	  enum and can be FORWARD or BACK which reflects to stepping forward or
+	  backward with the master artifact.
+
+	* src/main/java/de/intevation/flys/client/client/ui/ParameterList.java:
+	  Improved the way of adding/removing items to/from the static list of
+	  parameters. We now distinguish between the two ways:
+	  - step forward: the last item in the list is added to the static
+	                  parameter list. This makes redrawing much smoother.
+	  - step backward: only the necessary items are removed from the static
+	                   parameter list. Before, we have removed all items and
+	                   added the relevant ones afterwards. This makes
+	                   redrawing also much smoother.
+
+	* src/main/java/de/intevation/flys/client/client/ui/ContinuePanel.java:
+	  This panel will have no static widget.
+
+	* src/main/java/de/intevation/flys/client/client/ui/AutoIntegerPanel.java:
+	  This panel uses the parents createOld() now.
+
 2011-07-06  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/ParameterList.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/ParameterChangeEvent.java	Wed Jul 06 13:06:04 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/event/ParameterChangeEvent.java	Wed Jul 06 15:34:38 2011 +0000
@@ -10,14 +10,29 @@
  */
 public class ParameterChangeEvent {
 
+    public static enum Type {
+        FORWARD, BACK
+    }
+
+
     protected Artifact oldArtifact;
     protected Artifact newArtifact;
 
+    protected Type     type;
+
+
     public ParameterChangeEvent(Artifact old, Artifact newArt) {
-        oldArtifact = old;
-        newArtifact = newArt;
+        this(old, newArt, Type.FORWARD);
     }
 
+
+    public ParameterChangeEvent(Artifact oArt, Artifact nArt, Type type) {
+        oldArtifact = oArt;
+        newArtifact = nArt;
+        this.type   = type;
+    }
+
+
     public Artifact getOldValue() {
         return oldArtifact;
     }
@@ -25,5 +40,9 @@
     public Artifact getNewValue() {
         return newArtifact;
     }
+
+    public Type getType() {
+        return type;
+    }
 }
 // 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/AutoIntegerPanel.java	Wed Jul 06 13:06:04 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/AutoIntegerPanel.java	Wed Jul 06 15:34:38 2011 +0000
@@ -48,16 +48,6 @@
 
 
     @Override
-    public Canvas createOld(DataList dataList) {
-        Canvas c = new Canvas();
-        c.setHeight(1);
-        c.setWidth(1);
-
-        return c;
-    }
-
-
-    @Override
     protected Data[] getData() {
         GWT.log("+++ RETURN DATA FOR STATE: " + dataName + " +++");
         String value  = "TODO:FIND VALUE";
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ContinuePanel.java	Wed Jul 06 13:06:04 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ContinuePanel.java	Wed Jul 06 15:34:38 2011 +0000
@@ -56,11 +56,7 @@
 
     @Override
     public Canvas createOld(DataList dataList) {
-        Canvas c = new Canvas();
-        c.setHeight(1);
-        c.setWidth(1);
-
-        return c;
+        return null;
     }
 
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java	Wed Jul 06 13:06:04 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java	Wed Jul 06 15:34:38 2011 +0000
@@ -4,6 +4,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeMap;
 
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -95,6 +96,7 @@
     protected Artifact artifact;
 
     protected List<DataList> old;
+    protected Map<String, Canvas> oldStorage;
     protected DataList   current;
 
     protected UIProvider uiProvider;
@@ -116,6 +118,7 @@
 
         parameterHandlers = new ArrayList<ParameterChangeHandler>();
         old               = new ArrayList<DataList>();
+        oldStorage        = new TreeMap<String, Canvas>();
         topLayout         = new VLayout();
         oldItems          = new VLayout();
         currentItems      = new VLayout();
@@ -142,6 +145,7 @@
 
         parameterHandlers = new ArrayList<ParameterChangeHandler>();
         old               = new ArrayList<DataList>();
+        oldStorage        = new TreeMap<String, Canvas>();
         topLayout         = new VLayout();
         oldItems          = new VLayout();
         currentItems      = new VLayout();
@@ -152,7 +156,7 @@
 
         addParameterChangeHandler(this);
 
-        setArtifact(artifact);
+        setArtifact(artifact, false);
     }
 
 
@@ -247,10 +251,22 @@
 
 
     protected void setArtifact(Artifact artifact) {
+        setArtifact(artifact, true);
+    }
+
+
+    protected void setArtifact(Artifact artifact, boolean forward) {
         Artifact tmp  = this.artifact;
         this.artifact = artifact;
 
-        fireParameterChangeEvent(tmp, this.artifact);
+        if (forward) {
+            fireParameterChangeEvent(
+                tmp, this.artifact, ParameterChangeEvent.Type.FORWARD);
+        }
+        else {
+            fireParameterChangeEvent(
+                tmp, this.artifact, ParameterChangeEvent.Type.BACK);
+        }
     }
 
 
@@ -270,9 +286,15 @@
      * This method calls the <code>onParameterChange()</code> method of all
      * registered ParameterChangeHandler.
      */
-    protected void fireParameterChangeEvent(Artifact old, Artifact newArt) {
+    protected void fireParameterChangeEvent(
+        Artifact old,
+        Artifact newArt,
+        ParameterChangeEvent.Type type)
+    {
+        ParameterChangeEvent e = new ParameterChangeEvent(old, newArt, type);
+
         for (ParameterChangeHandler handler: parameterHandlers) {
-            handler.onParameterChange(new ParameterChangeEvent(old, newArt));
+            handler.onParameterChange(e);
         }
     }
 
@@ -348,6 +370,7 @@
 
                                 public void onSuccess(Artifact artifact) {
                                     GWT.log("Successfully feed the artifact.");
+                                    old.clear();
                                     setArtifact(artifact);
                                 }
                             });
@@ -369,15 +392,25 @@
 
 
     public void addOldData(DataList old) {
+        addOldData(old, true);
+    }
+
+
+    public void addOldData(DataList old, boolean redraw) {
         if (old != null) {
             this.old.add(old);
         }
 
-        refreshOld();
+        refreshOld(redraw);
     }
 
 
     public void addOldDatas(DataList[] old) {
+        addOldDatas(old, true);
+    }
+
+
+    public void addOldDatas(DataList[] old, boolean redraw) {
         if (old != null && old.length > 0) {
             for (DataList o: old) {
                 if (o == null) {
@@ -386,14 +419,18 @@
 
                 if (!exists(o)) {
                     GWT.log("Data '" + o.getLabel() + "' is new.");
-                    addOldData(o);
+                    addOldData(o, false);
                 }
             }
 
+            if (redraw) {
+                addOldData(null, true);
+            }
+
             return;
         }
 
-        addOldData(null);
+        addOldData(null, true);
     }
 
 
@@ -422,23 +459,64 @@
     }
 
 
-    public void refreshOld() {
-        // XXX maybe we should not remove all items but just add the newest item
-        // to the list.
-        oldItems.removeMembers(oldItems.getMembers());
+    public void refreshOld(boolean redrawAll) {
+        if (redrawAll) {
+            refreshAllOld();
+        }
+        else {
+            DataList dataList = old.get(old.size()-1);
+            String   state    = dataList.getState();
 
-        for (DataList dataList: old) {
-            HLayout h = new HLayout();
-            h.setAlign(VerticalAlignment.TOP);
-            h.setHeight(20);
+            if (oldStorage.get(state) == null) {
+                String     provider   = dataList.getUIProvider();
+                UIProvider uiprovider = UIProviderFactory.getProvider(provider);
+                ((HasStepBackHandlers) uiprovider).addStepBackHandler(this);
 
-            String     provider   = dataList.getUIProvider();
-            UIProvider uiprovider = UIProviderFactory.getProvider(provider);
-            ((HasStepBackHandlers) uiprovider).addStepBackHandler(this);
-
-            oldItems.addMember(uiprovider.createOld(dataList));
+                Canvas c = uiprovider.createOld(dataList);
+                if (c != null) {
+                    oldStorage.put(dataList.getState(), c);
+                    oldItems.addMember(c);
+                }
+            }
         }
 
+        updateOldHeight();
+    }
+
+
+    protected void refreshAllOld() {
+        List<String> not = new ArrayList<String>();
+
+        for (DataList data: old) {
+            String state = data.getState();
+
+            Canvas c = oldStorage.get(state);
+
+            if (c != null) {
+                not.add(state);
+            }
+        }
+
+        Map<String, Canvas> newOld = new TreeMap<String, Canvas>();
+
+        Set<Map.Entry<String, Canvas>> entries = oldStorage.entrySet();
+        for (Map.Entry<String, Canvas> entry: entries) {
+            String state = entry.getKey();
+            Canvas value = entry.getValue();
+
+            if (not.indexOf(state) < 0) {
+                oldItems.removeMember(value);
+            }
+            else {
+                newOld.put(state, value);
+            }
+        }
+
+        oldStorage = newOld;
+    }
+
+
+    protected void updateOldHeight() {
         int minHeight = oldItems.getMinHeight();
         if (minHeight <= 20) {
             oldItems.setHeight(20);
@@ -508,7 +586,9 @@
 
                 public void onSuccess(Artifact artifact) {
                     GWT.log("Successfully feed the artifact.");
-                    setArtifact(artifact);
+                    old.clear();
+
+                    setArtifact(artifact, true);
                 }
         });
     }
@@ -538,9 +618,8 @@
                     GWT.log("Successfully step back to '" + target + "'");
 
                     old.clear();
-                    oldItems.removeMembers(oldItems.getMembers());
 
-                    setArtifact(artifact);
+                    setArtifact(artifact, false);
                 }
             }
         );
@@ -563,9 +642,8 @@
                     GWT.log("Successfully advanced to '" + target + "'");
 
                     old.clear();
-                    oldItems.removeMembers(oldItems.getMembers());
 
-                    setArtifact(artifact);
+                    setArtifact(artifact, true);
                 }
             }
         );
@@ -622,7 +700,9 @@
             }
         }
 
-        addOldDatas(desc.getOldData());
+        addOldDatas(
+            desc.getOldData(),
+            event.getType() == ParameterChangeEvent.Type.BACK);
     }
 
 

http://dive4elements.wald.intevation.org