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