changeset 897:2b6efb8b2301

Refactored DatacageWidget to allow reuse in other use-cases. flys-client/trunk@2743 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 14 Sep 2011 14:18:54 +0000
parents fe23bbf0ea11
children a9dd792444a1
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java
diffstat 2 files changed, 70 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Sep 14 12:00:22 2011 +0000
+++ b/flys-client/ChangeLog	Wed Sep 14 14:18:54 2011 +0000
@@ -1,3 +1,13 @@
+2011-09-14	Felix Wolfsteller	<felix.wolfsteller@intevation.de> 
+
+	Ease access to selected elements of a DatacageWidget. Make button-less
+	DatacageWidget possible.
+
+	* src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java:
+	  Refactored to allow for button-less Widget and still be able to
+	  access current selection as ToLoad-objects from "outside"; in coo
+	  with Ingo Weinzierl.
+
 2011-09-14  Raimund Renkert <raimund.renkert@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/FLYSWorkspace.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java	Wed Sep 14 12:00:22 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java	Wed Sep 14 14:18:54 2011 +0000
@@ -44,6 +44,7 @@
 import java.util.List;
 import java.util.Stack;
 
+// TODO: refactor, extract ~DataCageGrid
 public class DatacageWidget
 extends      VLayout
 {
@@ -74,8 +75,12 @@
         this(artifact, user, null);
     }
 
+    public DatacageWidget(Artifact artifact, User user, String outs) {
+        this(artifact, user, outs, true);
+    }
 
-    public DatacageWidget(Artifact artifact, User user, String outs) {
+    public DatacageWidget(Artifact artifact, User user, String outs,
+         boolean showButton) {
         this();
 
         this.artifact = artifact;
@@ -107,37 +112,53 @@
 
         addMember(treeGrid);
 
-        // TODO: i18n + icon
-        Button plusBtn = new Button("+");
-        plusBtn.addClickHandler(new ClickHandler() {
-            @Override
-            public void onClick(ClickEvent event) {
-                plusClicked();
-            }
-        });
-
-        addMember(plusBtn);
+        if (showButton) {
+            addMember(createPlusButton());
+        }
 
         triggerTreeBuilding();
     }
 
+
+    /**
+     * @param handler Handler to be added (notified on add-action).
+     */
+    public DatacageWidget(Artifact artifact, User user, String outs,
+        DatacageHandler handler) {
+        this(artifact, user, outs);
+        this.addDatacageHandler(handler);
+    }
+
+
+    /**
+     * @param handler Handler to be added (notified on add-action).
+     */
     public void addDatacageHandler(DatacageHandler handler) {
         if (!handlers.contains(handler)) {
             handlers.add(handler);
         }
     }
 
+
+    /**
+     * @param handler Handler to remove from list.
+     */
     public void removeDatacageHandler(DatacageHandler handler) {
         handlers.remove(handler);
     }
 
+
     public ToLoad getToLoad() {
         return toLoad;
     }
 
-    public void plusClicked() {
+
+    public ToLoad getSelection() {
+        // Reset content of toLoads.
+        toLoad = new ToLoad();
+
         if (treeGrid == null) {
-            return;
+            return toLoad;
         }
 
         ListGridRecord [] selection = treeGrid.getSelection();
@@ -150,17 +171,41 @@
             }
         }
 
-        if (!toLoad.isEmpty()) {
+        return toLoad;
+    }
+
+
+    /**
+     * Callback for add-button.
+     * Fires to load for every selected element and handler.
+     */
+    public void plusClicked() {
+        if (!getSelection().isEmpty()) {
             fireToLoad();
         }
     }
 
+
+    protected Button createPlusButton() {
+        // TODO: i18n + icon
+        Button plusBtn = new Button("+");
+        plusBtn.addClickHandler(new ClickHandler() {
+            @Override
+            public void onClick(ClickEvent event) {
+                plusClicked();
+            }
+        });
+        return plusBtn;
+    }
+
+
     protected void fireToLoad() {
         for (DatacageHandler handler: handlers) {
             handler.toLoad(toLoad);
         }
     }
 
+
     protected void doubleClickedOnTree(RecordDoubleClickEvent event) {
 
         TreeNode node = (TreeNode)event.getRecord();
@@ -168,6 +213,7 @@
         destroy();
     }
 
+
     protected void collectToLoads(TreeNode node) {
         Stack<TreeNode> stack = new Stack<TreeNode>();
 

http://dive4elements.wald.intevation.org