|
@@ -1,12 +1,9 @@ |
1 |
1 |
|
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
2 |
|
package org.litesoft.GWT.client.widgets; |
3 |
3 |
|
|
4 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
5 |
|
- |
|
6 |
|
- |
import java.util.*; |
7 |
|
- |
|
8 |
4 |
|
import org.litesoft.GWT.client.*; |
9 |
5 |
|
import org.litesoft.GWT.client.widgets.nonpublic.*; |
|
6 |
+ |
import org.litesoft.commonfoundation.typeutils.*; |
10 |
7 |
|
import org.litesoft.commonfoundation.typeutils.Objects; |
11 |
8 |
|
import org.litesoft.core.util.*; |
12 |
9 |
|
|
|
@@ -15,8 +12,9 @@ |
15 |
12 |
|
import com.google.gwt.resources.client.*; |
16 |
13 |
|
import com.google.gwt.user.client.ui.*; |
17 |
14 |
|
|
18 |
|
- |
public class SizeableTree extends AbstractSizeableComposite implements TreeNode |
19 |
|
- |
{ |
|
15 |
+ |
import java.util.*; |
|
16 |
+ |
|
|
17 |
+ |
public class SizeableTree extends AbstractSizeableComposite implements TreeNode { |
20 |
18 |
|
public static final String FOLDER_OPEN_URL = "common/images/misc/folder_open_16x16.gif"; |
21 |
19 |
|
public static final String FOLDER_CLOSED_URL = "common/images/misc/folder_closed_16x16.gif"; |
22 |
20 |
|
public static final String FOLDER_LEAF_URL = "common/images/misc/TransparentSpacer_16x16.gif"; |
|
@@ -24,63 +22,55 @@ |
24 |
22 |
|
protected final Tree mTree; |
25 |
23 |
|
protected SizeableScrollPanel mScrollPanel; |
26 |
24 |
|
|
27 |
|
- |
private SizeableTree( Tree pTree ) |
28 |
|
- |
{ |
|
25 |
+ |
private SizeableTree( Tree pTree ) { |
29 |
26 |
|
mTree = pTree; |
30 |
27 |
|
initWidget( mScrollPanel = new SizeableScrollPanel( mTree ) ); |
31 |
28 |
|
LLstretchable(); |
32 |
|
- |
mTree.addSelectionHandler( new SelectionHandler<TreeItem>() |
33 |
|
- |
{ |
34 |
|
- |
@Override public void onSelection( SelectionEvent<TreeItem> event ) |
35 |
|
- |
{ |
|
29 |
+ |
mTree.addSelectionHandler( new SelectionHandler<TreeItem>() { |
|
30 |
+ |
@Override |
|
31 |
+ |
public void onSelection( SelectionEvent<TreeItem> event ) { |
36 |
32 |
|
notifySelectionChange(); |
37 |
33 |
|
} |
38 |
34 |
|
} ); |
39 |
|
- |
mTree.addOpenHandler( new OpenHandler<TreeItem>() |
40 |
|
- |
{ |
41 |
|
- |
@Override public void onOpen( OpenEvent<TreeItem> event ) |
42 |
|
- |
{ |
|
35 |
+ |
mTree.addOpenHandler( new OpenHandler<TreeItem>() { |
|
36 |
+ |
@Override |
|
37 |
+ |
public void onOpen( OpenEvent<TreeItem> event ) { |
43 |
38 |
|
notifyOpenCloseChange( true ); |
44 |
39 |
|
} |
45 |
40 |
|
} ); |
46 |
|
- |
mTree.addCloseHandler( new CloseHandler<TreeItem>() |
47 |
|
- |
{ |
48 |
|
- |
@Override public void onClose( CloseEvent<TreeItem> event ) |
49 |
|
- |
{ |
|
41 |
+ |
mTree.addCloseHandler( new CloseHandler<TreeItem>() { |
|
42 |
+ |
@Override |
|
43 |
+ |
public void onClose( CloseEvent<TreeItem> event ) { |
50 |
44 |
|
notifyOpenCloseChange( false ); |
51 |
45 |
|
} |
52 |
46 |
|
} ); |
53 |
47 |
|
} |
54 |
48 |
|
|
55 |
|
- |
public SizeableTree() |
56 |
|
- |
{ |
|
49 |
+ |
public SizeableTree() { |
57 |
50 |
|
this( new Tree() ); |
58 |
51 |
|
} |
59 |
52 |
|
|
60 |
53 |
|
public SizeableTree( String pOpenImageURL, int pOpenWidth, int pOpenHeight, // |
61 |
54 |
|
String pClosedImageURL, int pClosedWidth, int pClosedHeight, // |
62 |
55 |
|
String pLeafImageURL, int pLeafWidth, int pLeafHeight, // |
63 |
|
- |
boolean pUseLeafImage ) |
64 |
|
- |
{ |
65 |
|
- |
this( new Tree( new TreeImageAdaptor( pOpenImageURL, pOpenWidth, pOpenHeight, pClosedImageURL, pClosedWidth, pClosedHeight, pLeafImageURL, pLeafWidth, pLeafHeight ), pUseLeafImage ) ); |
|
56 |
+ |
boolean pUseLeafImage ) { |
|
57 |
+ |
this( new Tree( new TreeImageAdaptor( pOpenImageURL, pOpenWidth, pOpenHeight, pClosedImageURL, pClosedWidth, pClosedHeight, pLeafImageURL, pLeafWidth, |
|
58 |
+ |
pLeafHeight ), pUseLeafImage ) ); |
66 |
59 |
|
} |
67 |
60 |
|
|
68 |
|
- |
public static SizeableTree withFolders() |
69 |
|
- |
{ |
|
61 |
+ |
public static SizeableTree withFolders() { |
70 |
62 |
|
return new SizeableTree( FOLDER_OPEN_URL, 16, 16,// |
71 |
63 |
|
FOLDER_CLOSED_URL, 16, 16, // |
72 |
64 |
|
FOLDER_LEAF_URL, 16, 16, // |
73 |
65 |
|
false ); |
74 |
66 |
|
} |
75 |
67 |
|
|
76 |
|
- |
public SizeableTree style( String pStyleName ) |
77 |
|
- |
{ |
|
68 |
+ |
public SizeableTree style( String pStyleName ) { |
78 |
69 |
|
mTree.addStyleName( pStyleName ); |
79 |
70 |
|
return this; |
80 |
71 |
|
} |
81 |
72 |
|
|
82 |
|
- |
public boolean isEmpty() |
83 |
|
- |
{ |
|
73 |
+ |
public boolean isEmpty() { |
84 |
74 |
|
return (0 == mTree.getItemCount()); |
85 |
75 |
|
} |
86 |
76 |
|
|
|
@@ -89,8 +79,7 @@ |
89 |
79 |
|
* |
90 |
80 |
|
* @return Selected Node or null if none Selected |
91 |
81 |
|
*/ |
92 |
|
- |
public TreeNode getSelectedNode() |
93 |
|
- |
{ |
|
82 |
+ |
public TreeNode getSelectedNode() { |
94 |
83 |
|
return (TreeNode) mTree.getSelectedItem(); |
95 |
84 |
|
} |
96 |
85 |
|
|
|
@@ -99,8 +88,7 @@ |
99 |
88 |
|
* |
100 |
89 |
|
* @return UserObject for the currently selected "row" |
101 |
90 |
|
*/ |
102 |
|
- |
public Object getSelected() |
103 |
|
- |
{ |
|
91 |
+ |
public Object getSelected() { |
104 |
92 |
|
TreeNode zNode = getSelectedNode(); |
105 |
93 |
|
return (zNode != null) ? zNode.getUserObject() : null; |
106 |
94 |
|
} |
|
@@ -112,11 +100,9 @@ |
112 |
100 |
|
* |
113 |
101 |
|
* @return pUserObject or null if it was not found! |
114 |
102 |
|
*/ |
115 |
|
- |
public Object setSelected( Object pUserObject ) |
116 |
|
- |
{ |
|
103 |
+ |
public Object setSelected( Object pUserObject ) { |
117 |
104 |
|
MyTreeNode tn = getTreeNode( pUserObject ); |
118 |
|
- |
if ( tn != null ) |
119 |
|
- |
{ |
|
105 |
+ |
if ( tn != null ) { |
120 |
106 |
|
tn.setSelected( true ); |
121 |
107 |
|
return pUserObject; |
122 |
108 |
|
} |
|
@@ -129,8 +115,7 @@ |
129 |
115 |
|
* |
130 |
116 |
|
* @return null if no current selected, otherwise the open state of the currently selected node |
131 |
117 |
|
*/ |
132 |
|
- |
public Boolean isSelectedOpen() |
133 |
|
- |
{ |
|
118 |
+ |
public Boolean isSelectedOpen() { |
134 |
119 |
|
TreeNode tn = getSelectedNode(); |
135 |
120 |
|
return (tn == null) ? null : tn.areAnyOpen(); |
136 |
121 |
|
} |
|
@@ -140,26 +125,21 @@ |
140 |
125 |
|
* |
141 |
126 |
|
* @param pUserObject the item whose visibility is to be ensured |
142 |
127 |
|
*/ |
143 |
|
- |
public void ensureVisible( Object pUserObject ) |
144 |
|
- |
{ |
|
128 |
+ |
public void ensureVisible( Object pUserObject ) { |
145 |
129 |
|
MyTreeNode tn = getTreeNode( pUserObject ); |
146 |
|
- |
if ( tn != null ) |
147 |
|
- |
{ |
|
130 |
+ |
if ( tn != null ) { |
148 |
131 |
|
mScrollPanel.ensureVisible( tn ); |
149 |
132 |
|
} |
150 |
133 |
|
} |
151 |
134 |
|
|
152 |
|
- |
public SizeableTree setAnimationEnabled( boolean pEnable ) |
153 |
|
- |
{ |
|
135 |
+ |
public SizeableTree setAnimationEnabled( boolean pEnable ) { |
154 |
136 |
|
mTree.setAnimationEnabled( pEnable ); |
155 |
137 |
|
return this; |
156 |
138 |
|
} |
157 |
139 |
|
|
158 |
140 |
|
@Override |
159 |
|
- |
public TreeNode addChild( Object pUserObject ) |
160 |
|
- |
{ |
161 |
|
- |
if ( pUserObject == null ) |
162 |
|
- |
{ |
|
141 |
+ |
public TreeNode addChild( Object pUserObject ) { |
|
142 |
+ |
if ( pUserObject == null ) { |
163 |
143 |
|
return null; |
164 |
144 |
|
} |
165 |
145 |
|
MyTreeNode tn = createMyTreeNode( pUserObject ); |
|
@@ -170,16 +150,12 @@ |
170 |
150 |
|
} |
171 |
151 |
|
|
172 |
152 |
|
@Override |
173 |
|
- |
public boolean removeChild( Object pUserObject ) |
174 |
|
- |
{ |
175 |
|
- |
if ( pUserObject != null ) |
176 |
|
- |
{ |
|
153 |
+ |
public boolean removeChild( Object pUserObject ) { |
|
154 |
+ |
if ( pUserObject != null ) { |
177 |
155 |
|
int zCount = mTree.getItemCount(); |
178 |
|
- |
for ( int i = 0; i < zCount; i++ ) |
179 |
|
- |
{ |
|
156 |
+ |
for ( int i = 0; i < zCount; i++ ) { |
180 |
157 |
|
TreeItem zItem = mTree.getItem( i ); |
181 |
|
- |
if ( pUserObject == zItem.getUserObject() ) |
182 |
|
- |
{ |
|
158 |
+ |
if ( pUserObject == zItem.getUserObject() ) { |
183 |
159 |
|
return removeWithSelectMangementAndNotification( zItem ); |
184 |
160 |
|
} |
185 |
161 |
|
} |
|
@@ -188,30 +164,24 @@ |
188 |
164 |
|
} |
189 |
165 |
|
|
190 |
166 |
|
@Override |
191 |
|
- |
public boolean removeDescendant( Object pUserObject ) |
192 |
|
- |
{ |
|
167 |
+ |
public boolean removeDescendant( Object pUserObject ) { |
193 |
168 |
|
MyTreeNode tn = getTreeNode( pUserObject ); |
194 |
169 |
|
return (tn != null) && removeWithSelectMangementAndNotification( tn ); |
195 |
170 |
|
} |
196 |
171 |
|
|
197 |
172 |
|
@Override |
198 |
|
- |
public void clear() |
199 |
|
- |
{ |
|
173 |
+ |
public void clear() { |
200 |
174 |
|
mTree.removeItems(); |
201 |
175 |
|
notifyOpenCloseChange( null ); |
202 |
176 |
|
} |
203 |
177 |
|
|
204 |
178 |
|
@Override |
205 |
|
- |
public boolean areAnyOpen() |
206 |
|
- |
{ |
|
179 |
+ |
public boolean areAnyOpen() { |
207 |
180 |
|
int zChildCount = mTree.getItemCount(); // Top Level! |
208 |
|
- |
for ( int i = 0; i < zChildCount; i++ ) |
209 |
|
- |
{ |
|
181 |
+ |
for ( int i = 0; i < zChildCount; i++ ) { |
210 |
182 |
|
TreeItem zItem = mTree.getItem( i ); // Top Level! |
211 |
|
- |
if ( zItem.getChildCount() != 0 ) |
212 |
|
- |
{ |
213 |
|
- |
if ( zItem.getState() ) |
214 |
|
- |
{ |
|
183 |
+ |
if ( zItem.getChildCount() != 0 ) { |
|
184 |
+ |
if ( zItem.getState() ) { |
215 |
185 |
|
return true; |
216 |
186 |
|
} |
217 |
187 |
|
} |
|
@@ -220,16 +190,12 @@ |
220 |
190 |
|
} |
221 |
191 |
|
|
222 |
192 |
|
@Override |
223 |
|
- |
public boolean areAnyClosed() |
224 |
|
- |
{ |
|
193 |
+ |
public boolean areAnyClosed() { |
225 |
194 |
|
int zChildCount = mTree.getItemCount(); // Top Level! |
226 |
|
- |
for ( int i = 0; i < zChildCount; i++ ) |
227 |
|
- |
{ |
|
195 |
+ |
for ( int i = 0; i < zChildCount; i++ ) { |
228 |
196 |
|
TreeItem zItem = mTree.getItem( i ); // Top Level! |
229 |
|
- |
if ( zItem.getChildCount() != 0 ) |
230 |
|
- |
{ |
231 |
|
- |
if ( ((TreeNode) zItem).areAnyClosed() ) |
232 |
|
- |
{ |
|
197 |
+ |
if ( zItem.getChildCount() != 0 ) { |
|
198 |
+ |
if ( ((TreeNode) zItem).areAnyClosed() ) { |
233 |
199 |
|
return true; |
234 |
200 |
|
} |
235 |
201 |
|
} |
|
@@ -238,19 +204,15 @@ |
238 |
204 |
|
} |
239 |
205 |
|
|
240 |
206 |
|
@Override |
241 |
|
- |
public void openAll() |
242 |
|
- |
{ |
243 |
|
- |
if ( childrenUpdateOpenClosedState( true ) ) |
244 |
|
- |
{ |
|
207 |
+ |
public void openAll() { |
|
208 |
+ |
if ( childrenUpdateOpenClosedState( true ) ) { |
245 |
209 |
|
notifyOpenCloseChange( true ); |
246 |
210 |
|
} |
247 |
211 |
|
} |
248 |
212 |
|
|
249 |
213 |
|
@Override |
250 |
|
- |
public void closeAll() |
251 |
|
- |
{ |
252 |
|
- |
if ( childrenUpdateOpenClosedState( false ) ) |
253 |
|
- |
{ |
|
214 |
+ |
public void closeAll() { |
|
215 |
+ |
if ( childrenUpdateOpenClosedState( false ) ) { |
254 |
216 |
|
notifyOpenCloseChange( false ); |
255 |
217 |
|
} |
256 |
218 |
|
} |
|
@@ -261,51 +223,40 @@ |
261 |
223 |
|
* @return null |
262 |
224 |
|
*/ |
263 |
225 |
|
@Override |
264 |
|
- |
public Object getUserObject() |
265 |
|
- |
{ |
|
226 |
+ |
public Object getUserObject() { |
266 |
227 |
|
return null; |
267 |
228 |
|
} |
268 |
229 |
|
|
269 |
230 |
|
/** |
270 |
231 |
|
* @return iterator over Tree's UserObject(s) depth first |
271 |
232 |
|
*/ |
272 |
|
- |
public Iterator<Object> iterator() |
273 |
|
- |
{ |
|
233 |
+ |
public Iterator<Object> iterator() { |
274 |
234 |
|
List<Object> collector = new ArrayList<Object>(); |
275 |
235 |
|
int zCount = mTree.getItemCount(); // Top Level! |
276 |
|
- |
for ( int i = 0; i < zCount; i++ ) |
277 |
|
- |
{ |
|
236 |
+ |
for ( int i = 0; i < zCount; i++ ) { |
278 |
237 |
|
MyTreeNode tn = (MyTreeNode) mTree.getItem( i ); |
279 |
238 |
|
tn.addToDepthFirst( collector ); |
280 |
239 |
|
} |
281 |
240 |
|
return collector.iterator(); |
282 |
241 |
|
} |
283 |
242 |
|
|
284 |
|
- |
public SizeableTree connectOpenCloseButtons( Button pOpenButton, Button pCloseButton ) |
285 |
|
- |
{ |
286 |
|
- |
if ( (pOpenButton != null) || (pCloseButton != null) ) |
287 |
|
- |
{ |
|
243 |
+ |
public SizeableTree connectOpenCloseButtons( Button pOpenButton, Button pCloseButton ) { |
|
244 |
+ |
if ( (pOpenButton != null) || (pCloseButton != null) ) { |
288 |
245 |
|
final OpenCloseAllHelper zHelper = new OpenCloseAllHelper( pOpenButton, pCloseButton ); |
289 |
246 |
|
addTreeSelectionListener( zHelper ); |
290 |
247 |
|
addTreeOpenCloseListener( zHelper ); |
291 |
|
- |
if ( pOpenButton != null ) |
292 |
|
- |
{ |
293 |
|
- |
pOpenButton.addClickHandler( new ClickHandler() |
294 |
|
- |
{ |
|
248 |
+ |
if ( pOpenButton != null ) { |
|
249 |
+ |
pOpenButton.addClickHandler( new ClickHandler() { |
295 |
250 |
|
@Override |
296 |
|
- |
public void onClick( ClickEvent event ) |
297 |
|
- |
{ |
|
251 |
+ |
public void onClick( ClickEvent event ) { |
298 |
252 |
|
zHelper.processOpenAllRequest(); |
299 |
253 |
|
} |
300 |
254 |
|
} ); |
301 |
255 |
|
} |
302 |
|
- |
if ( pCloseButton != null ) |
303 |
|
- |
{ |
304 |
|
- |
pCloseButton.addClickHandler( new ClickHandler() |
305 |
|
- |
{ |
|
256 |
+ |
if ( pCloseButton != null ) { |
|
257 |
+ |
pCloseButton.addClickHandler( new ClickHandler() { |
306 |
258 |
|
@Override |
307 |
|
- |
public void onClick( ClickEvent event ) |
308 |
|
- |
{ |
|
259 |
+ |
public void onClick( ClickEvent event ) { |
309 |
260 |
|
zHelper.processCloseAllRequest(); |
310 |
261 |
|
} |
311 |
262 |
|
} ); |
|
@@ -314,27 +265,20 @@ |
314 |
265 |
|
return this; |
315 |
266 |
|
} |
316 |
267 |
|
|
317 |
|
- |
public void addTreeSelectionListener( TreeSelectionListener pListener ) |
318 |
|
- |
{ |
319 |
|
- |
if ( pListener != null ) |
320 |
|
- |
{ |
321 |
|
- |
if ( mSelectionListeners == null ) |
322 |
|
- |
{ |
|
268 |
+ |
public void addTreeSelectionListener( TreeSelectionListener pListener ) { |
|
269 |
+ |
if ( pListener != null ) { |
|
270 |
+ |
if ( mSelectionListeners == null ) { |
323 |
271 |
|
mSelectionListeners = new TreeSelectionListenerCollection(); |
324 |
272 |
|
} |
325 |
273 |
|
mSelectionListeners.add( pListener ); |
326 |
274 |
|
} |
327 |
275 |
|
} |
328 |
276 |
|
|
329 |
|
- |
public void removeTreeSelectionListener( TreeSelectionListener pListener ) |
330 |
|
- |
{ |
331 |
|
- |
if ( pListener != null ) |
332 |
|
- |
{ |
333 |
|
- |
if ( mSelectionListeners != null ) |
334 |
|
- |
{ |
|
277 |
+ |
public void removeTreeSelectionListener( TreeSelectionListener pListener ) { |
|
278 |
+ |
if ( pListener != null ) { |
|
279 |
+ |
if ( mSelectionListeners != null ) { |
335 |
280 |
|
mSelectionListeners.remove( pListener ); |
336 |
|
- |
if ( mSelectionListeners.isEmpty() ) |
337 |
|
- |
{ |
|
281 |
+ |
if ( mSelectionListeners.isEmpty() ) { |
338 |
282 |
|
mSelectionListeners = null; |
339 |
283 |
|
} |
340 |
284 |
|
} |
|
@@ -343,35 +287,26 @@ |
343 |
287 |
|
|
344 |
288 |
|
protected TreeSelectionListenerCollection mSelectionListeners = null; |
345 |
289 |
|
|
346 |
|
- |
protected void notifySelectionChange() |
347 |
|
- |
{ |
348 |
|
- |
if ( mSelectionListeners != null ) |
349 |
|
- |
{ |
|
290 |
+ |
protected void notifySelectionChange() { |
|
291 |
+ |
if ( mSelectionListeners != null ) { |
350 |
292 |
|
mSelectionListeners.notify( getSelected() ); |
351 |
293 |
|
} |
352 |
294 |
|
} |
353 |
295 |
|
|
354 |
|
- |
public void addTreeOpenCloseListener( TreeOpenCloseListener pListener ) |
355 |
|
- |
{ |
356 |
|
- |
if ( pListener != null ) |
357 |
|
- |
{ |
358 |
|
- |
if ( mOpenCloseListeners == null ) |
359 |
|
- |
{ |
|
296 |
+ |
public void addTreeOpenCloseListener( TreeOpenCloseListener pListener ) { |
|
297 |
+ |
if ( pListener != null ) { |
|
298 |
+ |
if ( mOpenCloseListeners == null ) { |
360 |
299 |
|
mOpenCloseListeners = new TreeOpenCloseListenerCollection(); |
361 |
300 |
|
} |
362 |
301 |
|
mOpenCloseListeners.add( pListener ); |
363 |
302 |
|
} |
364 |
303 |
|
} |
365 |
304 |
|
|
366 |
|
- |
public void removeTreeOpenCloseListener( TreeOpenCloseListener pListener ) |
367 |
|
- |
{ |
368 |
|
- |
if ( pListener != null ) |
369 |
|
- |
{ |
370 |
|
- |
if ( mOpenCloseListeners != null ) |
371 |
|
- |
{ |
|
305 |
+ |
public void removeTreeOpenCloseListener( TreeOpenCloseListener pListener ) { |
|
306 |
+ |
if ( pListener != null ) { |
|
307 |
+ |
if ( mOpenCloseListeners != null ) { |
372 |
308 |
|
mOpenCloseListeners.remove( pListener ); |
373 |
|
- |
if ( mOpenCloseListeners.isEmpty() ) |
374 |
|
- |
{ |
|
309 |
+ |
if ( mOpenCloseListeners.isEmpty() ) { |
375 |
310 |
|
mOpenCloseListeners = null; |
376 |
311 |
|
} |
377 |
312 |
|
} |
|
@@ -380,36 +315,28 @@ |
380 |
315 |
|
|
381 |
316 |
|
protected TreeOpenCloseListenerCollection mOpenCloseListeners = null; |
382 |
317 |
|
|
383 |
|
- |
protected void notifyOpenCloseChange( Boolean pOpened ) |
384 |
|
- |
{ |
385 |
|
- |
if ( mOpenCloseListeners != null ) |
386 |
|
- |
{ |
|
318 |
+ |
protected void notifyOpenCloseChange( Boolean pOpened ) { |
|
319 |
+ |
if ( mOpenCloseListeners != null ) { |
387 |
320 |
|
mOpenCloseListeners.openStateChanged( pOpened ); |
388 |
321 |
|
} |
389 |
322 |
|
} |
390 |
323 |
|
|
391 |
|
- |
private boolean childrenUpdateOpenClosedState( boolean pOpenAll ) |
392 |
|
- |
{ |
|
324 |
+ |
private boolean childrenUpdateOpenClosedState( boolean pOpenAll ) { |
393 |
325 |
|
boolean changed = false; |
394 |
326 |
|
int zChildCount = mTree.getItemCount(); // Top Level! |
395 |
|
- |
if ( pOpenAll ) |
396 |
|
- |
{ |
|
327 |
+ |
if ( pOpenAll ) { |
397 |
328 |
|
for ( int i = 0; i < zChildCount; i++ ) // Open from the Top Down |
398 |
329 |
|
{ |
399 |
330 |
|
TreeItem zItem = mTree.getItem( i ); // Top Level! |
400 |
|
- |
if ( zItem.getParentItem() == null ) |
401 |
|
- |
{ |
|
331 |
+ |
if ( zItem.getParentItem() == null ) { |
402 |
332 |
|
changed |= updateOpenClosedStateRecursively( zItem, pOpenAll ); |
403 |
333 |
|
} |
404 |
334 |
|
} |
405 |
|
- |
} |
406 |
|
- |
else |
407 |
|
- |
{ |
|
335 |
+ |
} else { |
408 |
336 |
|
for ( int i = zChildCount; 0 <= --i; ) // Close from the Bottom Up |
409 |
337 |
|
{ |
410 |
338 |
|
TreeItem zItem = mTree.getItem( i ); // Top Level! |
411 |
|
- |
if ( zItem.getParentItem() == null ) |
412 |
|
- |
{ |
|
339 |
+ |
if ( zItem.getParentItem() == null ) { |
413 |
340 |
|
changed |= updateOpenClosedStateRecursively( zItem, pOpenAll ); |
414 |
341 |
|
} |
415 |
342 |
|
} |
|
@@ -417,30 +344,23 @@ |
417 |
344 |
|
return changed; |
418 |
345 |
|
} |
419 |
346 |
|
|
420 |
|
- |
private static boolean updateOpenClosedState( TreeItem pTreeItem, boolean pOpen ) |
421 |
|
- |
{ |
422 |
|
- |
if ( (pTreeItem.getState() != pOpen) && (pTreeItem.getChildCount() != 0) ) |
423 |
|
- |
{ |
|
347 |
+ |
private static boolean updateOpenClosedState( TreeItem pTreeItem, boolean pOpen ) { |
|
348 |
+ |
if ( (pTreeItem.getState() != pOpen) && (pTreeItem.getChildCount() != 0) ) { |
424 |
349 |
|
pTreeItem.setState( pOpen ); |
425 |
350 |
|
return true; |
426 |
351 |
|
} |
427 |
352 |
|
return false; |
428 |
353 |
|
} |
429 |
354 |
|
|
430 |
|
- |
private static boolean updateOpenClosedStateRecursively( TreeItem pTreeItem, boolean pOpenAll ) |
431 |
|
- |
{ |
|
355 |
+ |
private static boolean updateOpenClosedStateRecursively( TreeItem pTreeItem, boolean pOpenAll ) { |
432 |
356 |
|
boolean changed = false; |
433 |
357 |
|
int zChildCount = pTreeItem.getChildCount(); |
434 |
|
- |
if ( pOpenAll ) |
435 |
|
- |
{ |
|
358 |
+ |
if ( pOpenAll ) { |
436 |
359 |
|
changed = updateOpenClosedState( pTreeItem, pOpenAll ); // Open from the Top Down |
437 |
|
- |
for ( int i = 0; i < zChildCount; i++ ) |
438 |
|
- |
{ |
|
360 |
+ |
for ( int i = 0; i < zChildCount; i++ ) { |
439 |
361 |
|
changed |= updateOpenClosedStateRecursively( pTreeItem.getChild( i ), pOpenAll ); |
440 |
362 |
|
} |
441 |
|
- |
} |
442 |
|
- |
else |
443 |
|
- |
{ |
|
363 |
+ |
} else { |
444 |
364 |
|
for ( int i = zChildCount; 0 <= --i; ) // Close from the Bottom Up |
445 |
365 |
|
{ |
446 |
366 |
|
changed |= updateOpenClosedStateRecursively( pTreeItem.getChild( i ), pOpenAll ); |
|
@@ -450,16 +370,12 @@ |
450 |
370 |
|
return changed; |
451 |
371 |
|
} |
452 |
372 |
|
|
453 |
|
- |
private MyTreeNode getTreeNode( Object pUserObject ) |
454 |
|
- |
{ |
455 |
|
- |
if ( pUserObject != null ) |
456 |
|
- |
{ |
|
373 |
+ |
private MyTreeNode getTreeNode( Object pUserObject ) { |
|
374 |
+ |
if ( pUserObject != null ) { |
457 |
375 |
|
int zCount = mTree.getItemCount(); // Top Level! |
458 |
|
- |
for ( int i = 0; i < zCount; i++ ) |
459 |
|
- |
{ |
|
376 |
+ |
for ( int i = 0; i < zCount; i++ ) { |
460 |
377 |
|
MyTreeNode tn = (MyTreeNode) mTree.getItem( i ); // Top Level! |
461 |
|
- |
if ( null != (tn = tn.getTreeNode( pUserObject )) ) |
462 |
|
- |
{ |
|
378 |
+ |
if ( null != (tn = tn.getTreeNode( pUserObject )) ) { |
463 |
379 |
|
return tn; |
464 |
380 |
|
} |
465 |
381 |
|
} |
|
@@ -467,8 +383,7 @@ |
467 |
383 |
|
return null; |
468 |
384 |
|
} |
469 |
385 |
|
|
470 |
|
- |
private boolean removeWithSelectMangementAndNotification( TreeItem pTreeItem ) |
471 |
|
- |
{ |
|
386 |
+ |
private boolean removeWithSelectMangementAndNotification( TreeItem pTreeItem ) { |
472 |
387 |
|
Object currentlySelected = getSelected(); |
473 |
388 |
|
|
474 |
389 |
|
removeWithoutSelectMangementAndNotification( pTreeItem ); |
|
@@ -477,46 +392,32 @@ |
477 |
392 |
|
return true; |
478 |
393 |
|
} |
479 |
394 |
|
|
480 |
|
- |
private void restoreSelection( Object pPreviouslySelected ) |
481 |
|
- |
{ |
|
395 |
+ |
private void restoreSelection( Object pPreviouslySelected ) { |
482 |
396 |
|
Object restoredSelected = setSelected( pPreviouslySelected ); |
483 |
|
- |
if ( restoredSelected != pPreviouslySelected ) |
484 |
|
- |
{ |
|
397 |
+ |
if ( restoredSelected != pPreviouslySelected ) { |
485 |
398 |
|
notifySelectionChange(); |
486 |
399 |
|
} |
487 |
400 |
|
notifyOpenCloseChange( null ); |
488 |
401 |
|
} |
489 |
402 |
|
|
490 |
|
- |
private void removeWithoutSelectMangementAndNotification( TreeItem pTreeItem ) |
491 |
|
- |
{ |
|
403 |
+ |
private void removeWithoutSelectMangementAndNotification( TreeItem pTreeItem ) { |
492 |
404 |
|
TreeItem zParentItem = pTreeItem.getParentItem(); |
493 |
|
- |
if ( zParentItem == null ) |
494 |
|
- |
{ |
|
405 |
+ |
if ( zParentItem == null ) { |
495 |
406 |
|
mTree.removeItem( pTreeItem ); |
496 |
|
- |
} |
497 |
|
- |
else |
498 |
|
- |
{ |
|
407 |
+ |
} else { |
499 |
408 |
|
zParentItem.removeItem( pTreeItem ); |
500 |
409 |
|
} |
501 |
410 |
|
} |
502 |
411 |
|
|
503 |
|
- |
private HierarchicalNode.ChangeListener<HierarchicalNode> getChangeListener() |
504 |
|
- |
{ |
505 |
|
- |
if ( mChangeListener == null ) |
506 |
|
- |
{ |
507 |
|
- |
mChangeListener = new HierarchicalNode.ChangeListener<HierarchicalNode>() |
508 |
|
- |
{ |
|
412 |
+ |
private HierarchicalNode.ChangeListener<HierarchicalNode> getChangeListener() { |
|
413 |
+ |
if ( mChangeListener == null ) { |
|
414 |
+ |
mChangeListener = new HierarchicalNode.ChangeListener<HierarchicalNode>() { |
509 |
415 |
|
@Override |
510 |
|
- |
public void change( HierarchicalNode pNode, HierarchicalNode.Change pChange ) |
511 |
|
- |
{ |
512 |
|
- |
if ( (pNode != null) && (pChange != null) ) |
513 |
|
- |
{ |
514 |
|
- |
if ( HierarchicalNode.Change.Deleted == pChange ) |
515 |
|
- |
{ |
|
416 |
+ |
public void change( HierarchicalNode pNode, HierarchicalNode.Change pChange ) { |
|
417 |
+ |
if ( (pNode != null) && (pChange != null) ) { |
|
418 |
+ |
if ( HierarchicalNode.Change.Deleted == pChange ) { |
516 |
419 |
|
removeChild( pNode ); |
517 |
|
- |
} |
518 |
|
- |
else |
519 |
|
- |
{ |
|
420 |
+ |
} else { |
520 |
421 |
|
updateChildren( pNode ); |
521 |
422 |
|
} |
522 |
423 |
|
} |
|
@@ -528,83 +429,65 @@ |
528 |
429 |
|
|
529 |
430 |
|
private HierarchicalNode.ChangeListener<HierarchicalNode> mChangeListener; |
530 |
431 |
|
|
531 |
|
- |
private static class TreeImageAdaptor implements Tree.Resources |
532 |
|
- |
{ |
|
432 |
+ |
private static class TreeImageAdaptor implements Tree.Resources { |
533 |
433 |
|
private ImageResource mOpen, mClosed, mLeaf; |
534 |
434 |
|
|
535 |
435 |
|
private TreeImageAdaptor( String pOpenImageURL, int pOpenWidth, int pOpenHeight, // |
536 |
436 |
|
String pClosedImageURL, int pClosedWidth, int pClosedHeight, // |
537 |
|
- |
String pLeafImageURL, int pLeafWidth, int pLeafHeight ) |
538 |
|
- |
{ |
|
437 |
+ |
String pLeafImageURL, int pLeafWidth, int pLeafHeight ) { |
539 |
438 |
|
mOpen = new ImageResourceAdapter( "Open", pOpenImageURL, pOpenWidth, pOpenHeight ); |
540 |
439 |
|
mClosed = new ImageResourceAdapter( "Closed", pClosedImageURL, pClosedWidth, pClosedHeight ); |
541 |
440 |
|
mLeaf = new ImageResourceAdapter( "Leaf", pLeafImageURL, pLeafWidth, pLeafHeight ); |
542 |
441 |
|
} |
543 |
442 |
|
|
544 |
443 |
|
@Override |
545 |
|
- |
public ImageResource treeOpen() |
546 |
|
- |
{ |
|
444 |
+ |
public ImageResource treeOpen() { |
547 |
445 |
|
return mOpen; |
548 |
446 |
|
} |
549 |
447 |
|
|
550 |
448 |
|
@Override |
551 |
|
- |
public ImageResource treeClosed() |
552 |
|
- |
{ |
|
449 |
+ |
public ImageResource treeClosed() { |
553 |
450 |
|
return mClosed; |
554 |
451 |
|
} |
555 |
452 |
|
|
556 |
453 |
|
@Override |
557 |
|
- |
public ImageResource treeLeaf() |
558 |
|
- |
{ |
|
454 |
+ |
public ImageResource treeLeaf() { |
559 |
455 |
|
return mLeaf; |
560 |
456 |
|
} |
561 |
457 |
|
} |
562 |
458 |
|
|
563 |
|
- |
private MyTreeNode createMyTreeNode( Object pUserObject ) |
564 |
|
- |
{ |
|
459 |
+ |
private MyTreeNode createMyTreeNode( Object pUserObject ) { |
565 |
460 |
|
MyTreeNode tn; |
566 |
|
- |
if ( pUserObject instanceof HasWidget ) |
567 |
|
- |
{ |
|
461 |
+ |
if ( pUserObject instanceof HasWidget ) { |
568 |
462 |
|
tn = new MyTreeNode( ((HasWidget) pUserObject).getWidget(), pUserObject ); |
569 |
|
- |
} |
570 |
|
- |
else if ( pUserObject instanceof Widget ) |
571 |
|
- |
{ |
|
463 |
+ |
} else if ( pUserObject instanceof Widget ) { |
572 |
464 |
|
tn = new MyTreeNode( (Widget) pUserObject, pUserObject ); |
573 |
|
- |
} |
574 |
|
- |
else |
575 |
|
- |
{ |
|
465 |
+ |
} else { |
576 |
466 |
|
tn = new MyTreeNode( new Label( pUserObject.toString() ), pUserObject ); |
577 |
467 |
|
} |
578 |
|
- |
if ( pUserObject instanceof HierarchicalNode ) |
579 |
|
- |
{ |
|
468 |
+ |
if ( pUserObject instanceof HierarchicalNode ) { |
580 |
469 |
|
//noinspection unchecked |
581 |
470 |
|
((HierarchicalNode) pUserObject).addChangeListener( getChangeListener() ); |
582 |
471 |
|
} |
583 |
472 |
|
return tn; |
584 |
473 |
|
} |
585 |
474 |
|
|
586 |
|
- |
private class MyTreeNode extends TreeItem implements TreeNode |
587 |
|
- |
{ |
588 |
|
- |
private MyTreeNode( Widget pWidget, Object pUserObject ) |
589 |
|
- |
{ |
|
475 |
+ |
private class MyTreeNode extends TreeItem implements TreeNode { |
|
476 |
+ |
private MyTreeNode( Widget pWidget, Object pUserObject ) { |
590 |
477 |
|
super( pWidget ); |
591 |
478 |
|
setUserObject( pUserObject ); |
592 |
479 |
|
} |
593 |
480 |
|
|
594 |
|
- |
public void addChildren() |
595 |
|
- |
{ |
|
481 |
+ |
public void addChildren() { |
596 |
482 |
|
Object zUserObject = getUserObject(); |
597 |
|
- |
if ( zUserObject instanceof HierarchicalNode ) |
598 |
|
- |
{ |
|
483 |
+ |
if ( zUserObject instanceof HierarchicalNode ) { |
599 |
484 |
|
addChildren( getChildren( (HierarchicalNode) zUserObject ) ); |
600 |
485 |
|
} |
601 |
486 |
|
} |
602 |
487 |
|
|
603 |
488 |
|
@Override |
604 |
|
- |
public MyTreeNode addChild( Object pUserObject ) |
605 |
|
- |
{ |
606 |
|
- |
if ( pUserObject == null ) |
607 |
|
- |
{ |
|
489 |
+ |
public MyTreeNode addChild( Object pUserObject ) { |
|
490 |
+ |
if ( pUserObject == null ) { |
608 |
491 |
|
return null; |
609 |
492 |
|
} |
610 |
493 |
|
MyTreeNode tn = createMyTreeNode( pUserObject ); |
|
@@ -615,18 +498,13 @@ |
615 |
498 |
|
} |
616 |
499 |
|
|
617 |
500 |
|
@Override |
618 |
|
- |
public boolean removeChild( Object pUserObject ) |
619 |
|
- |
{ |
620 |
|
- |
if ( pUserObject != null ) |
621 |
|
- |
{ |
|
501 |
+ |
public boolean removeChild( Object pUserObject ) { |
|
502 |
+ |
if ( pUserObject != null ) { |
622 |
503 |
|
int zCount = getChildCount(); |
623 |
|
- |
if ( zCount != 0 ) |
624 |
|
- |
{ |
625 |
|
- |
for ( int i = 0; i < zCount; i++ ) |
626 |
|
- |
{ |
|
504 |
+ |
if ( zCount != 0 ) { |
|
505 |
+ |
for ( int i = 0; i < zCount; i++ ) { |
627 |
506 |
|
TreeItem zItem = getChild( i ); |
628 |
|
- |
if ( (zItem != null) && (pUserObject == zItem.getUserObject()) ) |
629 |
|
- |
{ |
|
507 |
+ |
if ( (zItem != null) && (pUserObject == zItem.getUserObject()) ) { |
630 |
508 |
|
return removeWithSelectMangementAndNotification( zItem ); |
631 |
509 |
|
} |
632 |
510 |
|
} |
|
@@ -636,22 +514,16 @@ |
636 |
514 |
|
} |
637 |
515 |
|
|
638 |
516 |
|
@Override |
639 |
|
- |
public boolean removeDescendant( Object pUserObject ) |
640 |
|
- |
{ |
641 |
|
- |
if ( pUserObject != null ) |
642 |
|
- |
{ |
|
517 |
+ |
public boolean removeDescendant( Object pUserObject ) { |
|
518 |
+ |
if ( pUserObject != null ) { |
643 |
519 |
|
int zCount = getChildCount(); |
644 |
|
- |
if ( zCount != 0 ) |
645 |
|
- |
{ |
646 |
|
- |
for ( int i = 0; i < zCount; i++ ) |
647 |
|
- |
{ |
|
520 |
+ |
if ( zCount != 0 ) { |
|
521 |
+ |
for ( int i = 0; i < zCount; i++ ) { |
648 |
522 |
|
MyTreeNode tn = (MyTreeNode) getChild( i ); |
649 |
|
- |
if ( pUserObject == tn.getUserObject() ) |
650 |
|
- |
{ |
|
523 |
+ |
if ( pUserObject == tn.getUserObject() ) { |
651 |
524 |
|
return removeWithSelectMangementAndNotification( tn ); |
652 |
525 |
|
} |
653 |
|
- |
if ( tn.removeDescendant( pUserObject ) ) |
654 |
|
- |
{ |
|
526 |
+ |
if ( tn.removeDescendant( pUserObject ) ) { |
655 |
527 |
|
return true; |
656 |
528 |
|
} |
657 |
529 |
|
} |
|
@@ -661,103 +533,81 @@ |
661 |
533 |
|
} |
662 |
534 |
|
|
663 |
535 |
|
@Override |
664 |
|
- |
public void clear() |
665 |
|
- |
{ |
|
536 |
+ |
public void clear() { |
666 |
537 |
|
removeItems(); |
667 |
538 |
|
notifyOpenCloseChange( null ); |
668 |
539 |
|
} |
669 |
540 |
|
|
670 |
541 |
|
@Override |
671 |
|
- |
public boolean areAnyOpen() |
672 |
|
- |
{ |
|
542 |
+ |
public boolean areAnyOpen() { |
673 |
543 |
|
return parentsOpen() && (getChildCount() != 0) && getState(); |
674 |
544 |
|
} |
675 |
545 |
|
|
676 |
546 |
|
@Override |
677 |
|
- |
public boolean areAnyClosed() |
678 |
|
- |
{ |
|
547 |
+ |
public boolean areAnyClosed() { |
679 |
548 |
|
return parentsOpen() && LLareAnyClosed(); |
680 |
549 |
|
} |
681 |
550 |
|
|
682 |
551 |
|
@Override |
683 |
|
- |
public void openAll() |
684 |
|
- |
{ |
685 |
|
- |
if ( updateOpenClosedStateRecursively( this, true ) ) |
686 |
|
- |
{ |
|
552 |
+ |
public void openAll() { |
|
553 |
+ |
if ( updateOpenClosedStateRecursively( this, true ) ) { |
687 |
554 |
|
notifyOpenCloseChange( true ); |
688 |
555 |
|
} |
689 |
556 |
|
} |
690 |
557 |
|
|
691 |
558 |
|
@Override |
692 |
|
- |
public void closeAll() |
693 |
|
- |
{ |
694 |
|
- |
if ( updateOpenClosedStateRecursively( this, false ) ) |
695 |
|
- |
{ |
|
559 |
+ |
public void closeAll() { |
|
560 |
+ |
if ( updateOpenClosedStateRecursively( this, false ) ) { |
696 |
561 |
|
notifyOpenCloseChange( false ); |
697 |
562 |
|
} |
698 |
563 |
|
} |
699 |
564 |
|
|
700 |
|
- |
private boolean areAnyChildrenClosed() |
701 |
|
- |
{ |
702 |
|
- |
for ( int i = getChildCount(); 0 <= --i; ) |
703 |
|
- |
{ |
704 |
|
- |
if ( ((MyTreeNode) getChild( i )).LLareAnyClosed() ) |
705 |
|
- |
{ |
|
565 |
+ |
private boolean areAnyChildrenClosed() { |
|
566 |
+ |
for ( int i = getChildCount(); 0 <= --i; ) { |
|
567 |
+ |
if ( ((MyTreeNode) getChild( i )).LLareAnyClosed() ) { |
706 |
568 |
|
return true; |
707 |
569 |
|
} |
708 |
570 |
|
} |
709 |
571 |
|
return false; |
710 |
572 |
|
} |
711 |
573 |
|
|
712 |
|
- |
private boolean LLareAnyClosed() |
713 |
|
- |
{ |
|
574 |
+ |
private boolean LLareAnyClosed() { |
714 |
575 |
|
return (getChildCount() != 0) && (!getState() || areAnyChildrenClosed()); |
715 |
576 |
|
} |
716 |
577 |
|
|
717 |
|
- |
private boolean parentsOpen() |
718 |
|
- |
{ |
|
578 |
+ |
private boolean parentsOpen() { |
719 |
579 |
|
MyTreeNode zParent = (MyTreeNode) getParentItem(); |
720 |
580 |
|
return (zParent == null) || (zParent.getState() && zParent.parentsOpen()); |
721 |
581 |
|
} |
722 |
582 |
|
|
723 |
|
- |
private void addChildren( List<HierarchicalNode> pChildUserObjects ) |
724 |
|
- |
{ |
725 |
|
- |
if ( pChildUserObjects != null ) |
726 |
|
- |
{ |
727 |
|
- |
for ( HierarchicalNode zUserObject : pChildUserObjects ) |
728 |
|
- |
{ |
|
583 |
+ |
private void addChildren( List<HierarchicalNode> pChildUserObjects ) { |
|
584 |
+ |
if ( pChildUserObjects != null ) { |
|
585 |
+ |
for ( HierarchicalNode zUserObject : pChildUserObjects ) { |
729 |
586 |
|
MyTreeNode tn = addChild( zUserObject ); |
730 |
|
- |
if ( tn != null ) |
731 |
|
- |
{ |
|
587 |
+ |
if ( tn != null ) { |
732 |
588 |
|
tn.addChildren(); |
733 |
589 |
|
} |
734 |
590 |
|
} |
735 |
591 |
|
} |
736 |
592 |
|
} |
737 |
593 |
|
|
738 |
|
- |
public void addToDepthFirst( List<Object> pCollector ) |
739 |
|
- |
{ |
|
594 |
+ |
public void addToDepthFirst( List<Object> pCollector ) { |
740 |
595 |
|
pCollector.add( getUserObject() ); |
741 |
596 |
|
int zCount = getChildCount(); |
742 |
|
- |
for ( int i = 0; i < zCount; i++ ) |
743 |
|
- |
{ |
|
597 |
+ |
for ( int i = 0; i < zCount; i++ ) { |
744 |
598 |
|
MyTreeNode tn = (MyTreeNode) getChild( i ); |
745 |
599 |
|
tn.addToDepthFirst( pCollector ); |
746 |
600 |
|
} |
747 |
601 |
|
} |
748 |
602 |
|
|
749 |
|
- |
public MyTreeNode getTreeNode( Object pUserObject ) |
750 |
|
- |
{ |
751 |
|
- |
if ( pUserObject == getUserObject() ) |
752 |
|
- |
{ |
|
603 |
+ |
public MyTreeNode getTreeNode( Object pUserObject ) { |
|
604 |
+ |
if ( pUserObject == getUserObject() ) { |
753 |
605 |
|
return this; |
754 |
606 |
|
} |
755 |
607 |
|
int zCount = getChildCount(); |
756 |
|
- |
for ( int i = 0; i < zCount; i++ ) |
757 |
|
- |
{ |
|
608 |
+ |
for ( int i = 0; i < zCount; i++ ) { |
758 |
609 |
|
MyTreeNode tn = (MyTreeNode) getChild( i ); |
759 |
|
- |
if ( null != (tn = tn.getTreeNode( pUserObject )) ) |
760 |
|
- |
{ |
|
610 |
+ |
if ( null != (tn = tn.getTreeNode( pUserObject )) ) { |
761 |
611 |
|
return tn; |
762 |
612 |
|
} |
763 |
613 |
|
} |
|
@@ -766,19 +616,15 @@ |
766 |
616 |
|
} |
767 |
617 |
|
|
768 |
618 |
|
@SuppressWarnings({"unchecked"}) |
769 |
|
- |
private static List<HierarchicalNode> getChildren( HierarchicalNode pUserObject ) |
770 |
|
- |
{ |
|
619 |
+ |
private static List<HierarchicalNode> getChildren( HierarchicalNode pUserObject ) { |
771 |
620 |
|
return (List<HierarchicalNode>) pUserObject.getChildren(); |
772 |
621 |
|
} |
773 |
622 |
|
|
774 |
|
- |
protected void updateChildren( HierarchicalNode pNode ) |
775 |
|
- |
{ |
|
623 |
+ |
protected void updateChildren( HierarchicalNode pNode ) { |
776 |
624 |
|
MyTreeNode tn = getTreeNode( pNode ); |
777 |
|
- |
if ( tn != null ) |
778 |
|
- |
{ |
|
625 |
+ |
if ( tn != null ) { |
779 |
626 |
|
List<HierarchicalNode> zChildren = getChildren( pNode ); |
780 |
|
- |
if ( Lists.isNullOrEmpty( zChildren ) ) |
781 |
|
- |
{ |
|
627 |
+ |
if ( Lists.isNullOrEmpty( zChildren ) ) { |
782 |
628 |
|
Object currentlySelected = getSelected(); |
783 |
629 |
|
|
784 |
630 |
|
tn.removeItems(); |
|
@@ -791,51 +637,42 @@ |
791 |
637 |
|
} |
792 |
638 |
|
} |
793 |
639 |
|
|
794 |
|
- |
private class CurrentState |
795 |
|
- |
{ |
|
640 |
+ |
private class CurrentState { |
796 |
641 |
|
private Object mUserObject; |
797 |
642 |
|
private boolean mSelected, mOpen; |
798 |
643 |
|
private List<CurrentState> mChildren = new ArrayList<CurrentState>(); |
799 |
644 |
|
|
800 |
|
- |
public CurrentState( MyTreeNode pTreeNode ) |
801 |
|
- |
{ |
|
645 |
+ |
public CurrentState( MyTreeNode pTreeNode ) { |
802 |
646 |
|
mUserObject = pTreeNode.getUserObject(); |
803 |
647 |
|
mSelected = pTreeNode.isSelected(); |
804 |
648 |
|
mOpen = pTreeNode.getState(); // Open |
805 |
649 |
|
int zChildCount = pTreeNode.getChildCount(); |
806 |
|
- |
for ( int i = 0; i < zChildCount; i++ ) |
807 |
|
- |
{ |
|
650 |
+ |
for ( int i = 0; i < zChildCount; i++ ) { |
808 |
651 |
|
mChildren.add( new CurrentState( (MyTreeNode) pTreeNode.getChild( i ) ) ); |
809 |
652 |
|
} |
810 |
653 |
|
} |
811 |
654 |
|
|
812 |
|
- |
public CurrentState( HierarchicalNode pNew ) |
813 |
|
- |
{ |
|
655 |
+ |
public CurrentState( HierarchicalNode pNew ) { |
814 |
656 |
|
mUserObject = pNew; |
815 |
657 |
|
mSelected = mOpen = false; |
816 |
658 |
|
List<HierarchicalNode> zChildren = getChildren( pNew ); |
817 |
|
- |
if ( zChildren != null ) |
818 |
|
- |
{ |
819 |
|
- |
for ( HierarchicalNode zChild : zChildren ) |
820 |
|
- |
{ |
|
659 |
+ |
if ( zChildren != null ) { |
|
660 |
+ |
for ( HierarchicalNode zChild : zChildren ) { |
821 |
661 |
|
mChildren.add( new CurrentState( zChild ) ); |
822 |
662 |
|
} |
823 |
663 |
|
} |
824 |
664 |
|
} |
825 |
665 |
|
|
826 |
|
- |
private void setStateOn( MyTreeNode pTreeNode ) |
827 |
|
- |
{ |
|
666 |
+ |
private void setStateOn( MyTreeNode pTreeNode ) { |
828 |
667 |
|
pTreeNode.setState( mOpen ); |
829 |
668 |
|
pTreeNode.setSelected( mSelected ); |
830 |
669 |
|
} |
831 |
670 |
|
|
832 |
|
- |
public Object getUserObject() |
833 |
|
- |
{ |
|
671 |
+ |
public Object getUserObject() { |
834 |
672 |
|
return mUserObject; |
835 |
673 |
|
} |
836 |
674 |
|
|
837 |
|
- |
private boolean hasSameUserObject( CurrentState them ) |
838 |
|
- |
{ |
|
675 |
+ |
private boolean hasSameUserObject( CurrentState them ) { |
839 |
676 |
|
return Objects.areEqual( this.getUserObject(), them.getUserObject() ); |
840 |
677 |
|
} |
841 |
678 |
|
|
|
@@ -845,18 +682,14 @@ |
845 |
682 |
|
* @param pNewChildren - |
846 |
683 |
|
* @param pTreeNode - |
847 |
684 |
|
*/ |
848 |
|
- |
public void dropChildrenAndAlignWith( List<HierarchicalNode> pNewChildren, MyTreeNode pTreeNode ) |
849 |
|
- |
{ |
|
685 |
+ |
public void dropChildrenAndAlignWith( List<HierarchicalNode> pNewChildren, MyTreeNode pTreeNode ) { |
850 |
686 |
|
List<CurrentState> zChildren = new ArrayList<CurrentState>( pNewChildren.size() ); |
851 |
|
- |
for ( HierarchicalNode zChild : pNewChildren ) |
852 |
|
- |
{ |
|
687 |
+ |
for ( HierarchicalNode zChild : pNewChildren ) { |
853 |
688 |
|
zChildren.add( new CurrentState( zChild ) ); |
854 |
689 |
|
} |
855 |
|
- |
for ( CurrentState zChild : mChildren ) |
856 |
|
- |
{ |
|
690 |
+ |
for ( CurrentState zChild : mChildren ) { |
857 |
691 |
|
@SuppressWarnings({"SuspiciousMethodCalls"}) int at = pNewChildren.indexOf( zChild.getUserObject() ); |
858 |
|
- |
if ( at != -1 ) |
859 |
|
- |
{ |
|
692 |
+ |
if ( at != -1 ) { |
860 |
693 |
|
zChildren.set( at, zChild ); |
861 |
694 |
|
} |
862 |
695 |
|
} |
|
@@ -864,25 +697,21 @@ |
864 |
697 |
|
Object currentlySelected = getSelected(); |
865 |
698 |
|
// Skip over the front of tree that is common && delete front of tree that is NOT in new Tree! |
866 |
699 |
|
int i = 0; // MyTreeNode Child Index |
867 |
|
- |
while ( !zChildren.isEmpty() && !mChildren.isEmpty() && (i < pTreeNode.getChildCount()) ) |
868 |
|
- |
{ |
|
700 |
+ |
while ( !zChildren.isEmpty() && !mChildren.isEmpty() && (i < pTreeNode.getChildCount()) ) { |
869 |
701 |
|
//noinspection SuspiciousMethodCalls |
870 |
|
- |
if ( !pNewChildren.contains( mChildren.get( 0 ).getUserObject() ) ) |
871 |
|
- |
{ |
|
702 |
+ |
if ( !pNewChildren.contains( mChildren.get( 0 ).getUserObject() ) ) { |
872 |
703 |
|
mChildren.remove( 0 ); |
873 |
704 |
|
removeWithoutSelectMangementAndNotification( pTreeNode.getChild( i ) ); |
874 |
705 |
|
continue; |
875 |
706 |
|
} |
876 |
|
- |
while ( mChildren.get( 0 ).hasSameUserObject( zChildren.get( 0 ) ) ) |
877 |
|
- |
{ |
|
707 |
+ |
while ( mChildren.get( 0 ).hasSameUserObject( zChildren.get( 0 ) ) ) { |
878 |
708 |
|
zChildren.remove( 0 ); |
879 |
709 |
|
mChildren.remove( 0 ); |
880 |
710 |
|
i++; |
881 |
711 |
|
} |
882 |
712 |
|
} |
883 |
713 |
|
mChildren.clear(); |
884 |
|
- |
while ( i < pTreeNode.getChildCount() ) |
885 |
|
- |
{ |
|
714 |
+ |
while ( i < pTreeNode.getChildCount() ) { |
886 |
715 |
|
removeWithoutSelectMangementAndNotification( pTreeNode.getChild( i ) ); |
887 |
716 |
|
} |
888 |
717 |
|
addTo( pTreeNode, zChildren ); |
|
@@ -890,12 +719,9 @@ |
890 |
719 |
|
restoreSelection( currentlySelected ); |
891 |
720 |
|
} |
892 |
721 |
|
|
893 |
|
- |
private void addTo( MyTreeNode pTreeNode, List<CurrentState> zChildren ) |
894 |
|
- |
{ |
895 |
|
- |
if ( zChildren != null ) |
896 |
|
- |
{ |
897 |
|
- |
for ( CurrentState zChild : zChildren ) |
898 |
|
- |
{ |
|
722 |
+ |
private void addTo( MyTreeNode pTreeNode, List<CurrentState> zChildren ) { |
|
723 |
+ |
if ( zChildren != null ) { |
|
724 |
+ |
for ( CurrentState zChild : zChildren ) { |
899 |
725 |
|
MyTreeNode tn = createMyTreeNode( zChild.getUserObject() ); |
900 |
726 |
|
pTreeNode.addItem( tn ); |
901 |
727 |
|
zChild.setStateOn( tn ); |
|
@@ -905,76 +731,62 @@ |
905 |
731 |
|
} |
906 |
732 |
|
} |
907 |
733 |
|
|
908 |
|
- |
private static class NoOpEnableable implements Enableable |
909 |
|
- |
{ |
910 |
|
- |
public static Enableable deNull( Enableable pEnableable ) |
911 |
|
- |
{ |
|
734 |
+ |
private static class NoOpEnableable implements Enableable { |
|
735 |
+ |
public static Enableable deNull( Enableable pEnableable ) { |
912 |
736 |
|
return (pEnableable != null) ? pEnableable : new NoOpEnableable(); |
913 |
737 |
|
} |
914 |
738 |
|
|
915 |
739 |
|
@Override |
916 |
|
- |
public boolean isEnabled() |
917 |
|
- |
{ |
|
740 |
+ |
public boolean isEnabled() { |
918 |
741 |
|
return false; |
919 |
742 |
|
} |
920 |
743 |
|
|
921 |
744 |
|
@Override |
922 |
|
- |
public void setEnabled( boolean pEnabled ) |
923 |
|
- |
{ |
|
745 |
+ |
public void setEnabled( boolean pEnabled ) { |
924 |
746 |
|
} |
925 |
747 |
|
} |
926 |
748 |
|
|
927 |
749 |
|
private class OpenCloseAllHelper implements TreeSelectionListener, |
928 |
|
- |
TreeOpenCloseListener |
929 |
|
- |
{ |
|
750 |
+ |
TreeOpenCloseListener { |
930 |
751 |
|
private Enableable mOpenAll, mCloseAll; |
931 |
752 |
|
|
932 |
|
- |
public OpenCloseAllHelper( Enableable pOpenAll, Enableable pCloseAll ) |
933 |
|
- |
{ |
|
753 |
+ |
public OpenCloseAllHelper( Enableable pOpenAll, Enableable pCloseAll ) { |
934 |
754 |
|
mOpenAll = NoOpEnableable.deNull( pOpenAll ); |
935 |
755 |
|
mCloseAll = NoOpEnableable.deNull( pCloseAll ); |
936 |
756 |
|
update(); |
937 |
757 |
|
} |
938 |
758 |
|
|
939 |
|
- |
private void setAllState( boolean pOpenAllEnabled, boolean pCloseAllEnabled ) |
940 |
|
- |
{ |
|
759 |
+ |
private void setAllState( boolean pOpenAllEnabled, boolean pCloseAllEnabled ) { |
941 |
760 |
|
mOpenAll.setEnabled( pOpenAllEnabled ); |
942 |
761 |
|
mCloseAll.setEnabled( pCloseAllEnabled ); |
943 |
762 |
|
} |
944 |
763 |
|
|
945 |
764 |
|
@Override |
946 |
|
- |
public void openStateChanged( Boolean pOpened ) |
947 |
|
- |
{ |
|
765 |
+ |
public void openStateChanged( Boolean pOpened ) { |
948 |
766 |
|
update(); |
949 |
767 |
|
} |
950 |
768 |
|
|
951 |
769 |
|
@Override |
952 |
|
- |
public void selected( Object pSelected ) |
953 |
|
- |
{ |
|
770 |
+ |
public void selected( Object pSelected ) { |
954 |
771 |
|
update(); |
955 |
772 |
|
} |
956 |
773 |
|
|
957 |
|
- |
private void update() |
958 |
|
- |
{ |
|
774 |
+ |
private void update() { |
959 |
775 |
|
setAllState( areAnyClosed(), areAnyOpen() ); |
960 |
776 |
|
} |
961 |
777 |
|
|
962 |
|
- |
public void processOpenAllRequest() |
963 |
|
- |
{ |
|
778 |
+ |
public void processOpenAllRequest() { |
964 |
779 |
|
TreeNode tn = getSelectedNode(); |
965 |
|
- |
if ( (tn != null) && tn.areAnyClosed() ) |
966 |
|
- |
{ |
|
780 |
+ |
if ( (tn != null) && tn.areAnyClosed() ) { |
967 |
781 |
|
tn.openAll(); |
968 |
782 |
|
return; |
969 |
783 |
|
} |
970 |
784 |
|
openAll(); |
971 |
785 |
|
} |
972 |
786 |
|
|
973 |
|
- |
public void processCloseAllRequest() |
974 |
|
- |
{ |
|
787 |
+ |
public void processCloseAllRequest() { |
975 |
788 |
|
TreeNode tn = getSelectedNode(); |
976 |
|
- |
if ( (tn != null) && tn.areAnyOpen() ) |
977 |
|
- |
{ |
|
789 |
+ |
if ( (tn != null) && tn.areAnyOpen() ) { |
978 |
790 |
|
tn.closeAll(); |
979 |
791 |
|
return; |
980 |
792 |
|
} |