Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java @ 278:f33af25b7490
Datacage: transport rpc result to ui.
flys-client/trunk@1905 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 11 May 2011 16:38:54 +0000 |
parents | f4c8ce11df33 |
children | 3629d36f0e5d |
comparison
equal
deleted
inserted
replaced
277:50b88b641be6 | 278:f33af25b7490 |
---|---|
1 package de.intevation.flys.client.client.ui; | 1 package de.intevation.flys.client.client.ui; |
2 | 2 |
3 import java.util.List; | 3 import java.util.List; |
4 import java.util.ArrayList; | |
4 | 5 |
5 import com.google.gwt.core.client.GWT; | 6 import com.google.gwt.core.client.GWT; |
6 | 7 |
7 import com.google.gwt.user.client.rpc.AsyncCallback; | 8 import com.google.gwt.user.client.rpc.AsyncCallback; |
8 | 9 |
9 import com.smartgwt.client.util.SC; | 10 import com.smartgwt.client.util.SC; |
10 | 11 |
11 import com.smartgwt.client.widgets.Window; | 12 import com.smartgwt.client.widgets.Window; |
12 | 13 |
14 import com.smartgwt.client.widgets.tree.Tree; | |
15 import com.smartgwt.client.widgets.tree.TreeNode; | |
16 import com.smartgwt.client.widgets.tree.TreeGrid; | |
17 | |
18 import com.smartgwt.client.widgets.layout.Layout; | |
19 import com.smartgwt.client.widgets.layout.VLayout; | |
13 | 20 |
14 import de.intevation.flys.client.shared.model.Artifact; | 21 import de.intevation.flys.client.shared.model.Artifact; |
15 import de.intevation.flys.client.shared.model.ArtifactDescription; | 22 import de.intevation.flys.client.shared.model.ArtifactDescription; |
16 import de.intevation.flys.client.shared.model.Data; | 23 import de.intevation.flys.client.shared.model.Data; |
17 import de.intevation.flys.client.shared.model.DataList; | 24 import de.intevation.flys.client.shared.model.DataList; |
21 import de.intevation.flys.client.client.Config; | 28 import de.intevation.flys.client.client.Config; |
22 | 29 |
23 import de.intevation.flys.client.client.services.MetaDataService; | 30 import de.intevation.flys.client.client.services.MetaDataService; |
24 import de.intevation.flys.client.client.services.MetaDataServiceAsync; | 31 import de.intevation.flys.client.client.services.MetaDataServiceAsync; |
25 | 32 |
33 import de.intevation.flys.client.shared.model.DataCageTree; | |
34 import de.intevation.flys.client.shared.model.DataCageNode; | |
26 | 35 |
27 public class DatacageWindow | 36 public class DatacageWindow |
28 extends Window | 37 extends Window |
29 { | 38 { |
30 protected MetaDataServiceAsync metaDataService = | 39 protected MetaDataServiceAsync metaDataService = |
34 GWT.create(FLYSConstants.class); | 43 GWT.create(FLYSConstants.class); |
35 | 44 |
36 | 45 |
37 protected Artifact artifact; | 46 protected Artifact artifact; |
38 | 47 |
48 protected TreeGrid treeGrid; | |
49 | |
50 protected Layout layout; | |
51 | |
52 | |
39 public DatacageWindow(Artifact artifact) { | 53 public DatacageWindow(Artifact artifact) { |
40 this.artifact = artifact; | 54 this.artifact = artifact; |
41 setHeight(115); | 55 |
56 setWidth(200); | |
57 setHeight(300); | |
58 | |
59 layout = new VLayout(); | |
60 layout.setWidth100(); | |
61 | |
62 addItem(layout); | |
63 | |
64 treeGrid = new TreeGrid(); | |
65 treeGrid.setLoadDataOnDemand(false); | |
66 treeGrid.setWidth100(); | |
67 treeGrid.setHeight100(); | |
68 | |
69 layout.addMember(treeGrid); | |
70 | |
42 String river = findRiver(); | 71 String river = findRiver(); |
43 setTitle("Datenkorb: " + river); | 72 setTitle("Datenkorb: " + river); |
44 setShowMinimizeButton(false); | 73 setShowMinimizeButton(false); |
45 setIsModal(true); | 74 setIsModal(true); |
46 setShowModalMask(true); | 75 setShowModalMask(true); |
76 setCanDragResize(true); | |
77 | |
47 centerInPage(); | 78 centerInPage(); |
48 | 79 |
49 triggerTreeBuilding(river); | 80 triggerTreeBuilding(river); |
50 } | 81 } |
51 | 82 |
54 String url = config.getServerUrl(); | 85 String url = config.getServerUrl(); |
55 String locale = config.getLocale(); | 86 String locale = config.getLocale(); |
56 | 87 |
57 metaDataService.getMetaData( | 88 metaDataService.getMetaData( |
58 url, locale, river, | 89 url, locale, river, |
59 new AsyncCallback<List>() { | 90 new AsyncCallback<DataCageTree>() { |
60 public void onFailure(Throwable caught) { | 91 public void onFailure(Throwable caught) { |
61 GWT.log("Could not load meta data."); | 92 GWT.log("Could not load meta data."); |
62 SC.warn(messages.getString(caught.getMessage())); | 93 SC.warn(messages.getString(caught.getMessage())); |
63 } | 94 } |
64 | 95 |
65 public void onSuccess(List list) { | 96 public void onSuccess(DataCageTree tree) { |
66 GWT.log("Successfully created a new collection."); | 97 GWT.log("Successfully loaded meta data."); |
98 buildTree(tree); | |
67 } | 99 } |
68 }); | 100 }); |
101 } | |
102 | |
103 protected void buildTree(DataCageTree tree) { | |
104 treeGrid.setData(convert(tree)); | |
105 } | |
106 | |
107 protected static TreeNode convert(DataCageNode node) { | |
108 List<DataCageNode> children = node.getChildren(); | |
109 | |
110 TreeNode [] cs; | |
111 | |
112 if (children != null) { | |
113 ArrayList<TreeNode> nc = new ArrayList<TreeNode>(children.size()); | |
114 | |
115 for (DataCageNode dcn: children) { | |
116 nc.add(convert(dcn)); | |
117 } | |
118 | |
119 cs = nc.toArray(new TreeNode[nc.size()]); | |
120 } | |
121 else { | |
122 cs = new TreeNode[0]; | |
123 } | |
124 | |
125 return new TreeNode(node.getName(), cs); | |
126 } | |
127 | |
128 protected static Tree convert(DataCageTree tree) { | |
129 DataCageNode root = tree.getRoot(); | |
130 | |
131 List<DataCageNode> children = root.getChildren(); | |
132 | |
133 TreeNode [] cs; | |
134 | |
135 if (children != null) { | |
136 ArrayList<TreeNode> nc = new ArrayList<TreeNode>(children.size()); | |
137 | |
138 if (nc != null) { | |
139 for (DataCageNode dcn: children) { | |
140 nc.add(convert(dcn)); | |
141 } | |
142 } | |
143 cs = nc.toArray(new TreeNode[nc.size()]); | |
144 } | |
145 else { | |
146 cs = new TreeNode[0]; | |
147 } | |
148 | |
149 TreeNode rn = new TreeNode(root.getName(), cs); | |
150 | |
151 Tree r = new Tree(); | |
152 r.setRoot(rn); | |
153 | |
154 return r; | |
69 } | 155 } |
70 | 156 |
71 protected String findRiver() { | 157 protected String findRiver() { |
72 | 158 |
73 ArtifactDescription adescr = artifact.getArtifactDescription(); | 159 ArtifactDescription adescr = artifact.getArtifactDescription(); |