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