author | ca |
Sat, 31 Oct 1998 13:03:29 +0100 | |
changeset 1174 | 8d0c73401ea8 |
parent 1166 | d062a52bc7cc |
child 1176 | cd9fc4bfb273 |
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 |
|
44 |
to buildup file-trees, class tress etc. |
|
45 |
||
46 |
Especially suited for use with SelectionInTreeView. |
|
47 |
||
48 |
[See also:] |
|
49 |
TreeItem |
|
50 |
SelectionInTreeView |
|
51 |
||
52 |
[Author:] |
|
53 |
W. Olberding |
|
54 |
Claus Atzkern |
|
55 |
" |
|
56 |
! ! |
|
57 |
||
811 | 58 |
!SelectionInTree class methodsFor:'instance creation'! |
59 |
||
60 |
new |
|
61 |
^ super new initialize |
|
62 |
! ! |
|
63 |
||
1174 | 64 |
!SelectionInTree class methodsFor:'defaults'! |
65 |
||
66 |
defaultItemClass |
|
67 |
"returns the default item class or nil (the default) |
|
68 |
" |
|
69 |
^ nil |
|
70 |
||
71 |
||
72 |
||
73 |
! ! |
|
74 |
||
458 | 75 |
!SelectionInTree methodsFor:'accessing'! |
76 |
||
77 |
list |
|
78 |
"get list oc currently shown objects |
|
79 |
" |
|
80 |
^ list |
|
81 |
! |
|
82 |
||
83 |
root |
|
84 |
"get the root node |
|
85 |
" |
|
86 |
^ root |
|
87 |
! |
|
88 |
||
509 | 89 |
root:aRoot |
90 |
"set a new root |
|
458 | 91 |
" |
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
92 |
root notNil ifTrue: [ |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
93 |
root tree: nil |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
94 |
]. |
811 | 95 |
self stopRunningTasks. |
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
96 |
|
515 | 97 |
(root := aRoot) notNil ifTrue:[ |
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
98 |
root parent:nil. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
99 |
root tree: self. |
857 | 100 |
]. |
101 |
self listFromRoot. |
|
102 |
self changed:#list. |
|
860 | 103 |
! |
104 |
||
105 |
value |
|
106 |
^ list |
|
496 | 107 |
! ! |
491 | 108 |
|
496 | 109 |
!SelectionInTree methodsFor:'accessing behavior'! |
110 |
||
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
111 |
childrenAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
112 |
"get children action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
113 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
114 |
^childrenAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
115 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
116 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
117 |
childrenAction:aBlock |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
118 |
"set children action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
119 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
120 |
childrenAction := aBlock. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
121 |
! |
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 |
contentsAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
124 |
"get contents action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
125 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
126 |
^contentsAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
127 |
! |
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 |
contentsAction:aBlock |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
130 |
"set contents action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
131 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
132 |
contentsAction := aBlock. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
133 |
! |
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 |
iconAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
136 |
"get icon action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
137 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
138 |
^iconAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
139 |
! |
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 |
iconAction:aBlock |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
142 |
"set icon action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
143 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
144 |
iconAction := aBlock. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
145 |
! |
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 |
labelAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
148 |
"get label action block |
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 |
^labelAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
151 |
! |
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 |
labelAction:aBlock |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
154 |
"set label action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
155 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
156 |
labelAction := aBlock. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
157 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
158 |
|
496 | 159 |
showRoot |
160 |
"list with or without root |
|
161 |
" |
|
162 |
^ showRoot |
|
491 | 163 |
! |
164 |
||
496 | 165 |
showRoot:aState |
166 |
"list with or without root |
|
491 | 167 |
" |
496 | 168 |
aState ~~ showRoot ifTrue:[ |
169 |
showRoot := aState. |
|
491 | 170 |
|
496 | 171 |
root notNil ifTrue:[ |
857 | 172 |
aState ifTrue:[ |
173 |
list addFirst:root. |
|
174 |
self changed:#insertCollection: with:(Array with:1 with:1 with:nil). |
|
175 |
] ifFalse:[ |
|
176 |
list removeFirst. |
|
177 |
self changed:#removeFrom: with:(Array with:1 with:1 with:nil). |
|
178 |
]. |
|
491 | 179 |
]. |
180 |
]. |
|
458 | 181 |
! ! |
182 |
||
183 |
!SelectionInTree methodsFor:'accessing hierarchy'! |
|
184 |
||
185 |
collapse:something |
|
186 |
"collapse a node or collection of nodes |
|
187 |
" |
|
857 | 188 |
|listChanged| |
189 |
||
190 |
listChanged := false. |
|
458 | 191 |
|
192 |
self each:something do:[:aNode| |
|
193 |
aNode isCollapsable ifTrue:[ |
|
194 |
aNode collapse. |
|
857 | 195 |
listChanged := true |
458 | 196 |
] |
197 |
]. |
|
857 | 198 |
listChanged ifTrue:[ |
199 |
self listFromRoot. |
|
200 |
self changed:#list. |
|
201 |
] |
|
202 |
||
458 | 203 |
! |
204 |
||
509 | 205 |
expand |
206 |
"expand the root |
|
207 |
" |
|
208 |
self expand:root |
|
209 |
! |
|
210 |
||
458 | 211 |
expand:something |
212 |
"expand a node or collection of nodes |
|
213 |
" |
|
857 | 214 |
|listChanged| |
215 |
||
216 |
listChanged := false. |
|
458 | 217 |
|
218 |
self each:something do:[:aNode| |
|
219 |
aNode isExpandable ifTrue:[ |
|
220 |
aNode expand. |
|
857 | 221 |
listChanged := true |
458 | 222 |
] |
223 |
]. |
|
857 | 224 |
listChanged ifTrue:[ |
225 |
self listFromRoot. |
|
226 |
self changed:#list. |
|
227 |
] |
|
228 |
! ! |
|
229 |
||
230 |
!SelectionInTree methodsFor:'accessing hierarchy new'! |
|
231 |
||
232 |
doCollapse:something |
|
233 |
"collapse all children under an item or a sequence of items; |
|
234 |
if the list changed, notifications are raised |
|
235 |
" |
|
236 |
self each:something do:[:anItem| |
|
237 |
self collapseItem:anItem do:[ anItem collapse ] |
|
238 |
] |
|
239 |
! |
|
240 |
||
241 |
doCollapseAll:something |
|
242 |
"collapse all children and subChildren under an item or sequence of items; |
|
243 |
if the list changed, notifications are raised |
|
244 |
" |
|
245 |
self each:something do:[:anItem| |
|
246 |
self collapseItem:anItem do:[ anItem collapseAll ] |
|
247 |
] |
|
248 |
! |
|
249 |
||
250 |
doExpand:something |
|
251 |
"expand all children under an item or collection of items; |
|
252 |
if the list changed, notifications are raised |
|
253 |
" |
|
254 |
self each:something do:[:anItem| |
|
255 |
self expandItem:anItem do:[anItem expand] |
|
256 |
] |
|
257 |
! |
|
258 |
||
259 |
doExpandAll:something |
|
260 |
"expand all children and subChildren under an item or sequence of items; |
|
261 |
if the list changed, notifications are raised |
|
262 |
" |
|
263 |
self each:something do:[:anItem| |
|
264 |
self expandItem:anItem do:[anItem expandAll] |
|
265 |
] |
|
266 |
! |
|
267 |
||
268 |
doMakeVisible:something |
|
269 |
"make an item or list of items to become visible |
|
270 |
" |
|
271 |
|anchor parent| |
|
272 |
||
273 |
self each:something do:[:anItem| |
|
274 |
parent := anItem. |
|
275 |
anchor := nil. |
|
276 |
||
277 |
[(parent := parent parent) notNil] whileTrue:[ |
|
278 |
parent hidden ifTrue:[ |
|
279 |
anchor notNil ifTrue:[ anchor expand ]. |
|
280 |
anchor := parent. |
|
281 |
] |
|
282 |
]. |
|
283 |
anchor notNil ifTrue:[ |
|
284 |
self expandItem:anchor do:[anchor expand] |
|
285 |
] |
|
286 |
] |
|
458 | 287 |
! ! |
288 |
||
289 |
!SelectionInTree methodsFor:'adding & removing'! |
|
290 |
||
291 |
add:something after:aChild |
|
292 |
"add a node or collection of nodes to parent after a child |
|
293 |
" |
|
294 |
"add a node or collection of nodes to after a child |
|
295 |
" |
|
857 | 296 |
|p| |
297 |
||
298 |
(aChild notNil and:[(p := aChild parent) notNil]) ifTrue:[ |
|
299 |
self add:something afterIndex:(p indexOfChild:aChild) below:p |
|
458 | 300 |
] |
857 | 301 |
|
458 | 302 |
! |
303 |
||
304 |
add:something afterIndex:anIndex below:aParent |
|
305 |
"add a node or collection of nodes to parent after an index |
|
306 |
" |
|
857 | 307 |
self add:something beforeIndex:(anIndex + 1) below:aParent |
458 | 308 |
! |
309 |
||
310 |
add:something before:aChild |
|
311 |
"add a node or collection of nodes to before a child |
|
312 |
" |
|
857 | 313 |
|p| |
314 |
||
315 |
(aChild notNil and:[(p := aChild parent) notNil]) ifTrue:[ |
|
316 |
self add:something beforeIndex:(p indexOfChild:aChild) below:p |
|
458 | 317 |
] |
318 |
! |
|
319 |
||
320 |
add:something beforeIndex:anIndex below:aParent |
|
321 |
"add a node or collection of nodes to parent before an index |
|
322 |
" |
|
857 | 323 |
|children start index size pList| |
324 |
||
325 |
( aParent isNil |
|
326 |
or:[something isNil |
|
327 |
or:[(something isCollection and:[something isEmpty])]] |
|
328 |
) ifTrue:[ |
|
329 |
^ self |
|
330 |
]. |
|
331 |
||
332 |
(start := self indexOf:aParent) == 0 ifTrue:[ |
|
333 |
"/ |
|
334 |
"/ parent not visible; list not changed |
|
335 |
"/ |
|
336 |
aParent add:something beforeIndex:anIndex. |
|
337 |
^ self |
|
338 |
]. |
|
339 |
||
340 |
aParent shown ifFalse:[ |
|
341 |
aParent add:something beforeIndex:anIndex. |
|
342 |
self changed:#at: with:start. |
|
343 |
^ self |
|
344 |
]. |
|
345 |
children := aParent children. |
|
346 |
||
347 |
(children isEmpty or:[anIndex <= 1]) ifTrue:[ |
|
348 |
index := 1. |
|
349 |
] ifFalse:[ |
|
350 |
size := children size. |
|
351 |
||
352 |
anIndex > size ifTrue:[ |
|
353 |
index := size + 1. |
|
354 |
start := aParent numberOfAllVisibleChildren + start. |
|
355 |
] ifFalse:[ |
|
356 |
index := anIndex. |
|
357 |
start := (self indexOf:(children at:index)) - 1. |
|
358 |
] |
|
359 |
]. |
|
360 |
aParent add:something beforeIndex:index. |
|
361 |
||
362 |
(start := start + 1) == 0 ifTrue:[ |
|
363 |
"/ |
|
364 |
"/ not visible |
|
365 |
"/ |
|
366 |
^ self |
|
367 |
]. |
|
368 |
pList := OrderedCollection new:2048. |
|
369 |
||
370 |
self each:something do:[:aNode| |
|
371 |
pList add:aNode. |
|
372 |
aNode addVisibleChildrenTo:pList |
|
373 |
]. |
|
374 |
pList isEmpty ifTrue:[ |
|
375 |
^ self |
|
376 |
]. |
|
377 |
list addAll:pList beforeIndex:start. |
|
378 |
||
379 |
self changed:#insertCollection: |
|
380 |
with:(Array with:start with:pList size with:aParent). |
|
458 | 381 |
|
382 |
! |
|
383 |
||
384 |
add:something below:aParent |
|
385 |
"add a node or collection of nodes to parent |
|
386 |
" |
|
857 | 387 |
aParent notNil ifTrue:[ |
388 |
self add:something beforeIndex:(aParent numberOfChildren + 1) below:aParent |
|
389 |
] |
|
458 | 390 |
! |
391 |
||
392 |
remove:something |
|
393 |
"remove a node or collection of nodes |
|
394 |
" |
|
860 | 395 |
|node coll index loNums loItem start size parent stop| |
857 | 396 |
|
397 |
something isNil ifTrue:[ |
|
398 |
^ something |
|
399 |
]. |
|
400 |
loNums := SortedCollection new. |
|
401 |
||
402 |
self each:something do:[:el| |
|
403 |
node := el isNumber ifTrue:[list at:el ifAbsent:nil] |
|
404 |
ifFalse:[el]. |
|
405 |
||
406 |
node notNil ifTrue:[ |
|
407 |
self stopIndicatorValidationFor:node. |
|
458 | 408 |
|
857 | 409 |
node parent isNil ifTrue:[ |
410 |
"/ remove all including root |
|
411 |
node == root ifTrue:[ self root:nil ]. |
|
412 |
^ something |
|
413 |
]. |
|
414 |
index := self indexOf:node. |
|
811 | 415 |
|
857 | 416 |
index == 0 ifTrue:[ |
417 |
"/ not visible |
|
418 |
node parent removeChild:node |
|
419 |
] ifFalse:[ |
|
420 |
loNums add:index |
|
421 |
]. |
|
458 | 422 |
] |
423 |
]. |
|
857 | 424 |
|
425 |
loNums isEmpty ifTrue:[ |
|
426 |
"/ nothing visible changed |
|
427 |
^ something |
|
428 |
]. |
|
429 |
loItem := OrderedCollection new. |
|
430 |
loNums do:[:i| loItem add:(list at:i)]. |
|
431 |
||
432 |
loItem do:[:aNode| |
|
433 |
start := self indexOf:aNode. |
|
434 |
||
435 |
start ~~ 0 ifTrue:[ |
|
436 |
parent := aNode parent. |
|
437 |
size := 1 + aNode numberOfAllVisibleChildren. |
|
860 | 438 |
stop := start + size - 1. |
857 | 439 |
parent remove:aNode. |
860 | 440 |
list removeFromIndex:start toIndex:stop. |
811 | 441 |
|
857 | 442 |
self changed:#removeFrom: |
860 | 443 |
with:(Array with:start with:stop with:parent). |
857 | 444 |
] |
445 |
]. |
|
446 |
^ something |
|
447 |
! |
|
448 |
||
449 |
removeAllOtherThanRoot |
|
450 |
"remove all other than the root |
|
451 |
" |
|
452 |
|listChanged| |
|
453 |
||
454 |
root notNil ifTrue:[ |
|
455 |
listChanged := root isCollapsable. |
|
456 |
root children:(OrderedCollection new). |
|
457 |
||
458 |
listChanged ifTrue:[ |
|
459 |
self listFromRoot. |
|
460 |
self changed:#list |
|
461 |
] |
|
462 |
] |
|
458 | 463 |
! |
464 |
||
465 |
removeIndex:something |
|
466 |
"remove a node at index or collection of indexed nodes |
|
467 |
" |
|
857 | 468 |
self remove:something |
458 | 469 |
! |
470 |
||
471 |
removeSelection |
|
472 |
"remove selected nodes |
|
473 |
" |
|
857 | 474 |
|sel| |
475 |
||
476 |
sel := self selectionIndex. |
|
477 |
self selectionIndex:nil. |
|
478 |
self remove:sel. |
|
458 | 479 |
! ! |
480 |
||
758 | 481 |
!SelectionInTree methodsFor:'change & update'! |
482 |
||
483 |
invalidate |
|
484 |
"called; something changed what requires a redraw but no recomputation. |
|
485 |
for example a name |
|
486 |
" |
|
487 |
self dependents do:[:aDependent| |
|
488 |
aDependent isView ifTrue:[ aDependent invalidate ] |
|
489 |
]. |
|
490 |
||
491 |
||
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
492 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
493 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
494 |
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
|
495 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
496 |
self dependents do:[:aDependent| |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
497 |
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
|
498 |
] |
758 | 499 |
! ! |
500 |
||
458 | 501 |
!SelectionInTree methodsFor:'enumerating'! |
502 |
||
503 |
each:something do:aBlock |
|
504 |
"evaluate a block for something or in case of a collection for each |
|
505 |
element in the collection |
|
506 |
" |
|
507 |
something notNil ifTrue:[ |
|
508 |
something isCollection ifTrue:[something do:[:el|aBlock value:el]] |
|
509 |
ifFalse:[aBlock value:something] |
|
510 |
] |
|
511 |
||
512 |
! ! |
|
513 |
||
496 | 514 |
!SelectionInTree methodsFor:'initialization'! |
515 |
||
516 |
initialize |
|
811 | 517 |
|
1166
d062a52bc7cc
list attribute changed from OrderedCollection to List
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
518 |
showRoot := true. |
811 | 519 |
indicatorList := OrderedCollection new. |
520 |
accessLock := Semaphore forMutualExclusion. |
|
1166
d062a52bc7cc
list attribute changed from OrderedCollection to List
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
521 |
list := List new. |
d062a52bc7cc
list attribute changed from OrderedCollection to List
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
522 |
|
496 | 523 |
super initialize. |
811 | 524 |
|
496 | 525 |
! ! |
526 |
||
458 | 527 |
!SelectionInTree methodsFor:'private'! |
528 |
||
529 |
recomputeList |
|
530 |
"Travers the tree and build a new list." |
|
531 |
||
857 | 532 |
self listFromRoot. |
533 |
self changed:#list. |
|
534 |
! ! |
|
535 |
||
536 |
!SelectionInTree methodsFor:'private hierarchy'! |
|
537 |
||
538 |
collapseItem:anItem do:collapseBlock |
|
539 |
"collapse all children under an item; raise a notification if |
|
540 |
the list changed |
|
541 |
" |
|
542 |
|start stop size| |
|
543 |
||
544 |
anItem isCollapsable ifFalse:[ |
|
545 |
^ self |
|
546 |
]. |
|
547 |
||
548 |
(start := self indexOf:anItem) == 0 ifTrue:[ |
|
549 |
"/ |
|
550 |
"/ item not visible |
|
551 |
"/ |
|
552 |
collapseBlock value. |
|
553 |
] ifFalse:[ |
|
554 |
size := anItem numberOfAllVisibleChildren. |
|
555 |
collapseBlock value. |
|
556 |
||
557 |
size == 0 ifTrue:[ |
|
558 |
"/ |
|
559 |
"/ no children before; list not changed |
|
560 |
"/ |
|
561 |
self changed:#at: with:start |
|
562 |
] ifFalse:[ |
|
563 |
stop := start + size. |
|
564 |
start := start + 1. |
|
565 |
list removeFromIndex:start toIndex:stop. |
|
860 | 566 |
self changed:#removeFrom: with:(Array with:start with:stop with:anItem). |
857 | 567 |
] |
568 |
] |
|
569 |
! |
|
570 |
||
571 |
expandItem:anItem do:expandBlock |
|
572 |
"expand all children under an item; raise a notification if |
|
573 |
the list changed |
|
574 |
" |
|
575 |
|start size pList| |
|
576 |
||
577 |
anItem isExpandable ifFalse:[ |
|
578 |
^ self |
|
579 |
]. |
|
580 |
expandBlock value. |
|
581 |
||
582 |
(start := self indexOf:anItem) ~~ 0 ifTrue:[ |
|
583 |
anItem addVisibleChildrenTo:(pList := OrderedCollection new:2048). |
|
584 |
||
585 |
(size := pList size) ~~ 0 ifTrue:[ |
|
586 |
start := 1 + start. |
|
587 |
list addAll:pList beforeIndex:start. |
|
588 |
||
589 |
self changed:#insertCollection: |
|
590 |
with:(Array with:start with:size with:anItem). |
|
591 |
] ifFalse:[ |
|
592 |
self changed:#at: with:start |
|
593 |
] |
|
594 |
] |
|
595 |
! |
|
596 |
||
597 |
listFromRoot |
|
598 |
"Travers the tree and build a new list; |
|
599 |
no change notification is raised |
|
600 |
" |
|
842 | 601 |
list clearContents. |
458 | 602 |
|
603 |
root notNil ifTrue:[ |
|
857 | 604 |
showRoot ifTrue:[ list add:root ]. |
605 |
root addVisibleChildrenTo:list |
|
606 |
] |
|
607 |
||
608 |
! ! |
|
609 |
||
610 |
!SelectionInTree methodsFor:'queries'! |
|
611 |
||
612 |
indexOf:anItem |
|
613 |
"returns the index of an item or 0 |
|
614 |
" |
|
615 |
^ anItem notNil ifTrue:[list identityIndexOf:anItem] |
|
616 |
ifFalse:[0] |
|
458 | 617 |
! ! |
618 |
||
849 | 619 |
!SelectionInTree methodsFor:'searching'! |
620 |
||
621 |
detectItem:aOneArgBlock |
|
622 |
"detect an item the evaluation of the block returns true. The |
|
623 |
argument to the block is the item. |
|
624 |
" |
|
625 |
root notNil ifTrue:[ |
|
626 |
^ root detectChild:aOneArgBlock |
|
627 |
]. |
|
628 |
^ nil |
|
629 |
||
630 |
||
631 |
! |
|
632 |
||
633 |
detectItem:aTwoArgBlock arguments:aListOfArgs |
|
634 |
"detect an item the evaluation of the block returns true. The |
|
635 |
first argument to the block is the item, the second argument |
|
636 |
the value derived from the argument list at an index |
|
637 |
" |
|
638 |
root notNil ifTrue:[ |
|
639 |
^ root detectChild:aTwoArgBlock arguments:aListOfArgs index:1 |
|
640 |
]. |
|
641 |
^ nil |
|
642 |
||
643 |
||
644 |
! ! |
|
645 |
||
458 | 646 |
!SelectionInTree methodsFor:'selection'! |
647 |
||
906 | 648 |
selectedNode |
649 |
"returns selected node or nil |
|
650 |
" |
|
651 |
|nodes| |
|
652 |
(nodes := self selectedNodes) notNil ifTrue: [ |
|
653 |
^nodes first |
|
654 |
]. |
|
655 |
^nil |
|
656 |
||
657 |
||
658 |
! |
|
659 |
||
857 | 660 |
selectedNodes |
661 |
"returns list of selected nodes or nil |
|
662 |
" |
|
663 |
|node coll| |
|
664 |
||
665 |
selection isNil ifTrue:[ |
|
666 |
^ nil |
|
667 |
]. |
|
668 |
||
669 |
selection isCollection ifFalse:[ |
|
670 |
node := list at:selection ifAbsent:nil. |
|
671 |
^ node notNil ifTrue:[Array with:node] ifFalse:[nil] |
|
672 |
]. |
|
673 |
||
674 |
selection isEmpty ifTrue:[ |
|
675 |
^ nil |
|
676 |
]. |
|
677 |
||
678 |
coll := OrderedCollection new:(selection size). |
|
679 |
||
680 |
selection do:[:idx| |
|
681 |
(node := list at:idx ifAbsent:nil) notNil ifTrue:[ |
|
682 |
coll add:node |
|
683 |
] |
|
684 |
]. |
|
685 |
^ coll notEmpty ifTrue:[coll] ifFalse:[nil] |
|
686 |
||
687 |
! |
|
688 |
||
458 | 689 |
selection |
690 |
"get the selection or nil |
|
691 |
" |
|
692 |
^ self selectionIndex |
|
693 |
! |
|
694 |
||
695 |
selection:indexesOrNil |
|
696 |
"set the selection |
|
697 |
" |
|
698 |
self selectionIndex:indexesOrNil |
|
699 |
! |
|
700 |
||
701 |
selectionIndex |
|
702 |
"get the selection or nil |
|
703 |
" |
|
704 |
^ selection |
|
705 |
! |
|
706 |
||
707 |
selectionIndex:indexesOrNil |
|
708 |
"set the selection |
|
709 |
" |
|
496 | 710 |
|oldSel| |
711 |
||
712 |
oldSel := selection. |
|
713 |
self setSelectionIndex:indexesOrNil. |
|
714 |
||
715 |
oldSel = selection ifFalse:[ |
|
585 | 716 |
self changed:#selectionIndex |
496 | 717 |
] |
718 |
! |
|
719 |
||
720 |
setSelection:indexesOrNil |
|
721 |
"set the selection without raising a notification |
|
722 |
" |
|
723 |
self setSelectionIndex:indexesOrNil |
|
724 |
! |
|
725 |
||
726 |
setSelectionIndex:indexesOrNil |
|
727 |
"set the selection without raising a notification |
|
728 |
" |
|
458 | 729 |
|indexes| |
730 |
||
731 |
indexes := indexesOrNil. |
|
732 |
||
733 |
indexes size == 0 ifTrue:[ |
|
734 |
(indexes isCollection or:[indexes == 0]) ifTrue:[ |
|
735 |
indexes := nil |
|
736 |
] |
|
737 |
]. |
|
496 | 738 |
selection := indexes |
458 | 739 |
|
740 |
! ! |
|
741 |
||
811 | 742 |
!SelectionInTree methodsFor:'update indication task'! |
743 |
||
744 |
startIndicatorValidationFor:aNode |
|
745 |
"add a node to list of updating indications |
|
746 |
" |
|
747 |
|index| |
|
748 |
||
749 |
accessLock critical:[ |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
750 |
|prio| |
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
751 |
|
811 | 752 |
index := indicatorList identityIndexOf:aNode. |
753 |
||
754 |
index ~~ 0 ifTrue:[ |
|
755 |
indicatorList removeIndex:index. "/ reorganize list to be faster |
|
756 |
]. |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
757 |
indicatorList addLast: "addFirst:" aNode. |
811 | 758 |
|
759 |
indicatorTask isNil ifTrue:[ |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
760 |
prio := Processor activePriority. |
811 | 761 |
indicatorTask := [ |
762 |
[ 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
|
763 |
] forkAt:(prio - 1). |
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
764 |
indicatorTask priorityRange:(prio-1 to:prio). |
811 | 765 |
] |
766 |
]. |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
767 |
|
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
768 |
"Modified: / 26.9.1998 / 15:20:44 / cg" |
811 | 769 |
! |
770 |
||
771 |
stopIndicatorValidationFor:aNodeOrList |
|
772 |
"remove a node or list of nodes from list of updating indications |
|
773 |
" |
|
774 |
accessLock critical:[ |
|
775 |
aNodeOrList isCollection ifTrue:[ |
|
776 |
aNodeOrList do:[:aNode| |
|
777 |
indicatorList removeIdentical:aNode ifAbsent:nil |
|
778 |
] |
|
779 |
] ifFalse:[ |
|
780 |
indicatorList removeIdentical:aNodeOrList ifAbsent:nil |
|
781 |
] |
|
782 |
] |
|
783 |
||
784 |
||
785 |
! |
|
786 |
||
787 |
stopRunningTasks |
|
788 |
"stop task |
|
789 |
" |
|
790 |
accessLock critical:[ indicatorList removeAll ] |
|
791 |
||
792 |
! |
|
793 |
||
794 |
taskCycle |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
795 |
"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
|
796 |
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
|
797 |
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
|
798 |
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
|
799 |
|
811 | 800 |
|node| |
801 |
||
802 |
accessLock critical:[ |
|
803 |
indicatorList isEmpty ifTrue:[ "/ queue is empty; terminate task |
|
804 |
indicatorTask := nil. |
|
805 |
^ false |
|
806 |
]. |
|
807 |
node := indicatorList removeFirst. "/ run task on first node |
|
808 |
node hasValidIndicator ifTrue:[ "/ up to date |
|
809 |
^ true |
|
810 |
]. |
|
811 |
node setShowIndicator:false "/ disable registry |
|
812 |
]. |
|
813 |
||
1145 | 814 |
(DirectoryContents |
815 |
directoryNamed:(node fileName) |
|
816 |
detect:(node matchAction)) |
|
817 |
ifTrue:[ |
|
811 | 818 |
node showIndicator:true |
819 |
]. |
|
820 |
^ true |
|
1145 | 821 |
|
1155
ff5b146ca277
run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
822 |
"Modified: / 26.9.1998 / 15:11:16 / cg" |
811 | 823 |
! ! |
824 |
||
458 | 825 |
!SelectionInTree class methodsFor:'documentation'! |
826 |
||
827 |
version |
|
1174 | 828 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTree.st,v 1.19 1998-10-31 12:03:29 ca Exp $' |
458 | 829 |
! ! |