Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
821:56069d236afa | 822:ffb98b228b3c |
---|---|
5 import com.google.gwt.user.client.rpc.AsyncCallback; | 5 import com.google.gwt.user.client.rpc.AsyncCallback; |
6 | 6 |
7 import com.smartgwt.client.util.SC; | 7 import com.smartgwt.client.util.SC; |
8 | 8 |
9 import com.smartgwt.client.widgets.Window; | 9 import com.smartgwt.client.widgets.Window; |
10 import com.smartgwt.client.widgets.Button; | |
10 | 11 |
11 import com.smartgwt.client.widgets.tree.Tree; | 12 import com.smartgwt.client.widgets.tree.Tree; |
12 import com.smartgwt.client.widgets.tree.TreeGrid; | 13 import com.smartgwt.client.widgets.tree.TreeGrid; |
13 import com.smartgwt.client.widgets.tree.TreeNode; | 14 import com.smartgwt.client.widgets.tree.TreeNode; |
14 | 15 |
15 import com.smartgwt.client.types.TreeModelType; | 16 import com.smartgwt.client.types.TreeModelType; |
16 | 17 |
17 import com.smartgwt.client.widgets.layout.Layout; | 18 import com.smartgwt.client.widgets.layout.Layout; |
18 import com.smartgwt.client.widgets.layout.VLayout; | 19 import com.smartgwt.client.widgets.layout.VLayout; |
19 | 20 |
20 import com.smartgwt.client.widgets.tree.events.LeafClickEvent; | 21 import com.smartgwt.client.widgets.events.ClickHandler; |
21 import com.smartgwt.client.widgets.tree.events.LeafClickHandler; | 22 import com.smartgwt.client.widgets.events.ClickEvent; |
23 | |
24 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
25 | |
26 import com.smartgwt.client.widgets.grid.events.RecordDoubleClickEvent; | |
27 import com.smartgwt.client.widgets.grid.events.RecordDoubleClickHandler; | |
22 | 28 |
23 import de.intevation.flys.client.shared.model.Artifact; | 29 import de.intevation.flys.client.shared.model.Artifact; |
24 import de.intevation.flys.client.shared.model.ArtifactDescription; | 30 import de.intevation.flys.client.shared.model.ArtifactDescription; |
25 import de.intevation.flys.client.shared.model.Data; | 31 import de.intevation.flys.client.shared.model.Data; |
26 import de.intevation.flys.client.shared.model.DataList; | 32 import de.intevation.flys.client.shared.model.DataList; |
27 import de.intevation.flys.client.shared.model.DataItem; | 33 import de.intevation.flys.client.shared.model.DataItem; |
28 import de.intevation.flys.client.shared.model.User; | 34 import de.intevation.flys.client.shared.model.User; |
35 import de.intevation.flys.client.shared.model.ToLoad; | |
29 | 36 |
30 import de.intevation.flys.client.client.FLYSConstants; | 37 import de.intevation.flys.client.client.FLYSConstants; |
31 import de.intevation.flys.client.client.Config; | 38 import de.intevation.flys.client.client.Config; |
32 | 39 |
33 import de.intevation.flys.client.client.services.MetaDataService; | 40 import de.intevation.flys.client.client.services.MetaDataService; |
37 import de.intevation.flys.client.shared.model.DataCageNode; | 44 import de.intevation.flys.client.shared.model.DataCageNode; |
38 import de.intevation.flys.client.shared.model.AttrList; | 45 import de.intevation.flys.client.shared.model.AttrList; |
39 | 46 |
40 import java.util.ArrayList; | 47 import java.util.ArrayList; |
41 import java.util.List; | 48 import java.util.List; |
49 import java.util.Stack; | |
42 | 50 |
43 public class DatacageWindow | 51 public class DatacageWindow |
44 extends Window | 52 extends Window |
45 { | 53 { |
46 protected MetaDataServiceAsync metaDataService = | 54 protected MetaDataServiceAsync metaDataService = |
56 protected TreeGrid treeGrid; | 64 protected TreeGrid treeGrid; |
57 protected Tree tree; | 65 protected Tree tree; |
58 | 66 |
59 protected Layout layout; | 67 protected Layout layout; |
60 | 68 |
69 protected List<ToLoad> toLoad; | |
70 | |
61 | 71 |
62 public DatacageWindow(Artifact artifact, User user) { | 72 public DatacageWindow(Artifact artifact, User user) { |
63 this.artifact = artifact; | 73 this.artifact = artifact; |
64 this.user = user; | 74 this.user = user; |
65 | 75 |
66 setWidth(250); | 76 setWidth(300); |
67 setHeight(400); | 77 setHeight(500); |
68 | 78 |
69 layout = new VLayout(); | 79 layout = new VLayout(); |
70 layout.setWidth100(); | 80 layout.setWidth100(); |
71 | 81 |
72 addItem(layout); | 82 addItem(layout); |
81 treeGrid.setLoadDataOnDemand(false); | 91 treeGrid.setLoadDataOnDemand(false); |
82 treeGrid.setWidth100(); | 92 treeGrid.setWidth100(); |
83 treeGrid.setHeight100(); | 93 treeGrid.setHeight100(); |
84 treeGrid.setShowRoot(false); | 94 treeGrid.setShowRoot(false); |
85 | 95 |
86 treeGrid.addLeafClickHandler(new LeafClickHandler() { | 96 treeGrid.addRecordDoubleClickHandler(new RecordDoubleClickHandler() { |
87 @Override | 97 @Override |
88 public void onLeafClick(LeafClickEvent lce) { | 98 public void onRecordDoubleClick(RecordDoubleClickEvent event) { |
89 GWT.log("I was here"); | 99 doubleClickedOnTree(event); |
90 } | 100 } |
91 }); | 101 }); |
92 | 102 |
93 layout.addMember(treeGrid); | 103 layout.addMember(treeGrid); |
104 | |
105 // TODO: i18n + icon | |
106 Button plusBtn = new Button("+"); | |
107 plusBtn.addClickHandler(new ClickHandler() { | |
108 @Override | |
109 public void onClick(ClickEvent event) { | |
110 plusClicked(); | |
111 } | |
112 }); | |
113 | |
114 layout.addMember(plusBtn); | |
94 | 115 |
95 String river = findRiver(); | 116 String river = findRiver(); |
96 // TODO: i18n | 117 // TODO: i18n |
97 setTitle("Datenkorb: " + river); | 118 setTitle("Datenkorb: " + river); |
98 setShowMinimizeButton(false); | 119 setShowMinimizeButton(false); |
100 setShowModalMask(true); | 121 setShowModalMask(true); |
101 setCanDragResize(true); | 122 setCanDragResize(true); |
102 | 123 |
103 centerInPage(); | 124 centerInPage(); |
104 | 125 |
126 toLoad = new ArrayList<ToLoad>(); | |
127 | |
105 triggerTreeBuilding(); | 128 triggerTreeBuilding(); |
106 } | 129 } |
130 | |
131 public List<ToLoad> toLoad() { | |
132 return toLoad; | |
133 } | |
134 | |
135 public void plusClicked() { | |
136 if (treeGrid == null) { | |
137 return; | |
138 } | |
139 | |
140 ListGridRecord [] selection = treeGrid.getSelection(); | |
141 | |
142 if (selection != null) { | |
143 for (ListGridRecord record: selection) { | |
144 if (record instanceof TreeNode) { | |
145 collectToLoads((TreeNode)record); | |
146 } | |
147 } | |
148 } | |
149 | |
150 GWT.log(toLoad.toString()); | |
151 | |
152 if (!toLoad.isEmpty()) { | |
153 destroy(); | |
154 } | |
155 } | |
156 | |
157 protected void doubleClickedOnTree(RecordDoubleClickEvent event) { | |
158 | |
159 TreeNode node = (TreeNode)event.getRecord(); | |
160 collectToLoads(node); | |
161 GWT.log(toLoad.toString()); | |
162 destroy(); | |
163 } | |
164 | |
165 protected void collectToLoads(TreeNode node) { | |
166 Stack<TreeNode> stack = new Stack<TreeNode>(); | |
167 | |
168 stack.push(node); | |
169 | |
170 while (!stack.isEmpty()) { | |
171 node = stack.pop(); | |
172 String factory = node.getAttribute("factory"); | |
173 if (factory != null) { // we need at least a factory | |
174 String ids = node.getAttribute("ids"); | |
175 String artifactId = node.getAttribute("artifact-id"); | |
176 String num = node.getAttribute("num"); | |
177 | |
178 ToLoad tl = new ToLoad(factory, artifactId, ids, num); | |
179 if (!toLoad.contains(tl)) { | |
180 toLoad.add(tl); | |
181 } | |
182 } | |
183 TreeNode [] children = tree.getChildren(node); | |
184 if (children != null) { | |
185 for (TreeNode child: children) { | |
186 stack.push(child); | |
187 } | |
188 } | |
189 } | |
190 } | |
191 | |
107 | 192 |
108 protected void triggerTreeBuilding() { | 193 protected void triggerTreeBuilding() { |
109 Config config = Config.getInstance(); | 194 Config config = Config.getInstance(); |
110 String url = config.getServerUrl(); | 195 String url = config.getServerUrl(); |
111 String locale = config.getLocale(); | 196 String locale = config.getLocale(); |