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