author | Claus Gittinger <cg@exept.de> |
Fri, 19 Mar 1999 22:19:17 +0100 | |
changeset 1268 | 37066c039eb3 |
parent 1234 | 1dee4432fd38 |
child 1304 | e6693ac51d54 |
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 |
"/ |
|
344 |
aParent add:something beforeIndex:anIndex. |
|
345 |
^ self |
|
346 |
]. |
|
347 |
||
348 |
aParent shown ifFalse:[ |
|
349 |
aParent add:something beforeIndex:anIndex. |
|
350 |
self changed:#at: with:start. |
|
351 |
^ self |
|
352 |
]. |
|
353 |
children := aParent children. |
|
354 |
||
355 |
(children isEmpty or:[anIndex <= 1]) ifTrue:[ |
|
356 |
index := 1. |
|
357 |
] ifFalse:[ |
|
358 |
size := children size. |
|
359 |
||
360 |
anIndex > size ifTrue:[ |
|
361 |
index := size + 1. |
|
362 |
start := aParent numberOfAllVisibleChildren + start. |
|
363 |
] ifFalse:[ |
|
364 |
index := anIndex. |
|
365 |
start := (self indexOf:(children at:index)) - 1. |
|
366 |
] |
|
367 |
]. |
|
368 |
aParent add:something beforeIndex:index. |
|
369 |
||
370 |
(start := start + 1) == 0 ifTrue:[ |
|
371 |
"/ |
|
372 |
"/ not visible |
|
373 |
"/ |
|
374 |
^ self |
|
375 |
]. |
|
376 |
pList := OrderedCollection new:2048. |
|
377 |
||
378 |
self each:something do:[:aNode| |
|
379 |
pList add:aNode. |
|
380 |
aNode addVisibleChildrenTo:pList |
|
381 |
]. |
|
382 |
pList isEmpty ifTrue:[ |
|
383 |
^ self |
|
384 |
]. |
|
385 |
list addAll:pList beforeIndex:start. |
|
386 |
||
387 |
self changed:#insertCollection: |
|
388 |
with:(Array with:start with:pList size with:aParent). |
|
458 | 389 |
|
390 |
! |
|
391 |
||
392 |
add:something below:aParent |
|
393 |
"add a node or collection of nodes to parent |
|
394 |
" |
|
857 | 395 |
aParent notNil ifTrue:[ |
396 |
self add:something beforeIndex:(aParent numberOfChildren + 1) below:aParent |
|
397 |
] |
|
458 | 398 |
! |
399 |
||
400 |
remove:something |
|
401 |
"remove a node or collection of nodes |
|
402 |
" |
|
1268 | 403 |
|node index loNums loItem start size parent stop| |
857 | 404 |
|
405 |
something isNil ifTrue:[ |
|
406 |
^ something |
|
407 |
]. |
|
408 |
loNums := SortedCollection new. |
|
409 |
||
410 |
self each:something do:[:el| |
|
411 |
node := el isNumber ifTrue:[list at:el ifAbsent:nil] |
|
412 |
ifFalse:[el]. |
|
413 |
||
414 |
node notNil ifTrue:[ |
|
415 |
self stopIndicatorValidationFor:node. |
|
458 | 416 |
|
857 | 417 |
node parent isNil ifTrue:[ |
418 |
"/ remove all including root |
|
419 |
node == root ifTrue:[ self root:nil ]. |
|
420 |
^ something |
|
421 |
]. |
|
422 |
index := self indexOf:node. |
|
811 | 423 |
|
857 | 424 |
index == 0 ifTrue:[ |
425 |
"/ not visible |
|
426 |
node parent removeChild:node |
|
427 |
] ifFalse:[ |
|
428 |
loNums add:index |
|
429 |
]. |
|
458 | 430 |
] |
431 |
]. |
|
857 | 432 |
|
433 |
loNums isEmpty ifTrue:[ |
|
434 |
"/ nothing visible changed |
|
435 |
^ something |
|
436 |
]. |
|
437 |
loItem := OrderedCollection new. |
|
438 |
loNums do:[:i| loItem add:(list at:i)]. |
|
439 |
||
440 |
loItem do:[:aNode| |
|
441 |
start := self indexOf:aNode. |
|
442 |
||
443 |
start ~~ 0 ifTrue:[ |
|
444 |
parent := aNode parent. |
|
445 |
size := 1 + aNode numberOfAllVisibleChildren. |
|
860 | 446 |
stop := start + size - 1. |
857 | 447 |
parent remove:aNode. |
860 | 448 |
list removeFromIndex:start toIndex:stop. |
811 | 449 |
|
857 | 450 |
self changed:#removeFrom: |
860 | 451 |
with:(Array with:start with:stop with:parent). |
857 | 452 |
] |
453 |
]. |
|
454 |
^ something |
|
455 |
! |
|
456 |
||
457 |
removeAllOtherThanRoot |
|
458 |
"remove all other than the root |
|
459 |
" |
|
460 |
|listChanged| |
|
461 |
||
462 |
root notNil ifTrue:[ |
|
463 |
listChanged := root isCollapsable. |
|
464 |
root children:(OrderedCollection new). |
|
465 |
||
466 |
listChanged ifTrue:[ |
|
467 |
self listFromRoot. |
|
468 |
self changed:#list |
|
469 |
] |
|
470 |
] |
|
458 | 471 |
! |
472 |
||
473 |
removeIndex:something |
|
474 |
"remove a node at index or collection of indexed nodes |
|
475 |
" |
|
857 | 476 |
self remove:something |
458 | 477 |
! |
478 |
||
479 |
removeSelection |
|
480 |
"remove selected nodes |
|
481 |
" |
|
857 | 482 |
|sel| |
483 |
||
484 |
sel := self selectionIndex. |
|
485 |
self selectionIndex:nil. |
|
486 |
self remove:sel. |
|
1209 | 487 |
! |
488 |
||
489 |
replaceNode:aNode with:aNewNode |
|
490 |
"replace a node by a new node; if the new node is nil, the node and its |
|
491 |
children are removed. Otherwise the children are taken over to the new |
|
492 |
node. |
|
493 |
" |
|
494 |
|parent index children| |
|
495 |
||
496 |
(aNode isNil or:[aNode == aNewNode]) ifTrue:[ |
|
497 |
^ self |
|
498 |
]. |
|
499 |
||
500 |
aNewNode isNil ifTrue:[ |
|
501 |
^ self remove:aNode |
|
502 |
]. |
|
503 |
self stopIndicatorValidationFor:aNode. |
|
504 |
||
505 |
aNewNode children:(aNode children). |
|
506 |
aNode children:nil. |
|
507 |
||
508 |
aNode == root ifTrue:[ |
|
509 |
aNewNode tree:(aNode tree). |
|
510 |
aNewNode parent:nil. |
|
511 |
root := aNewNode. |
|
512 |
] ifFalse:[ |
|
513 |
parent := aNode parent. |
|
514 |
aNewNode tree:nil. |
|
515 |
aNewNode parent:parent. |
|
516 |
children := parent children. |
|
517 |
index := children identityIndexOf:aNode. |
|
518 |
children at:index put:aNewNode. |
|
519 |
]. |
|
520 |
||
521 |
aNode tree:nil. |
|
522 |
aNode parent:nil. |
|
523 |
||
524 |
(index := self indexOf:aNode) ~~ 0 ifTrue:[ |
|
525 |
list at:index put:aNewNode. |
|
526 |
self changed:#at: with:index |
|
527 |
]. |
|
458 | 528 |
! ! |
529 |
||
758 | 530 |
!SelectionInTree methodsFor:'change & update'! |
531 |
||
532 |
invalidate |
|
533 |
"called; something changed what requires a redraw but no recomputation. |
|
534 |
for example a name |
|
535 |
" |
|
536 |
self dependents do:[:aDependent| |
|
537 |
aDependent isView ifTrue:[ aDependent invalidate ] |
|
538 |
]. |
|
539 |
||
540 |
||
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
541 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
542 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
543 |
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
|
544 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
545 |
self dependents do:[:aDependent| |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
546 |
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
|
547 |
] |
758 | 548 |
! ! |
549 |
||
458 | 550 |
!SelectionInTree methodsFor:'enumerating'! |
551 |
||
552 |
each:something do:aBlock |
|
553 |
"evaluate a block for something or in case of a collection for each |
|
554 |
element in the collection |
|
555 |
" |
|
556 |
something notNil ifTrue:[ |
|
557 |
something isCollection ifTrue:[something do:[:el|aBlock value:el]] |
|
558 |
ifFalse:[aBlock value:something] |
|
559 |
] |
|
560 |
||
561 |
! ! |
|
562 |
||
496 | 563 |
!SelectionInTree methodsFor:'initialization'! |
564 |
||
565 |
initialize |
|
811 | 566 |
|
1166
d062a52bc7cc
list attribute changed from OrderedCollection to List
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
567 |
showRoot := true. |
811 | 568 |
indicatorList := OrderedCollection new. |
569 |
accessLock := Semaphore forMutualExclusion. |
|
1166
d062a52bc7cc
list attribute changed from OrderedCollection to List
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
570 |
list := List new. |
d062a52bc7cc
list attribute changed from OrderedCollection to List
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
571 |
|
496 | 572 |
super initialize. |
811 | 573 |
|
496 | 574 |
! ! |
575 |
||
458 | 576 |
!SelectionInTree methodsFor:'private'! |
577 |
||
578 |
recomputeList |
|
579 |
"Travers the tree and build a new list." |
|
580 |
||
857 | 581 |
self listFromRoot. |
582 |
self changed:#list. |
|
583 |
! ! |
|
584 |
||
585 |
!SelectionInTree methodsFor:'private hierarchy'! |
|
586 |
||
587 |
collapseItem:anItem do:collapseBlock |
|
588 |
"collapse all children under an item; raise a notification if |
|
589 |
the list changed |
|
590 |
" |
|
591 |
|start stop size| |
|
592 |
||
593 |
anItem isCollapsable ifFalse:[ |
|
594 |
^ self |
|
595 |
]. |
|
596 |
||
597 |
(start := self indexOf:anItem) == 0 ifTrue:[ |
|
598 |
"/ |
|
599 |
"/ item not visible |
|
600 |
"/ |
|
601 |
collapseBlock value. |
|
602 |
] ifFalse:[ |
|
603 |
size := anItem numberOfAllVisibleChildren. |
|
604 |
collapseBlock value. |
|
605 |
||
606 |
size == 0 ifTrue:[ |
|
607 |
"/ |
|
608 |
"/ no children before; list not changed |
|
609 |
"/ |
|
610 |
self changed:#at: with:start |
|
611 |
] ifFalse:[ |
|
612 |
stop := start + size. |
|
613 |
start := start + 1. |
|
614 |
list removeFromIndex:start toIndex:stop. |
|
860 | 615 |
self changed:#removeFrom: with:(Array with:start with:stop with:anItem). |
857 | 616 |
] |
617 |
] |
|
618 |
! |
|
619 |
||
620 |
expandItem:anItem do:expandBlock |
|
621 |
"expand all children under an item; raise a notification if |
|
622 |
the list changed |
|
623 |
" |
|
624 |
|start size pList| |
|
625 |
||
626 |
anItem isExpandable ifFalse:[ |
|
627 |
^ self |
|
628 |
]. |
|
629 |
expandBlock value. |
|
630 |
||
631 |
(start := self indexOf:anItem) ~~ 0 ifTrue:[ |
|
632 |
anItem addVisibleChildrenTo:(pList := OrderedCollection new:2048). |
|
633 |
||
634 |
(size := pList size) ~~ 0 ifTrue:[ |
|
635 |
start := 1 + start. |
|
636 |
list addAll:pList beforeIndex:start. |
|
637 |
||
638 |
self changed:#insertCollection: |
|
639 |
with:(Array with:start with:size with:anItem). |
|
640 |
] ifFalse:[ |
|
641 |
self changed:#at: with:start |
|
642 |
] |
|
643 |
] |
|
644 |
! |
|
645 |
||
646 |
listFromRoot |
|
1204 | 647 |
"Traverse the tree and build a new list; |
857 | 648 |
no change notification is raised |
649 |
" |
|
842 | 650 |
list clearContents. |
458 | 651 |
|
652 |
root notNil ifTrue:[ |
|
857 | 653 |
showRoot ifTrue:[ list add:root ]. |
654 |
root addVisibleChildrenTo:list |
|
655 |
] |
|
656 |
||
657 |
! ! |
|
658 |
||
659 |
!SelectionInTree methodsFor:'queries'! |
|
660 |
||
661 |
indexOf:anItem |
|
662 |
"returns the index of an item or 0 |
|
663 |
" |
|
664 |
^ anItem notNil ifTrue:[list identityIndexOf:anItem] |
|
665 |
ifFalse:[0] |
|
458 | 666 |
! ! |
667 |
||
849 | 668 |
!SelectionInTree methodsFor:'searching'! |
669 |
||
670 |
detectItem:aOneArgBlock |
|
671 |
"detect an item the evaluation of the block returns true. The |
|
672 |
argument to the block is the item. |
|
673 |
" |
|
674 |
root notNil ifTrue:[ |
|
675 |
^ root detectChild:aOneArgBlock |
|
676 |
]. |
|
677 |
^ nil |
|
678 |
||
679 |
||
680 |
! |
|
681 |
||
682 |
detectItem:aTwoArgBlock arguments:aListOfArgs |
|
683 |
"detect an item the evaluation of the block returns true. The |
|
684 |
first argument to the block is the item, the second argument |
|
685 |
the value derived from the argument list at an index |
|
686 |
" |
|
687 |
root notNil ifTrue:[ |
|
688 |
^ root detectChild:aTwoArgBlock arguments:aListOfArgs index:1 |
|
689 |
]. |
|
690 |
^ nil |
|
691 |
||
692 |
||
693 |
! ! |
|
694 |
||
458 | 695 |
!SelectionInTree methodsFor:'selection'! |
696 |
||
1213 | 697 |
selectNode:aNode |
698 |
|index| |
|
699 |
||
700 |
(index := self indexOf:aNode) ~~ 0 ifTrue:[ |
|
701 |
self selectionIndex:index |
|
702 |
] |
|
703 |
! |
|
704 |
||
1234 | 705 |
selectNodes:aCollectionOfNodes |
706 |
| indices| |
|
707 |
||
708 |
indices := aCollectionOfNodes collect:[:aNode | self indexOf:aNode]. |
|
709 |
indices := indices select:[:idx | idx ~~ 0]. |
|
710 |
indices sort. |
|
711 |
self selectionIndex:indices |
|
712 |
||
713 |
"Created: / 6.3.1999 / 22:37:59 / cg" |
|
714 |
! |
|
715 |
||
906 | 716 |
selectedNode |
717 |
"returns selected node or nil |
|
718 |
" |
|
719 |
|nodes| |
|
720 |
(nodes := self selectedNodes) notNil ifTrue: [ |
|
721 |
^nodes first |
|
722 |
]. |
|
723 |
^nil |
|
724 |
||
725 |
||
726 |
! |
|
727 |
||
857 | 728 |
selectedNodes |
729 |
"returns list of selected nodes or nil |
|
730 |
" |
|
731 |
|node coll| |
|
732 |
||
733 |
selection isNil ifTrue:[ |
|
734 |
^ nil |
|
735 |
]. |
|
736 |
||
737 |
selection isCollection ifFalse:[ |
|
738 |
node := list at:selection ifAbsent:nil. |
|
739 |
^ node notNil ifTrue:[Array with:node] ifFalse:[nil] |
|
740 |
]. |
|
741 |
||
742 |
selection isEmpty ifTrue:[ |
|
743 |
^ nil |
|
744 |
]. |
|
745 |
||
746 |
coll := OrderedCollection new:(selection size). |
|
747 |
||
748 |
selection do:[:idx| |
|
749 |
(node := list at:idx ifAbsent:nil) notNil ifTrue:[ |
|
750 |
coll add:node |
|
751 |
] |
|
752 |
]. |
|
753 |
^ coll notEmpty ifTrue:[coll] ifFalse:[nil] |
|
754 |
||
755 |
! |
|
756 |
||
458 | 757 |
selection |
758 |
"get the selection or nil |
|
759 |
" |
|
760 |
^ self selectionIndex |
|
761 |
! |
|
762 |
||
763 |
selection:indexesOrNil |
|
764 |
"set the selection |
|
765 |
" |
|
766 |
self selectionIndex:indexesOrNil |
|
767 |
! |
|
768 |
||
769 |
selectionIndex |
|
770 |
"get the selection or nil |
|
771 |
" |
|
772 |
^ selection |
|
773 |
! |
|
774 |
||
775 |
selectionIndex:indexesOrNil |
|
776 |
"set the selection |
|
777 |
" |
|
496 | 778 |
|oldSel| |
779 |
||
780 |
oldSel := selection. |
|
781 |
self setSelectionIndex:indexesOrNil. |
|
782 |
||
783 |
oldSel = selection ifFalse:[ |
|
585 | 784 |
self changed:#selectionIndex |
496 | 785 |
] |
786 |
! |
|
787 |
||
788 |
setSelection:indexesOrNil |
|
789 |
"set the selection without raising a notification |
|
790 |
" |
|
791 |
self setSelectionIndex:indexesOrNil |
|
792 |
! |
|
793 |
||
794 |
setSelectionIndex:indexesOrNil |
|
795 |
"set the selection without raising a notification |
|
796 |
" |
|
458 | 797 |
|indexes| |
798 |
||
799 |
indexes := indexesOrNil. |
|
800 |
||
801 |
indexes size == 0 ifTrue:[ |
|
802 |
(indexes isCollection or:[indexes == 0]) ifTrue:[ |
|
803 |
indexes := nil |
|
804 |
] |
|
805 |
]. |
|
496 | 806 |
selection := indexes |
458 | 807 |
|
808 |
! ! |
|
809 |
||
811 | 810 |
!SelectionInTree methodsFor:'update indication task'! |
811 |
||
812 |
startIndicatorValidationFor:aNode |
|
813 |
"add a node to list of updating indications |
|
814 |
" |
|
815 |
|index| |
|
816 |
||
817 |
accessLock critical:[ |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
818 |
|prio| |
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
819 |
|
811 | 820 |
index := indicatorList identityIndexOf:aNode. |
821 |
||
822 |
index ~~ 0 ifTrue:[ |
|
823 |
indicatorList removeIndex:index. "/ reorganize list to be faster |
|
824 |
]. |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
825 |
indicatorList addLast: "addFirst:" aNode. |
811 | 826 |
|
827 |
indicatorTask isNil ifTrue:[ |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
828 |
prio := Processor activePriority. |
811 | 829 |
indicatorTask := [ |
830 |
[ 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
|
831 |
] forkAt:(prio - 1). |
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
832 |
indicatorTask priorityRange:(prio-1 to:prio). |
811 | 833 |
] |
834 |
]. |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
835 |
|
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
836 |
"Modified: / 26.9.1998 / 15:20:44 / cg" |
811 | 837 |
! |
838 |
||
839 |
stopIndicatorValidationFor:aNodeOrList |
|
840 |
"remove a node or list of nodes from list of updating indications |
|
841 |
" |
|
842 |
accessLock critical:[ |
|
843 |
aNodeOrList isCollection ifTrue:[ |
|
844 |
aNodeOrList do:[:aNode| |
|
845 |
indicatorList removeIdentical:aNode ifAbsent:nil |
|
846 |
] |
|
847 |
] ifFalse:[ |
|
848 |
indicatorList removeIdentical:aNodeOrList ifAbsent:nil |
|
849 |
] |
|
850 |
] |
|
851 |
||
852 |
||
853 |
! |
|
854 |
||
855 |
stopRunningTasks |
|
856 |
"stop task |
|
857 |
" |
|
858 |
accessLock critical:[ indicatorList removeAll ] |
|
859 |
||
860 |
! |
|
861 |
||
862 |
taskCycle |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
863 |
"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
|
864 |
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
|
865 |
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
|
866 |
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
|
867 |
|
811 | 868 |
|node| |
869 |
||
870 |
accessLock critical:[ |
|
871 |
indicatorList isEmpty ifTrue:[ "/ queue is empty; terminate task |
|
872 |
indicatorTask := nil. |
|
873 |
^ false |
|
874 |
]. |
|
875 |
node := indicatorList removeFirst. "/ run task on first node |
|
876 |
node hasValidIndicator ifTrue:[ "/ up to date |
|
877 |
^ true |
|
878 |
]. |
|
879 |
node setShowIndicator:false "/ disable registry |
|
880 |
]. |
|
881 |
||
1145 | 882 |
(DirectoryContents |
883 |
directoryNamed:(node fileName) |
|
884 |
detect:(node matchAction)) |
|
885 |
ifTrue:[ |
|
811 | 886 |
node showIndicator:true |
887 |
]. |
|
888 |
^ true |
|
1145 | 889 |
|
1155
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:11:16 / cg" |
811 | 891 |
! ! |
892 |
||
458 | 893 |
!SelectionInTree class methodsFor:'documentation'! |
894 |
||
895 |
version |
|
1268 | 896 |
^ '$Header: /cvs/stx/stx/libwidg2/Attic/SelInTree.st,v 1.26 1999-03-19 21:18:32 cg Exp $' |
458 | 897 |
! ! |