changeset 1325:2f5fbfeda1d4

Introduced i18n for datacage flys-client/trunk@2967 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 13 Oct 2011 16:30:55 +0000
parents 90b786325324
children 974c6b3700de
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java
diffstat 5 files changed, 84 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Thu Oct 13 12:55:16 2011 +0000
+++ b/flys-client/ChangeLog	Thu Oct 13 16:30:55 2011 +0000
@@ -1,3 +1,16 @@
+2011-10-13	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java:
+	  Removed top level '${datacage}' using CHILDREN mode for tree.
+	  Introduced i18n.
+	  If tree contains less the MAX_OPEN (30) nodes and leafs the
+	  tree is rendered all open. This minimizes clicks.
+
+	* src/main/java/de/intevation/flys/client/client/FLYSConstants.java,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties:
+	  i18n for data cage
+
 2011-10-13  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/webapp/images/adjustElevation.png: Replaced old one that had a
@@ -79,7 +92,7 @@
 	  src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties:
 	  Added warning and error messages used when elevation control is used.
 
-2011-10-13	Sascha L, Teichmann	<sascha.teichmann@intevation.de>
+2011-10-13	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	Updated SmartGWT to 2.5
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Thu Oct 13 12:55:16 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Thu Oct 13 16:30:55 2011 +0000
@@ -451,5 +451,11 @@
     String measureDistance();
 
     String measureArea();
+
+    // data cage
+
+    String old_calculations();
+
+    String datacageAdd();
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Thu Oct 13 12:55:16 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Thu Oct 13 16:30:55 2011 +0000
@@ -229,3 +229,7 @@
 adjustElevationTooltip = Festlegen von H\u00f6hen für D\u00e4mme, Ringeiche, Gr\u00e4ben und Rohre
 measureDistance = L\u00e4ngenmessung
 measureArea = Streckenmessung
+
+# data cage
+old_calculations = Alte Berechnungen
+datacageAdd = Daten laden
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Thu Oct 13 12:55:16 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Thu Oct 13 16:30:55 2011 +0000
@@ -223,3 +223,7 @@
 adjustElevationTooltip = Define elevations for barriers
 measureDistance = Measure line
 measureArea = Measure area
+
+# data cage
+old_calculations = Former calculations
+datacageAdd = Add data
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java	Thu Oct 13 12:55:16 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java	Thu Oct 13 16:30:55 2011 +0000
@@ -44,6 +44,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.MissingResourceException;
 import java.util.Stack;
 
 // TODO: refactor, extract ~DataCageGrid
@@ -54,6 +55,8 @@
 public class DatacageWidget
 extends      VLayout
 {
+    public static final int MAX_OPEN = 30;
+
     protected MetaDataServiceAsync metaDataService =
         GWT.create(MetaDataService.class);
 
@@ -117,16 +120,19 @@
         setWidth100();
 
         tree = new Tree();
-        tree.setModelType(TreeModelType.PARENT);
+        tree.setModelType(TreeModelType.CHILDREN);
         tree.setNameProperty("name");
         tree.setIdField("id");
-        tree.setParentIdField("parent-id");
+        tree.setChildrenProperty("children-nodes");
+        tree.setShowRoot(false);
 
         treeGrid = new TreeGrid();
         treeGrid.setLoadDataOnDemand(false);
         treeGrid.setWidth100();
         treeGrid.setHeight100();
         treeGrid.setShowRoot(false);
+        treeGrid.setNodeIcon("[SKIN]/images/blank.gif");
+        treeGrid.setShowConnectors(true);
 
         treeGrid.addRecordDoubleClickHandler(new RecordDoubleClickHandler() {
             @Override
@@ -273,8 +279,7 @@
 
 
     protected Button createPlusButton() {
-        // TODO: i18n + icon
-        Button plusBtn = new Button("+");
+        Button plusBtn = new Button(messages.datacageAdd());
         plusBtn.addClickHandler(new ClickHandler() {
             @Override
             public void onClick(ClickEvent event) {
@@ -354,41 +359,71 @@
 
                 public void onSuccess(DataCageTree dcTree) {
                     GWT.log("Successfully loaded meta data.");
-                    tree.setData(treeToData(dcTree));
+                    IdGenerator idGenerator = new IdGenerator();
+                    DataCageNode dcRoot = dcTree.getRoot();
+                    TreeNode root = buildRecursiveChildren(
+                        dcRoot, idGenerator);
+                    tree.setRoot(root);
+                    if (idGenerator.current() < MAX_OPEN) {
+                        tree.openAll();
+                    }
                     treeGrid.setData(tree);
                 }
             });
     }
 
-    private static class IdGenerator {
+    private static final class IdGenerator {
         protected int current;
 
         public IdGenerator() {
         }
 
-        public IdGenerator(int start) {
-            current = start;
+        public int next() {
+            return current++;
         }
 
-        public int next() {
-            return current++;
+        public int current() {
+            return current;
         }
     } // class IdGenerator
 
-    protected static void buildRecursive(
+    private String i18n(String s) {
+        if (!(s.startsWith("${") && s.endsWith("}"))) {
+            return s;
+        }
+
+        s = s.substring(2, s.length()-1);
+
+        try {
+            return messages.getString(s);
+        }
+        catch (MissingResourceException mre) {
+            GWT.log("cannot find i18n for + '" + s + "'");
+            return s;
+        }
+    }
+
+    protected TreeNode buildRecursiveChildren(
         DataCageNode   node, 
-        int            parentId,
-        IdGenerator    idGenerator,
-        List<TreeNode> nodes
+        IdGenerator    idGenerator
     ) {
         TreeNode tn = new TreeNode();
-        int id = idGenerator.next();
-        tn.setAttribute("parent-id", parentId);
-        tn.setAttribute("id", id);
-        // TODO: i18n
-        tn.setAttribute("name", node.getDescription());
+        tn.setAttribute("id", idGenerator.next());
+
+        List<DataCageNode> children = node.getChildren();
+
+        if (children != null) {
+            TreeNode [] tns = new TreeNode[children.size()];
+            for (int i = 0; i < tns.length; ++i) {
+                DataCageNode child = children.get(i);
+                tns[i] = buildRecursiveChildren(child, idGenerator);
+            }
+            tn.setAttribute("children-nodes", tns);
+        }
+
+        tn.setAttribute("name", i18n(node.getDescription()));
         tn.setAttribute("facet", node.getName());
-        nodes.add(tn);
+
         AttrList attrs = node.getAttributes();
         if (attrs != null) {
             for (int i = 0, N = attrs.size(); i < N; ++i) {
@@ -397,25 +432,8 @@
                 tn.setAttribute(key, value);
             }
         }
-        List<DataCageNode> children = node.getChildren();
-        if (children != null) {
-            for (DataCageNode child: children) {
-                buildRecursive(child, id, idGenerator, nodes);
-            }
-        }
-    }
-
 
-    protected static TreeNode [] treeToData(DataCageTree tree) {
-        List<TreeNode> nodes = new ArrayList<TreeNode>();
-
-        DataCageNode root = tree.getRoot();
-
-        IdGenerator idGenerator = new IdGenerator();
-
-        buildRecursive(root, idGenerator.next(), idGenerator, nodes);
-
-        return nodes.toArray(new TreeNode[nodes.size()]);
+        return tn;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org