Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java @ 822:ffb98b228b3c
Add code to extract data to load from datacage tree.
flys-client/trunk@2493 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 12 Aug 2011 15:51:51 +0000 |
parents | 56069d236afa |
children | 2f65c742803f |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java Tue Aug 09 13:37:40 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java Fri Aug 12 15:51:51 2011 +0000 @@ -7,6 +7,7 @@ import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Window; +import com.smartgwt.client.widgets.Button; import com.smartgwt.client.widgets.tree.Tree; import com.smartgwt.client.widgets.tree.TreeGrid; @@ -17,8 +18,13 @@ import com.smartgwt.client.widgets.layout.Layout; import com.smartgwt.client.widgets.layout.VLayout; -import com.smartgwt.client.widgets.tree.events.LeafClickEvent; -import com.smartgwt.client.widgets.tree.events.LeafClickHandler; +import com.smartgwt.client.widgets.events.ClickHandler; +import com.smartgwt.client.widgets.events.ClickEvent; + +import com.smartgwt.client.widgets.grid.ListGridRecord; + +import com.smartgwt.client.widgets.grid.events.RecordDoubleClickEvent; +import com.smartgwt.client.widgets.grid.events.RecordDoubleClickHandler; import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.shared.model.ArtifactDescription; @@ -26,6 +32,7 @@ import de.intevation.flys.client.shared.model.DataList; import de.intevation.flys.client.shared.model.DataItem; import de.intevation.flys.client.shared.model.User; +import de.intevation.flys.client.shared.model.ToLoad; import de.intevation.flys.client.client.FLYSConstants; import de.intevation.flys.client.client.Config; @@ -39,6 +46,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Stack; public class DatacageWindow extends Window @@ -58,13 +66,15 @@ protected Layout layout; + protected List<ToLoad> toLoad; + public DatacageWindow(Artifact artifact, User user) { this.artifact = artifact; this.user = user; - setWidth(250); - setHeight(400); + setWidth(300); + setHeight(500); layout = new VLayout(); layout.setWidth100(); @@ -83,15 +93,26 @@ treeGrid.setHeight100(); treeGrid.setShowRoot(false); - treeGrid.addLeafClickHandler(new LeafClickHandler() { + treeGrid.addRecordDoubleClickHandler(new RecordDoubleClickHandler() { @Override - public void onLeafClick(LeafClickEvent lce) { - GWT.log("I was here"); + public void onRecordDoubleClick(RecordDoubleClickEvent event) { + doubleClickedOnTree(event); } }); layout.addMember(treeGrid); + // TODO: i18n + icon + Button plusBtn = new Button("+"); + plusBtn.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + plusClicked(); + } + }); + + layout.addMember(plusBtn); + String river = findRiver(); // TODO: i18n setTitle("Datenkorb: " + river); @@ -102,9 +123,73 @@ centerInPage(); + toLoad = new ArrayList<ToLoad>(); + triggerTreeBuilding(); } + public List<ToLoad> toLoad() { + return toLoad; + } + + public void plusClicked() { + if (treeGrid == null) { + return; + } + + ListGridRecord [] selection = treeGrid.getSelection(); + + if (selection != null) { + for (ListGridRecord record: selection) { + if (record instanceof TreeNode) { + collectToLoads((TreeNode)record); + } + } + } + + GWT.log(toLoad.toString()); + + if (!toLoad.isEmpty()) { + destroy(); + } + } + + protected void doubleClickedOnTree(RecordDoubleClickEvent event) { + + TreeNode node = (TreeNode)event.getRecord(); + collectToLoads(node); + GWT.log(toLoad.toString()); + destroy(); + } + + protected void collectToLoads(TreeNode node) { + Stack<TreeNode> stack = new Stack<TreeNode>(); + + stack.push(node); + + while (!stack.isEmpty()) { + node = stack.pop(); + String factory = node.getAttribute("factory"); + if (factory != null) { // we need at least a factory + String ids = node.getAttribute("ids"); + String artifactId = node.getAttribute("artifact-id"); + String num = node.getAttribute("num"); + + ToLoad tl = new ToLoad(factory, artifactId, ids, num); + if (!toLoad.contains(tl)) { + toLoad.add(tl); + } + } + TreeNode [] children = tree.getChildren(node); + if (children != null) { + for (TreeNode child: children) { + stack.push(child); + } + } + } + } + + protected void triggerTreeBuilding() { Config config = Config.getInstance(); String url = config.getServerUrl();