diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DatacageWidget.java @ 9227:84397da33d17

Allow to control specific behaviour in TwinDatacagePanel Implemented client logic of 'intelligent datacage filtering' for SINFO
author gernotbelger
date Wed, 04 Jul 2018 18:28:08 +0200
parents e3c2ae1887e8
children
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DatacageWidget.java	Wed Jul 04 17:14:16 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DatacageWidget.java	Wed Jul 04 18:28:08 2018 +0200
@@ -48,7 +48,10 @@
  * Display tree of, for example, previous calculations and allows
  * selection in order to access/clone these.
  */
-public class DatacageWidget extends VLayout {
+public final class DatacageWidget extends VLayout {
+
+    private static final FLYSConstants MSG = GWT.create(FLYSConstants.class);
+
     public static final int MAX_OPEN = 30;
 
     public interface DatacageFilter {
@@ -62,10 +65,15 @@
         }
     };
 
+    public static final DatacageFilter ACCEPT_NONE_FILTER = new DatacageFilter() {
+        @Override
+        public boolean accept(final DataCageNode node) {
+            return false;
+        }
+    };
+
     private final MetaDataServiceAsync metaDataService = GWT.create(MetaDataService.class);
 
-    private final FLYSConstants messages = GWT.create(FLYSConstants.class);
-
     private final List<DatacageHandler> handlers = new ArrayList<DatacageHandler>();
 
     private final List<DatacageDoubleClickHandler> doubleHandlers = new ArrayList<DatacageDoubleClickHandler>();
@@ -105,11 +113,9 @@
         this.treeGrid.setShowRoot(false);
         this.treeGrid.setNodeIcon("[SKIN]/../blank.gif");
         this.treeGrid.setShowConnectors(true);
-        this.treeGrid.setLoadingMessage(this.messages.databasket_loading());
-        this.treeGrid.setLoadingDataMessage(this.messages.databasket_loading());
-
-        // FIXME: other message
-        this.treeGrid.setEmptyMessage(this.messages.databasket_loading());
+        this.treeGrid.setLoadingMessage(MSG.databasket_loading());
+        this.treeGrid.setLoadingDataMessage(MSG.databasket_loading());
+        this.treeGrid.setEmptyMessage(MSG.databasket_empty());
 
         this.treeGrid.setHoverMoveWithMouse(true);
         this.treeGrid.setCanHover(true);
@@ -157,6 +163,10 @@
             updateTree(this.dcTree);
     }
 
+    public TreeGrid getTreeGrid() {
+        return this.treeGrid;
+    }
+
     /** Disable input, show spinning wheel of joy. */
     private void lockUI() {
         this.lockScreen = ScreenLock.lockUI(this, this.lockScreen);
@@ -211,11 +221,13 @@
 
     public ToLoad getSelection() {
         // Reset content of toLoads.
+
+        // FIXME: bad... instead we should react to selection events and update toLoad in this way.
+
         this.toLoad = new ToLoad();
 
-        if (this.treeGrid == null) {
+        if (this.treeGrid == null)
             return this.toLoad;
-        }
 
         final ListGridRecord[] selection = this.treeGrid.getSelectedRecords();
 
@@ -278,7 +290,7 @@
     }
 
     private Button createPlusButton() {
-        final Button plusBtn = new Button(this.messages.datacageAdd());
+        final Button plusBtn = new Button(MSG.datacageAdd());
         plusBtn.addClickHandler(new ClickHandler() {
             @Override
             public void onClick(final ClickEvent event) {
@@ -312,13 +324,13 @@
      * Afterwards, add all children of node to stack to parse (next time
      * collectToLoads is called).
      */
-    private void collectToLoads(TreeNode node) {
+    private void collectToLoads(final TreeNode root1) {
         final Stack<TreeNode> stack = new Stack<TreeNode>();
 
-        stack.push(node);
+        stack.push(root1);
 
         while (!stack.isEmpty()) {
-            node = stack.pop();
+            final TreeNode node = stack.pop();
             final String factory = node.getAttribute("factory");
             if (factory != null) { // we need at least a factory
                 final String artifact = node.getAttribute("artifact-id");
@@ -384,7 +396,7 @@
         updateTree(this.dcTree);
     }
 
-    private void updateTree(final DataCageTree data) {
+    private void updateTree(final DataCageTree dcData) {
 
         this.tree = new Tree();
         this.tree.setModelType(TreeModelType.CHILDREN);
@@ -394,7 +406,7 @@
         this.tree.setShowRoot(false);
 
         final IdGenerator idGenerator = new IdGenerator();
-        final DataCageNode dcRoot = data.getRoot();
+        final DataCageNode dcRoot = dcData.getRoot();
         final TreeNode root = buildRecursiveChildren(dcRoot, idGenerator);
         if (root != null) {
             this.tree.setRoot(root);
@@ -428,19 +440,18 @@
         }
     } // class IdGenerator
 
-    private String i18n(String s) {
-        if (!(s.startsWith("${") && s.endsWith("}"))) {
+    private String i18n(final String s) {
+        if (!(s.startsWith("${") && s.endsWith("}")))
             return s;
-        }
 
-        s = s.substring(2, s.length() - 1);
+        final String sub = s.substring(2, s.length() - 1);
 
         try {
-            return this.messages.getString(s);
+            return MSG.getString(sub);
         }
         catch (final MissingResourceException mre) {
-            GWT.log("cannot find i18n for + '" + s + "'");
-            return s;
+            GWT.log("cannot find i18n for + '" + sub + "'", mre);
+            return sub;
         }
     }
 

http://dive4elements.wald.intevation.org