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