# HG changeset patch # User Sascha L. Teichmann # Date 1312897060 0 # Node ID 56069d236afa3f10755605f429e4b3f8cda10465 # Parent 912379835298878c82ef16aab98d4880c5d0acdf Datacage: Build UI tree in a more compatible style flys-client/trunk@2479 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 912379835298 -r 56069d236afa flys-client/ChangeLog --- a/flys-client/ChangeLog Tue Aug 09 13:02:10 2011 +0000 +++ b/flys-client/ChangeLog Tue Aug 09 13:37:40 2011 +0000 @@ -1,3 +1,15 @@ +2011-08-09 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/client/server/meta/Converter.java: + Do not use 'name' attribute of datacage. + + * src/main/java/de/intevation/flys/client/client/widgets/tree/AttributedTreeNode.java: + Removed. Not longer needed. + + * src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java: + Build the UI tree in a more smartgwt compatible style. Prevents lots + of exception when using click listeners. + 2011-08-09 Felix Wolfsteller * src/main/java/de/intevation/flys/client/client/ui/CollectionView.java: diff -r 912379835298 -r 56069d236afa flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java Tue Aug 09 13:02:10 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java Tue Aug 09 13:37:40 2011 +0000 @@ -1,7 +1,5 @@ package de.intevation.flys.client.client.ui; -import java.util.List; - import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -12,6 +10,9 @@ import com.smartgwt.client.widgets.tree.Tree; import com.smartgwt.client.widgets.tree.TreeGrid; +import com.smartgwt.client.widgets.tree.TreeNode; + +import com.smartgwt.client.types.TreeModelType; import com.smartgwt.client.widgets.layout.Layout; import com.smartgwt.client.widgets.layout.VLayout; @@ -36,7 +37,8 @@ import de.intevation.flys.client.shared.model.DataCageNode; import de.intevation.flys.client.shared.model.AttrList; -import de.intevation.flys.client.client.widgets.tree.AttributedTreeNode; +import java.util.ArrayList; +import java.util.List; public class DatacageWindow extends Window @@ -52,6 +54,7 @@ protected User user; protected TreeGrid treeGrid; + protected Tree tree; protected Layout layout; @@ -68,10 +71,24 @@ addItem(layout); + tree = new Tree(); + tree.setModelType(TreeModelType.PARENT); + tree.setNameProperty("name"); + tree.setIdField("id"); + tree.setParentIdField("parent-id"); + treeGrid = new TreeGrid(); treeGrid.setLoadDataOnDemand(false); treeGrid.setWidth100(); treeGrid.setHeight100(); + treeGrid.setShowRoot(false); + + treeGrid.addLeafClickHandler(new LeafClickHandler() { + @Override + public void onLeafClick(LeafClickEvent lce) { + GWT.log("I was here"); + } + }); layout.addMember(treeGrid); @@ -106,62 +123,69 @@ SC.warn(caught.getMessage()); } - public void onSuccess(DataCageTree tree) { + public void onSuccess(DataCageTree dcTree) { GWT.log("Successfully loaded meta data."); - buildTree(tree); + tree.setData(treeToData(dcTree)); + treeGrid.setData(tree); } }); } - protected void buildTree(DataCageTree tree) { - treeGrid.setData(convertTree(tree)); - } - - protected static AttributedTreeNode convert(DataCageNode node) { - List children = node.getChildren(); + private static class IdGenerator { + protected int current; - AttributedTreeNode [] cs; + public IdGenerator() { + } - if (children != null) { - cs = new AttributedTreeNode[children.size()]; + public IdGenerator(int start) { + current = start; + } - for (int i = 0, N = children.size(); i < N; ++i) { - cs[i] = convert(children.get(i)); + public int next() { + return current++; + } + } // class IdGenerator + + protected static void buildRecursive( + DataCageNode node, + int parentId, + IdGenerator idGenerator, + List nodes + ) { + TreeNode tn = new TreeNode(); + int id = idGenerator.next(); + tn.setAttribute("parent-id", parentId); + tn.setAttribute("id", id); + // TODO: i18n + tn.setAttribute("name", node.getName()); + nodes.add(tn); + AttrList attrs = node.getAttributes(); + if (attrs != null) { + for (int i = 0, N = attrs.size(); i < N; ++i) { + String key = attrs.getKey(i); + String value = attrs.getValue(i); + tn.setAttribute(key, value); } } - else { - cs = new AttributedTreeNode[0]; + List children = node.getChildren(); + if (children != null) { + for (DataCageNode child: children) { + buildRecursive(child, id, idGenerator, nodes); + } } - - return new AttributedTreeNode( - node.getName(), node.getAttributes(), cs); } - protected static Tree convertTree(DataCageTree tree) { + + protected static TreeNode [] treeToData(DataCageTree tree) { + List nodes = new ArrayList(); + DataCageNode root = tree.getRoot(); - List children = root.getChildren(); - - AttributedTreeNode [] cs; - - if (children != null) { - cs = new AttributedTreeNode[children.size()]; + IdGenerator idGenerator = new IdGenerator(); - for (int i = 0, N = children.size(); i < N; ++i) { - cs[i] = convert(children.get(i)); - } - } - else { - cs = new AttributedTreeNode[0]; - } + buildRecursive(root, idGenerator.next(), idGenerator, nodes); - AttributedTreeNode rn = new AttributedTreeNode( - root.getName(), root.getAttributes(), cs); - - Tree r = new Tree(); - r.setRoot(rn); - - return r; + return nodes.toArray(new TreeNode[nodes.size()]); } protected String findRiver() { diff -r 912379835298 -r 56069d236afa flys-client/src/main/java/de/intevation/flys/client/client/widgets/tree/AttributedTreeNode.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/widgets/tree/AttributedTreeNode.java Tue Aug 09 13:02:10 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -package de.intevation.flys.client.client.widgets.tree; - -import com.smartgwt.client.widgets.tree.TreeNode; - -import com.google.gwt.core.client.JavaScriptObject; - -import de.intevation.flys.client.shared.model.AttrList; - -public class AttributedTreeNode -extends TreeNode -{ - protected AttrList attrs; - - public AttributedTreeNode() { - } - - public AttributedTreeNode(JavaScriptObject jsObj) { - super(jsObj); - } - - public AttributedTreeNode(String name) { - super(name); - } - - public AttributedTreeNode(String name, TreeNode ... children) { - super(name, children); - } - - public AttributedTreeNode(String name, AttrList attrs) { - super(name); - this.attrs = attrs; - } - - public AttributedTreeNode(String name, AttrList attrs, TreeNode ... children) { - super(name, children); - this.attrs = attrs; - } - - public AttrList getSpecialAttributes() { - return attrs; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 912379835298 -r 56069d236afa flys-client/src/main/java/de/intevation/flys/client/server/meta/Converter.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/meta/Converter.java Tue Aug 09 13:02:10 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/meta/Converter.java Tue Aug 09 13:37:40 2011 +0000 @@ -79,7 +79,6 @@ protected void registerConverters() { System.err.println("register converters called"); - converters.put("datacage", NAME_CONVERTER); converters.put("river", NAME_CONVERTER); converters.put("gauge", NAME_CONVERTER); converters.put("historical", NAME_CONVERTER);