author | Claus Gittinger <cg@exept.de> |
Sat, 13 Jul 2013 23:06:39 +0200 | |
changeset 4275 | 9b7b0a680e70 |
parent 3872 | a35d3ecdb0bb |
child 4941 | bd6fab9e6d8f |
permissions | -rw-r--r-- |
458 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
1818 | 12 |
"{ Package: 'stx:libwidg2' }" |
13 |
||
458 | 14 |
Model subclass:#SelectionInTree |
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
15 |
instanceVariableNames:'root list selection showRoot contentsAction labelAction |
811 | 16 |
childrenAction iconAction indicatorList indicatorTask accessLock' |
458 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
19 |
category:'Interface-Support-Models' |
|
20 |
! |
|
21 |
||
22 |
!SelectionInTree class methodsFor:'documentation'! |
|
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
||
37 |
||
38 |
! |
|
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
list and selection holder for hierarchical list structures. Used |
|
1189 | 43 |
to buildup file-trees, class trees etc. |
458 | 44 |
|
45 |
Especially suited for use with SelectionInTreeView. |
|
46 |
||
1189 | 47 |
Notice: this class replaces SelectionInHierarchy, which provides |
48 |
similar (but less sphisticated) functionality. |
|
49 |
||
458 | 50 |
[See also:] |
51 |
TreeItem |
|
52 |
SelectionInTreeView |
|
53 |
||
54 |
[Author:] |
|
55 |
W. Olberding |
|
56 |
Claus Atzkern |
|
57 |
" |
|
58 |
! ! |
|
59 |
||
811 | 60 |
!SelectionInTree class methodsFor:'instance creation'! |
61 |
||
62 |
new |
|
2840 | 63 |
^ self basicNew initialize |
811 | 64 |
! ! |
65 |
||
1174 | 66 |
!SelectionInTree class methodsFor:'defaults'! |
67 |
||
68 |
defaultItemClass |
|
69 |
"returns the default item class or nil (the default) |
|
70 |
" |
|
71 |
^ nil |
|
72 |
||
73 |
||
74 |
||
75 |
! ! |
|
76 |
||
458 | 77 |
!SelectionInTree methodsFor:'accessing'! |
78 |
||
79 |
list |
|
1189 | 80 |
"get the list of currently shown objects |
458 | 81 |
" |
82 |
^ list |
|
83 |
! |
|
84 |
||
85 |
root |
|
86 |
"get the root node |
|
87 |
" |
|
88 |
^ root |
|
89 |
! |
|
90 |
||
509 | 91 |
root:aRoot |
92 |
"set a new root |
|
458 | 93 |
" |
1176 | 94 |
|tree| |
95 |
||
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
96 |
root notNil ifTrue: [ |
1176 | 97 |
tree := root tree. |
98 |
root tree:nil. |
|
99 |
] ifFalse:[ |
|
100 |
tree := self |
|
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
101 |
]. |
811 | 102 |
self stopRunningTasks. |
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
103 |
|
515 | 104 |
(root := aRoot) notNil ifTrue:[ |
1176 | 105 |
root tree:tree. |
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
106 |
root parent:nil. |
857 | 107 |
]. |
1189 | 108 |
self recomputeList |
860 | 109 |
! |
110 |
||
111 |
value |
|
112 |
^ list |
|
496 | 113 |
! ! |
491 | 114 |
|
2697 | 115 |
!SelectionInTree methodsFor:'accessing hierarchy new'! |
116 |
||
117 |
doMakeVisible:something |
|
118 |
"make an item or list of items to become visible |
|
119 |
" |
|
120 |
|anchor parent| |
|
121 |
||
122 |
self each:something do:[:anItem| |
|
123 |
parent := anItem. |
|
124 |
anchor := nil. |
|
125 |
||
126 |
parent notNil ifTrue:[ |
|
127 |
[(parent := parent parent) notNil] whileTrue:[ |
|
128 |
parent hidden ifTrue:[ |
|
129 |
anchor notNil ifTrue:[ anchor expand ]. |
|
130 |
anchor := parent. |
|
131 |
] |
|
132 |
]. |
|
133 |
anchor notNil ifTrue:[ |
|
134 |
self expandItem:anchor do:[anchor expand] |
|
135 |
] |
|
136 |
]. |
|
137 |
] |
|
138 |
! ! |
|
139 |
||
1818 | 140 |
!SelectionInTree methodsFor:'accessing-behavior'! |
496 | 141 |
|
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
142 |
childrenAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
143 |
"get children action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
144 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
145 |
^childrenAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
146 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
147 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
148 |
childrenAction:aBlock |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
149 |
"set children action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
150 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
151 |
childrenAction := aBlock. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
152 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
153 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
154 |
contentsAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
155 |
"get contents action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
156 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
157 |
^contentsAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
158 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
159 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
160 |
contentsAction:aBlock |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
161 |
"set contents action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
162 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
163 |
contentsAction := aBlock. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
164 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
165 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
166 |
iconAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
167 |
"get icon action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
168 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
169 |
^iconAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
170 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
171 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
172 |
iconAction:aBlock |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
173 |
"set icon action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
174 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
175 |
iconAction := aBlock. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
176 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
177 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
178 |
labelAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
179 |
"get label action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
180 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
181 |
^labelAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
182 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
183 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
184 |
labelAction:aBlock |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
185 |
"set label action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
186 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
187 |
labelAction := aBlock. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
188 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
189 |
|
496 | 190 |
showRoot |
191 |
"list with or without root |
|
192 |
" |
|
193 |
^ showRoot |
|
491 | 194 |
! |
195 |
||
496 | 196 |
showRoot:aState |
197 |
"list with or without root |
|
491 | 198 |
" |
496 | 199 |
aState ~~ showRoot ifTrue:[ |
200 |
showRoot := aState. |
|
491 | 201 |
|
496 | 202 |
root notNil ifTrue:[ |
857 | 203 |
aState ifTrue:[ |
204 |
list addFirst:root. |
|
205 |
self changed:#insertCollection: with:(Array with:1 with:1 with:nil). |
|
206 |
] ifFalse:[ |
|
207 |
list removeFirst. |
|
208 |
self changed:#removeFrom: with:(Array with:1 with:1 with:nil). |
|
209 |
]. |
|
491 | 210 |
]. |
211 |
]. |
|
458 | 212 |
! ! |
213 |
||
1818 | 214 |
!SelectionInTree methodsFor:'accessing-hierarchy'! |
458 | 215 |
|
216 |
collapse:something |
|
217 |
"collapse a node or collection of nodes |
|
218 |
" |
|
857 | 219 |
|listChanged| |
220 |
||
221 |
listChanged := false. |
|
458 | 222 |
|
223 |
self each:something do:[:aNode| |
|
224 |
aNode isCollapsable ifTrue:[ |
|
225 |
aNode collapse. |
|
857 | 226 |
listChanged := true |
458 | 227 |
] |
228 |
]. |
|
857 | 229 |
listChanged ifTrue:[ |
230 |
self listFromRoot. |
|
231 |
self changed:#list. |
|
232 |
] |
|
233 |
||
458 | 234 |
! |
235 |
||
509 | 236 |
expand |
237 |
"expand the root |
|
238 |
" |
|
239 |
self expand:root |
|
240 |
! |
|
241 |
||
458 | 242 |
expand:something |
243 |
"expand a node or collection of nodes |
|
244 |
" |
|
857 | 245 |
|listChanged| |
246 |
||
247 |
listChanged := false. |
|
458 | 248 |
|
249 |
self each:something do:[:aNode| |
|
250 |
aNode isExpandable ifTrue:[ |
|
251 |
aNode expand. |
|
857 | 252 |
listChanged := true |
458 | 253 |
] |
254 |
]. |
|
857 | 255 |
listChanged ifTrue:[ |
256 |
self listFromRoot. |
|
257 |
self changed:#list. |
|
258 |
] |
|
259 |
! ! |
|
260 |
||
1818 | 261 |
!SelectionInTree methodsFor:'accessing-hierarchy new'! |
857 | 262 |
|
263 |
doCollapse:something |
|
264 |
"collapse all children under an item or a sequence of items; |
|
265 |
if the list changed, notifications are raised |
|
266 |
" |
|
267 |
self each:something do:[:anItem| |
|
268 |
self collapseItem:anItem do:[ anItem collapse ] |
|
269 |
] |
|
270 |
! |
|
271 |
||
272 |
doCollapseAll:something |
|
273 |
"collapse all children and subChildren under an item or sequence of items; |
|
274 |
if the list changed, notifications are raised |
|
275 |
" |
|
276 |
self each:something do:[:anItem| |
|
277 |
self collapseItem:anItem do:[ anItem collapseAll ] |
|
278 |
] |
|
279 |
! |
|
280 |
||
281 |
doExpand:something |
|
282 |
"expand all children under an item or collection of items; |
|
283 |
if the list changed, notifications are raised |
|
284 |
" |
|
285 |
self each:something do:[:anItem| |
|
286 |
self expandItem:anItem do:[anItem expand] |
|
287 |
] |
|
288 |
! |
|
289 |
||
290 |
doExpandAll:something |
|
291 |
"expand all children and subChildren under an item or sequence of items; |
|
292 |
if the list changed, notifications are raised |
|
293 |
" |
|
294 |
self each:something do:[:anItem| |
|
295 |
self expandItem:anItem do:[anItem expandAll] |
|
296 |
] |
|
458 | 297 |
! ! |
298 |
||
299 |
!SelectionInTree methodsFor:'adding & removing'! |
|
300 |
||
301 |
add:something after:aChild |
|
302 |
"add a node or collection of nodes to parent after a child |
|
303 |
" |
|
304 |
"add a node or collection of nodes to after a child |
|
305 |
" |
|
857 | 306 |
|p| |
307 |
||
308 |
(aChild notNil and:[(p := aChild parent) notNil]) ifTrue:[ |
|
309 |
self add:something afterIndex:(p indexOfChild:aChild) below:p |
|
458 | 310 |
] |
857 | 311 |
|
458 | 312 |
! |
313 |
||
314 |
add:something afterIndex:anIndex below:aParent |
|
315 |
"add a node or collection of nodes to parent after an index |
|
316 |
" |
|
857 | 317 |
self add:something beforeIndex:(anIndex + 1) below:aParent |
458 | 318 |
! |
319 |
||
320 |
add:something before:aChild |
|
321 |
"add a node or collection of nodes to before a child |
|
322 |
" |
|
857 | 323 |
|p| |
324 |
||
325 |
(aChild notNil and:[(p := aChild parent) notNil]) ifTrue:[ |
|
326 |
self add:something beforeIndex:(p indexOfChild:aChild) below:p |
|
458 | 327 |
] |
328 |
! |
|
329 |
||
330 |
add:something beforeIndex:anIndex below:aParent |
|
1204 | 331 |
"add a node or collection of nodes to aParents children |
332 |
before anIndex (which is a child-index) |
|
458 | 333 |
" |
857 | 334 |
|children start index size pList| |
335 |
||
336 |
( aParent isNil |
|
337 |
or:[something isNil |
|
338 |
or:[(something isCollection and:[something isEmpty])]] |
|
339 |
) ifTrue:[ |
|
340 |
^ self |
|
341 |
]. |
|
342 |
||
343 |
(start := self indexOf:aParent) == 0 ifTrue:[ |
|
344 |
"/ |
|
345 |
"/ parent not visible; list not changed |
|
346 |
"/ |
|
1304 | 347 |
aParent == root ifFalse:[ |
348 |
aParent add:something beforeIndex:anIndex. |
|
349 |
^ self |
|
350 |
] |
|
351 |
] ifFalse:[ |
|
352 |
aParent shown ifFalse:[ |
|
353 |
aParent add:something beforeIndex:anIndex. |
|
354 |
self changed:#at: with:start. |
|
355 |
^ self |
|
356 |
] |
|
857 | 357 |
]. |
358 |
children := aParent children. |
|
359 |
||
360 |
(children isEmpty or:[anIndex <= 1]) ifTrue:[ |
|
361 |
index := 1. |
|
362 |
] ifFalse:[ |
|
363 |
size := children size. |
|
364 |
||
365 |
anIndex > size ifTrue:[ |
|
366 |
index := size + 1. |
|
367 |
start := aParent numberOfAllVisibleChildren + start. |
|
368 |
] ifFalse:[ |
|
369 |
index := anIndex. |
|
370 |
start := (self indexOf:(children at:index)) - 1. |
|
371 |
] |
|
372 |
]. |
|
373 |
aParent add:something beforeIndex:index. |
|
374 |
||
375 |
(start := start + 1) == 0 ifTrue:[ |
|
376 |
"/ |
|
377 |
"/ not visible |
|
378 |
"/ |
|
379 |
^ self |
|
380 |
]. |
|
381 |
pList := OrderedCollection new:2048. |
|
382 |
||
383 |
self each:something do:[:aNode| |
|
384 |
pList add:aNode. |
|
385 |
aNode addVisibleChildrenTo:pList |
|
386 |
]. |
|
387 |
pList isEmpty ifTrue:[ |
|
388 |
^ self |
|
389 |
]. |
|
390 |
list addAll:pList beforeIndex:start. |
|
391 |
||
392 |
self changed:#insertCollection: |
|
393 |
with:(Array with:start with:pList size with:aParent). |
|
458 | 394 |
|
395 |
! |
|
396 |
||
397 |
add:something below:aParent |
|
398 |
"add a node or collection of nodes to parent |
|
399 |
" |
|
857 | 400 |
aParent notNil ifTrue:[ |
401 |
self add:something beforeIndex:(aParent numberOfChildren + 1) below:aParent |
|
402 |
] |
|
458 | 403 |
! |
404 |
||
405 |
remove:something |
|
406 |
"remove a node or collection of nodes |
|
407 |
" |
|
1268 | 408 |
|node index loNums loItem start size parent stop| |
857 | 409 |
|
410 |
something isNil ifTrue:[ |
|
411 |
^ something |
|
412 |
]. |
|
413 |
loNums := SortedCollection new. |
|
414 |
||
415 |
self each:something do:[:el| |
|
416 |
node := el isNumber ifTrue:[list at:el ifAbsent:nil] |
|
417 |
ifFalse:[el]. |
|
418 |
||
419 |
node notNil ifTrue:[ |
|
420 |
self stopIndicatorValidationFor:node. |
|
458 | 421 |
|
857 | 422 |
node parent isNil ifTrue:[ |
423 |
"/ remove all including root |
|
424 |
node == root ifTrue:[ self root:nil ]. |
|
425 |
^ something |
|
426 |
]. |
|
427 |
index := self indexOf:node. |
|
811 | 428 |
|
857 | 429 |
index == 0 ifTrue:[ |
430 |
"/ not visible |
|
431 |
node parent removeChild:node |
|
432 |
] ifFalse:[ |
|
433 |
loNums add:index |
|
434 |
]. |
|
458 | 435 |
] |
436 |
]. |
|
857 | 437 |
|
438 |
loNums isEmpty ifTrue:[ |
|
439 |
"/ nothing visible changed |
|
440 |
^ something |
|
441 |
]. |
|
442 |
loItem := OrderedCollection new. |
|
443 |
loNums do:[:i| loItem add:(list at:i)]. |
|
444 |
||
445 |
loItem do:[:aNode| |
|
446 |
start := self indexOf:aNode. |
|
447 |
||
448 |
start ~~ 0 ifTrue:[ |
|
449 |
parent := aNode parent. |
|
450 |
size := 1 + aNode numberOfAllVisibleChildren. |
|
860 | 451 |
stop := start + size - 1. |
857 | 452 |
parent remove:aNode. |
860 | 453 |
list removeFromIndex:start toIndex:stop. |
811 | 454 |
|
857 | 455 |
self changed:#removeFrom: |
860 | 456 |
with:(Array with:start with:stop with:parent). |
857 | 457 |
] |
458 |
]. |
|
459 |
^ something |
|
460 |
! |
|
461 |
||
462 |
removeAllOtherThanRoot |
|
463 |
"remove all other than the root |
|
464 |
" |
|
465 |
|listChanged| |
|
466 |
||
467 |
root notNil ifTrue:[ |
|
468 |
listChanged := root isCollapsable. |
|
469 |
root children:(OrderedCollection new). |
|
470 |
||
471 |
listChanged ifTrue:[ |
|
472 |
self listFromRoot. |
|
473 |
self changed:#list |
|
474 |
] |
|
475 |
] |
|
458 | 476 |
! |
477 |
||
478 |
removeIndex:something |
|
479 |
"remove a node at index or collection of indexed nodes |
|
480 |
" |
|
857 | 481 |
self remove:something |
458 | 482 |
! |
483 |
||
484 |
removeSelection |
|
485 |
"remove selected nodes |
|
486 |
" |
|
857 | 487 |
|sel| |
488 |
||
489 |
sel := self selectionIndex. |
|
490 |
self selectionIndex:nil. |
|
491 |
self remove:sel. |
|
1209 | 492 |
! |
493 |
||
494 |
replaceNode:aNode with:aNewNode |
|
495 |
"replace a node by a new node; if the new node is nil, the node and its |
|
496 |
children are removed. Otherwise the children are taken over to the new |
|
497 |
node. |
|
498 |
" |
|
499 |
|parent index children| |
|
500 |
||
501 |
(aNode isNil or:[aNode == aNewNode]) ifTrue:[ |
|
502 |
^ self |
|
503 |
]. |
|
504 |
||
505 |
aNewNode isNil ifTrue:[ |
|
506 |
^ self remove:aNode |
|
507 |
]. |
|
508 |
self stopIndicatorValidationFor:aNode. |
|
509 |
||
510 |
aNewNode children:(aNode children). |
|
511 |
aNode children:nil. |
|
512 |
||
513 |
aNode == root ifTrue:[ |
|
514 |
aNewNode tree:(aNode tree). |
|
515 |
aNewNode parent:nil. |
|
516 |
root := aNewNode. |
|
517 |
] ifFalse:[ |
|
518 |
parent := aNode parent. |
|
519 |
aNewNode tree:nil. |
|
520 |
aNewNode parent:parent. |
|
521 |
children := parent children. |
|
522 |
index := children identityIndexOf:aNode. |
|
523 |
children at:index put:aNewNode. |
|
524 |
]. |
|
525 |
||
526 |
aNode tree:nil. |
|
527 |
aNode parent:nil. |
|
528 |
||
529 |
(index := self indexOf:aNode) ~~ 0 ifTrue:[ |
|
530 |
list at:index put:aNewNode. |
|
531 |
self changed:#at: with:index |
|
532 |
]. |
|
458 | 533 |
! ! |
534 |
||
758 | 535 |
!SelectionInTree methodsFor:'change & update'! |
536 |
||
537 |
invalidate |
|
538 |
"called; something changed what requires a redraw but no recomputation. |
|
539 |
for example a name |
|
540 |
" |
|
541 |
self dependents do:[:aDependent| |
|
542 |
aDependent isView ifTrue:[ aDependent invalidate ] |
|
543 |
]. |
|
544 |
||
545 |
||
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
546 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
547 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
548 |
update:something with:aParameter from:aModel |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
549 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
550 |
self dependents do:[:aDependent| |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
551 |
aDependent update:something with:aParameter from:aModel |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
552 |
] |
758 | 553 |
! ! |
554 |
||
458 | 555 |
!SelectionInTree methodsFor:'enumerating'! |
556 |
||
557 |
each:something do:aBlock |
|
558 |
"evaluate a block for something or in case of a collection for each |
|
559 |
element in the collection |
|
560 |
" |
|
561 |
something notNil ifTrue:[ |
|
562 |
something isCollection ifTrue:[something do:[:el|aBlock value:el]] |
|
563 |
ifFalse:[aBlock value:something] |
|
564 |
] |
|
565 |
||
566 |
! ! |
|
567 |
||
496 | 568 |
!SelectionInTree methodsFor:'initialization'! |
569 |
||
570 |
initialize |
|
811 | 571 |
|
1166
d062a52bc7cc
list attribute changed from OrderedCollection to List
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
572 |
showRoot := true. |
811 | 573 |
indicatorList := OrderedCollection new. |
574 |
accessLock := Semaphore forMutualExclusion. |
|
1166
d062a52bc7cc
list attribute changed from OrderedCollection to List
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
575 |
list := List new. |
496 | 576 |
! ! |
577 |
||
458 | 578 |
!SelectionInTree methodsFor:'private'! |
579 |
||
580 |
recomputeList |
|
581 |
"Travers the tree and build a new list." |
|
582 |
||
857 | 583 |
self listFromRoot. |
584 |
self changed:#list. |
|
585 |
! ! |
|
586 |
||
2494 | 587 |
!SelectionInTree methodsFor:'private-hierarchy'! |
857 | 588 |
|
589 |
collapseItem:anItem do:collapseBlock |
|
590 |
"collapse all children under an item; raise a notification if |
|
591 |
the list changed |
|
592 |
" |
|
593 |
|start stop size| |
|
594 |
||
595 |
anItem isCollapsable ifFalse:[ |
|
596 |
^ self |
|
597 |
]. |
|
598 |
||
599 |
(start := self indexOf:anItem) == 0 ifTrue:[ |
|
600 |
"/ |
|
601 |
"/ item not visible |
|
602 |
"/ |
|
603 |
collapseBlock value. |
|
604 |
] ifFalse:[ |
|
605 |
size := anItem numberOfAllVisibleChildren. |
|
606 |
collapseBlock value. |
|
607 |
||
608 |
size == 0 ifTrue:[ |
|
609 |
"/ |
|
610 |
"/ no children before; list not changed |
|
611 |
"/ |
|
612 |
self changed:#at: with:start |
|
613 |
] ifFalse:[ |
|
614 |
stop := start + size. |
|
615 |
start := start + 1. |
|
616 |
list removeFromIndex:start toIndex:stop. |
|
860 | 617 |
self changed:#removeFrom: with:(Array with:start with:stop with:anItem). |
857 | 618 |
] |
619 |
] |
|
620 |
! |
|
621 |
||
622 |
expandItem:anItem do:expandBlock |
|
623 |
"expand all children under an item; raise a notification if |
|
624 |
the list changed |
|
625 |
" |
|
626 |
|start size pList| |
|
627 |
||
628 |
anItem isExpandable ifFalse:[ |
|
629 |
^ self |
|
630 |
]. |
|
631 |
expandBlock value. |
|
632 |
||
633 |
(start := self indexOf:anItem) ~~ 0 ifTrue:[ |
|
634 |
anItem addVisibleChildrenTo:(pList := OrderedCollection new:2048). |
|
635 |
||
636 |
(size := pList size) ~~ 0 ifTrue:[ |
|
637 |
start := 1 + start. |
|
638 |
list addAll:pList beforeIndex:start. |
|
639 |
||
640 |
self changed:#insertCollection: |
|
641 |
with:(Array with:start with:size with:anItem). |
|
642 |
] ifFalse:[ |
|
643 |
self changed:#at: with:start |
|
644 |
] |
|
645 |
] |
|
646 |
! |
|
647 |
||
648 |
listFromRoot |
|
1204 | 649 |
"Traverse the tree and build a new list; |
857 | 650 |
no change notification is raised |
651 |
" |
|
842 | 652 |
list clearContents. |
458 | 653 |
|
654 |
root notNil ifTrue:[ |
|
857 | 655 |
showRoot ifTrue:[ list add:root ]. |
656 |
root addVisibleChildrenTo:list |
|
657 |
] |
|
658 |
||
659 |
! ! |
|
660 |
||
661 |
!SelectionInTree methodsFor:'queries'! |
|
662 |
||
663 |
indexOf:anItem |
|
664 |
"returns the index of an item or 0 |
|
665 |
" |
|
666 |
^ anItem notNil ifTrue:[list identityIndexOf:anItem] |
|
667 |
ifFalse:[0] |
|
458 | 668 |
! ! |
669 |
||
849 | 670 |
!SelectionInTree methodsFor:'searching'! |
671 |
||
1550 | 672 |
detectFirstItem:aOneArgBlock |
673 |
"detect an item the evaluation of the block returns true. |
|
674 |
The argument to the block is the item. |
|
675 |
This recursively enumerates the tree for the first item for which |
|
676 |
the block returns true. |
|
677 |
" |
|
678 |
root notNil ifTrue:[ |
|
679 |
^ root detectFirstChild:aOneArgBlock |
|
680 |
]. |
|
681 |
^ nil |
|
682 |
||
683 |
||
684 |
! |
|
685 |
||
849 | 686 |
detectItem:aOneArgBlock |
1553 | 687 |
"detect an item the evaluation of the block returns true. |
688 |
The argument to the block is the item. |
|
1550 | 689 |
This searches top-level items only. |
849 | 690 |
" |
691 |
root notNil ifTrue:[ |
|
692 |
^ root detectChild:aOneArgBlock |
|
693 |
]. |
|
694 |
^ nil |
|
695 |
||
696 |
||
697 |
! |
|
698 |
||
699 |
detectItem:aTwoArgBlock arguments:aListOfArgs |
|
1553 | 700 |
"detect an item the evaluation of the block returns true. |
701 |
The first argument to the block is the item, the second argument |
|
702 |
the value derived from the argument list at level. |
|
703 |
This recursively walks down the tree up to aListOfArgs size levels; |
|
704 |
i.e. if you pass (1 to:10) as aListOfArgs, the block will get the sub-level |
|
705 |
as second argument and stop the search after 10 levels. |
|
849 | 706 |
" |
1550 | 707 |
|
849 | 708 |
root notNil ifTrue:[ |
1553 | 709 |
^ root detectChild:aTwoArgBlock arguments:aListOfArgs |
849 | 710 |
]. |
711 |
^ nil |
|
712 |
||
713 |
||
714 |
! ! |
|
715 |
||
458 | 716 |
!SelectionInTree methodsFor:'selection'! |
717 |
||
1213 | 718 |
selectNode:aNode |
719 |
|index| |
|
720 |
||
721 |
(index := self indexOf:aNode) ~~ 0 ifTrue:[ |
|
722 |
self selectionIndex:index |
|
723 |
] |
|
724 |
! |
|
725 |
||
1234 | 726 |
selectNodes:aCollectionOfNodes |
727 |
| indices| |
|
728 |
||
729 |
indices := aCollectionOfNodes collect:[:aNode | self indexOf:aNode]. |
|
730 |
indices := indices select:[:idx | idx ~~ 0]. |
|
731 |
indices sort. |
|
732 |
self selectionIndex:indices |
|
733 |
||
734 |
"Created: / 6.3.1999 / 22:37:59 / cg" |
|
735 |
! |
|
736 |
||
906 | 737 |
selectedNode |
738 |
"returns selected node or nil |
|
739 |
" |
|
740 |
|nodes| |
|
741 |
(nodes := self selectedNodes) notNil ifTrue: [ |
|
742 |
^nodes first |
|
743 |
]. |
|
744 |
^nil |
|
745 |
||
746 |
||
747 |
! |
|
748 |
||
857 | 749 |
selectedNodes |
750 |
"returns list of selected nodes or nil |
|
751 |
" |
|
752 |
|node coll| |
|
753 |
||
754 |
selection isNil ifTrue:[ |
|
755 |
^ nil |
|
756 |
]. |
|
757 |
||
758 |
selection isCollection ifFalse:[ |
|
759 |
node := list at:selection ifAbsent:nil. |
|
760 |
^ node notNil ifTrue:[Array with:node] ifFalse:[nil] |
|
761 |
]. |
|
762 |
||
763 |
selection isEmpty ifTrue:[ |
|
764 |
^ nil |
|
765 |
]. |
|
766 |
||
767 |
coll := OrderedCollection new:(selection size). |
|
768 |
||
769 |
selection do:[:idx| |
|
770 |
(node := list at:idx ifAbsent:nil) notNil ifTrue:[ |
|
771 |
coll add:node |
|
772 |
] |
|
773 |
]. |
|
4275 | 774 |
^ coll asNilIfEmpty |
857 | 775 |
! |
776 |
||
2038 | 777 |
selectedNodesDo:aOneArgBlock |
778 |
"evaluate the block on eack node selected |
|
779 |
" |
|
780 |
|node| |
|
781 |
||
782 |
selection isNil ifTrue:[ |
|
783 |
^ nil |
|
784 |
]. |
|
785 |
||
786 |
selection isCollection ifFalse:[ |
|
787 |
node := list at:selection ifAbsent:nil. |
|
788 |
node notNil ifTrue:[ |
|
789 |
aOneArgBlock value:node |
|
790 |
]. |
|
791 |
^ self |
|
792 |
]. |
|
793 |
||
794 |
selection do:[:i| |
|
795 |
node := list at:i ifAbsent:nil. |
|
796 |
||
797 |
node notNil ifTrue:[ |
|
798 |
aOneArgBlock value:node |
|
799 |
]. |
|
800 |
]. |
|
801 |
! |
|
802 |
||
458 | 803 |
selection |
804 |
"get the selection or nil |
|
805 |
" |
|
806 |
^ self selectionIndex |
|
807 |
! |
|
808 |
||
809 |
selection:indexesOrNil |
|
3872
a35d3ecdb0bb
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2840
diff
changeset
|
810 |
"set the selection" |
a35d3ecdb0bb
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2840
diff
changeset
|
811 |
|
458 | 812 |
self selectionIndex:indexesOrNil |
813 |
! |
|
814 |
||
815 |
selectionIndex |
|
816 |
"get the selection or nil |
|
817 |
" |
|
818 |
^ selection |
|
819 |
! |
|
820 |
||
821 |
selectionIndex:indexesOrNil |
|
822 |
"set the selection |
|
823 |
" |
|
496 | 824 |
|oldSel| |
825 |
||
826 |
oldSel := selection. |
|
827 |
self setSelectionIndex:indexesOrNil. |
|
828 |
||
829 |
oldSel = selection ifFalse:[ |
|
2038 | 830 |
self changed:#selectionIndex. |
831 |
||
832 |
self selectedNodesDo:[:aNode| |
|
833 |
aNode changedSelected |
|
834 |
] |
|
496 | 835 |
] |
836 |
! |
|
837 |
||
838 |
setSelection:indexesOrNil |
|
839 |
"set the selection without raising a notification |
|
840 |
" |
|
841 |
self setSelectionIndex:indexesOrNil |
|
842 |
! |
|
843 |
||
844 |
setSelectionIndex:indexesOrNil |
|
845 |
"set the selection without raising a notification |
|
846 |
" |
|
458 | 847 |
|indexes| |
848 |
||
849 |
indexes := indexesOrNil. |
|
850 |
||
851 |
indexes size == 0 ifTrue:[ |
|
852 |
(indexes isCollection or:[indexes == 0]) ifTrue:[ |
|
853 |
indexes := nil |
|
854 |
] |
|
855 |
]. |
|
496 | 856 |
selection := indexes |
458 | 857 |
|
858 |
! ! |
|
859 |
||
811 | 860 |
!SelectionInTree methodsFor:'update indication task'! |
861 |
||
862 |
startIndicatorValidationFor:aNode |
|
863 |
"add a node to list of updating indications |
|
864 |
" |
|
865 |
|index| |
|
866 |
||
867 |
accessLock critical:[ |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
868 |
|prio| |
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
869 |
|
811 | 870 |
index := indicatorList identityIndexOf:aNode. |
871 |
||
872 |
index ~~ 0 ifTrue:[ |
|
873 |
indicatorList removeIndex:index. "/ reorganize list to be faster |
|
874 |
]. |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
875 |
indicatorList addLast: "addFirst:" aNode. |
811 | 876 |
|
877 |
indicatorTask isNil ifTrue:[ |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
878 |
prio := Processor activePriority. |
811 | 879 |
indicatorTask := [ |
880 |
[ self taskCycle ] whileTrue:[ Processor yield ] |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
881 |
] forkAt:(prio - 1). |
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
882 |
indicatorTask priorityRange:(prio-1 to:prio). |
811 | 883 |
] |
884 |
]. |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
885 |
|
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
886 |
"Modified: / 26.9.1998 / 15:20:44 / cg" |
811 | 887 |
! |
888 |
||
889 |
stopIndicatorValidationFor:aNodeOrList |
|
890 |
"remove a node or list of nodes from list of updating indications |
|
891 |
" |
|
892 |
accessLock critical:[ |
|
893 |
aNodeOrList isCollection ifTrue:[ |
|
894 |
aNodeOrList do:[:aNode| |
|
895 |
indicatorList removeIdentical:aNode ifAbsent:nil |
|
896 |
] |
|
897 |
] ifFalse:[ |
|
898 |
indicatorList removeIdentical:aNodeOrList ifAbsent:nil |
|
899 |
] |
|
900 |
] |
|
901 |
||
902 |
||
903 |
! |
|
904 |
||
905 |
stopRunningTasks |
|
906 |
"stop task |
|
907 |
" |
|
908 |
accessLock critical:[ indicatorList removeAll ] |
|
909 |
||
910 |
! |
|
911 |
||
912 |
taskCycle |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
913 |
"run one cycle fetching indicator state. |
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
914 |
This is done in the background to avoid long startup |
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
915 |
delays, in case the indicator information takes long to |
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
916 |
gather (i.e. when reading directories)" |
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
917 |
|
2038 | 918 |
|node flag| |
811 | 919 |
|
920 |
accessLock critical:[ |
|
921 |
indicatorList isEmpty ifTrue:[ "/ queue is empty; terminate task |
|
922 |
indicatorTask := nil. |
|
923 |
^ false |
|
924 |
]. |
|
925 |
node := indicatorList removeFirst. "/ run task on first node |
|
926 |
node hasValidIndicator ifTrue:[ "/ up to date |
|
927 |
^ true |
|
928 |
]. |
|
2038 | 929 |
node setShowIndicator:(node defaultShowSeparator). "/ disable registry |
811 | 930 |
]. |
931 |
||
2038 | 932 |
flag := DirectoryContents directoryNamed:(node fileName) detect:(node matchAction). |
933 |
node showIndicator:flag. |
|
811 | 934 |
^ true |
1145 | 935 |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
936 |
"Modified: / 26.9.1998 / 15:11:16 / cg" |
811 | 937 |
! ! |
938 |
||
458 | 939 |
!SelectionInTree class methodsFor:'documentation'! |
940 |
||
941 |
version |
|
4275 | 942 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTree.st,v 1.36 2013-07-13 21:06:39 cg Exp $' |
3872
a35d3ecdb0bb
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2840
diff
changeset
|
943 |
! |
a35d3ecdb0bb
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2840
diff
changeset
|
944 |
|
a35d3ecdb0bb
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2840
diff
changeset
|
945 |
version_CVS |
4275 | 946 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTree.st,v 1.36 2013-07-13 21:06:39 cg Exp $' |
458 | 947 |
! ! |
4275 | 948 |