Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacageWidget.java @ 897:2b6efb8b2301
Refactored DatacageWidget to allow reuse in other use-cases.
flys-client/trunk@2743 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 14 Sep 2011 14:18:54 +0000 |
parents | 63b258bf365c |
children | a1a5dc2b9e34 |
comparison
equal
deleted
inserted
replaced
896:fe23bbf0ea11 | 897:2b6efb8b2301 |
---|---|
42 | 42 |
43 import java.util.ArrayList; | 43 import java.util.ArrayList; |
44 import java.util.List; | 44 import java.util.List; |
45 import java.util.Stack; | 45 import java.util.Stack; |
46 | 46 |
47 // TODO: refactor, extract ~DataCageGrid | |
47 public class DatacageWidget | 48 public class DatacageWidget |
48 extends VLayout | 49 extends VLayout |
49 { | 50 { |
50 protected MetaDataServiceAsync metaDataService = | 51 protected MetaDataServiceAsync metaDataService = |
51 GWT.create(MetaDataService.class); | 52 GWT.create(MetaDataService.class); |
72 | 73 |
73 public DatacageWidget(Artifact artifact, User user) { | 74 public DatacageWidget(Artifact artifact, User user) { |
74 this(artifact, user, null); | 75 this(artifact, user, null); |
75 } | 76 } |
76 | 77 |
77 | |
78 public DatacageWidget(Artifact artifact, User user, String outs) { | 78 public DatacageWidget(Artifact artifact, User user, String outs) { |
79 this(artifact, user, outs, true); | |
80 } | |
81 | |
82 public DatacageWidget(Artifact artifact, User user, String outs, | |
83 boolean showButton) { | |
79 this(); | 84 this(); |
80 | 85 |
81 this.artifact = artifact; | 86 this.artifact = artifact; |
82 this.user = user; | 87 this.user = user; |
83 this.outs = outs; | 88 this.outs = outs; |
105 } | 110 } |
106 }); | 111 }); |
107 | 112 |
108 addMember(treeGrid); | 113 addMember(treeGrid); |
109 | 114 |
115 if (showButton) { | |
116 addMember(createPlusButton()); | |
117 } | |
118 | |
119 triggerTreeBuilding(); | |
120 } | |
121 | |
122 | |
123 /** | |
124 * @param handler Handler to be added (notified on add-action). | |
125 */ | |
126 public DatacageWidget(Artifact artifact, User user, String outs, | |
127 DatacageHandler handler) { | |
128 this(artifact, user, outs); | |
129 this.addDatacageHandler(handler); | |
130 } | |
131 | |
132 | |
133 /** | |
134 * @param handler Handler to be added (notified on add-action). | |
135 */ | |
136 public void addDatacageHandler(DatacageHandler handler) { | |
137 if (!handlers.contains(handler)) { | |
138 handlers.add(handler); | |
139 } | |
140 } | |
141 | |
142 | |
143 /** | |
144 * @param handler Handler to remove from list. | |
145 */ | |
146 public void removeDatacageHandler(DatacageHandler handler) { | |
147 handlers.remove(handler); | |
148 } | |
149 | |
150 | |
151 public ToLoad getToLoad() { | |
152 return toLoad; | |
153 } | |
154 | |
155 | |
156 public ToLoad getSelection() { | |
157 // Reset content of toLoads. | |
158 toLoad = new ToLoad(); | |
159 | |
160 if (treeGrid == null) { | |
161 return toLoad; | |
162 } | |
163 | |
164 ListGridRecord [] selection = treeGrid.getSelection(); | |
165 | |
166 if (selection != null) { | |
167 for (ListGridRecord record: selection) { | |
168 if (record instanceof TreeNode) { | |
169 collectToLoads((TreeNode)record); | |
170 } | |
171 } | |
172 } | |
173 | |
174 return toLoad; | |
175 } | |
176 | |
177 | |
178 /** | |
179 * Callback for add-button. | |
180 * Fires to load for every selected element and handler. | |
181 */ | |
182 public void plusClicked() { | |
183 if (!getSelection().isEmpty()) { | |
184 fireToLoad(); | |
185 } | |
186 } | |
187 | |
188 | |
189 protected Button createPlusButton() { | |
110 // TODO: i18n + icon | 190 // TODO: i18n + icon |
111 Button plusBtn = new Button("+"); | 191 Button plusBtn = new Button("+"); |
112 plusBtn.addClickHandler(new ClickHandler() { | 192 plusBtn.addClickHandler(new ClickHandler() { |
113 @Override | 193 @Override |
114 public void onClick(ClickEvent event) { | 194 public void onClick(ClickEvent event) { |
115 plusClicked(); | 195 plusClicked(); |
116 } | 196 } |
117 }); | 197 }); |
118 | 198 return plusBtn; |
119 addMember(plusBtn); | 199 } |
120 | 200 |
121 triggerTreeBuilding(); | |
122 } | |
123 | |
124 public void addDatacageHandler(DatacageHandler handler) { | |
125 if (!handlers.contains(handler)) { | |
126 handlers.add(handler); | |
127 } | |
128 } | |
129 | |
130 public void removeDatacageHandler(DatacageHandler handler) { | |
131 handlers.remove(handler); | |
132 } | |
133 | |
134 public ToLoad getToLoad() { | |
135 return toLoad; | |
136 } | |
137 | |
138 public void plusClicked() { | |
139 if (treeGrid == null) { | |
140 return; | |
141 } | |
142 | |
143 ListGridRecord [] selection = treeGrid.getSelection(); | |
144 | |
145 if (selection != null) { | |
146 for (ListGridRecord record: selection) { | |
147 if (record instanceof TreeNode) { | |
148 collectToLoads((TreeNode)record); | |
149 } | |
150 } | |
151 } | |
152 | |
153 if (!toLoad.isEmpty()) { | |
154 fireToLoad(); | |
155 } | |
156 } | |
157 | 201 |
158 protected void fireToLoad() { | 202 protected void fireToLoad() { |
159 for (DatacageHandler handler: handlers) { | 203 for (DatacageHandler handler: handlers) { |
160 handler.toLoad(toLoad); | 204 handler.toLoad(toLoad); |
161 } | 205 } |
162 } | 206 } |
163 | 207 |
208 | |
164 protected void doubleClickedOnTree(RecordDoubleClickEvent event) { | 209 protected void doubleClickedOnTree(RecordDoubleClickEvent event) { |
165 | 210 |
166 TreeNode node = (TreeNode)event.getRecord(); | 211 TreeNode node = (TreeNode)event.getRecord(); |
167 collectToLoads(node); | 212 collectToLoads(node); |
168 destroy(); | 213 destroy(); |
169 } | 214 } |
215 | |
170 | 216 |
171 protected void collectToLoads(TreeNode node) { | 217 protected void collectToLoads(TreeNode node) { |
172 Stack<TreeNode> stack = new Stack<TreeNode>(); | 218 Stack<TreeNode> stack = new Stack<TreeNode>(); |
173 | 219 |
174 stack.push(node); | 220 stack.push(node); |