author | tz |
Sat, 14 Feb 1998 17:15:32 +0100 | |
changeset 762 | df337e82f064 |
parent 758 | 0f0b16a16fa7 |
child 811 | a688e8f11bc6 |
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 |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
17 |
childrenAction iconAction' |
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 |
||
58 |
!SelectionInTree methodsFor:'accessing'! |
|
59 |
||
60 |
list |
|
61 |
"get list oc currently shown objects |
|
62 |
" |
|
63 |
^ list |
|
64 |
! |
|
65 |
||
66 |
root |
|
67 |
"get the root node |
|
68 |
" |
|
69 |
^ root |
|
70 |
! |
|
71 |
||
509 | 72 |
root:aRoot |
73 |
"set a new root |
|
458 | 74 |
" |
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
75 |
root notNil ifTrue: [ |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
76 |
root tree: nil |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
77 |
]. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
78 |
|
515 | 79 |
(root := aRoot) notNil ifTrue:[ |
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
80 |
root parent:nil. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
81 |
root tree: self. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
82 |
]. |
496 | 83 |
self recomputeList. |
84 |
||
85 |
! ! |
|
491 | 86 |
|
496 | 87 |
!SelectionInTree methodsFor:'accessing behavior'! |
88 |
||
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
89 |
childrenAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
90 |
"get children action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
91 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
92 |
^childrenAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
93 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
94 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
95 |
childrenAction:aBlock |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
96 |
"set children action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
97 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
98 |
childrenAction := aBlock. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
99 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
100 |
self changed:#list. |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
101 |
|
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 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
104 |
contentsAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
105 |
"get contents action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
106 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
107 |
^contentsAction |
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 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
110 |
contentsAction:aBlock |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
111 |
"set contents action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
112 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
113 |
contentsAction := aBlock. |
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 |
self changed:#list. |
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 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
119 |
iconAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
120 |
"get icon action block |
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 |
^iconAction |
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 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
125 |
iconAction:aBlock |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
126 |
"set icon action block |
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 |
iconAction := aBlock. |
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 |
self changed:#list. |
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 |
! |
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 |
labelAction |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
135 |
"get label action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
136 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
137 |
^labelAction |
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 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
140 |
labelAction:aBlock |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
141 |
"set label action block |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
142 |
" |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
143 |
labelAction := aBlock. |
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 |
self changed:#list. |
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 |
|
496 | 149 |
showRoot |
150 |
"list with or without root |
|
151 |
" |
|
152 |
^ showRoot |
|
491 | 153 |
! |
154 |
||
496 | 155 |
showRoot:aState |
156 |
"list with or without root |
|
491 | 157 |
" |
496 | 158 |
aState ~~ showRoot ifTrue:[ |
159 |
showRoot := aState. |
|
491 | 160 |
|
496 | 161 |
root notNil ifTrue:[ |
162 |
aState ifTrue:[list addFirst:root] |
|
163 |
ifFalse:[list removeFirst]. |
|
491 | 164 |
|
496 | 165 |
self changed:#list. |
491 | 166 |
]. |
167 |
]. |
|
458 | 168 |
! ! |
169 |
||
170 |
!SelectionInTree methodsFor:'accessing hierarchy'! |
|
171 |
||
172 |
collapse:something |
|
173 |
"collapse a node or collection of nodes |
|
174 |
" |
|
175 |
|invalidate| |
|
176 |
||
177 |
self each:something do:[:aNode| |
|
178 |
aNode isCollapsable ifTrue:[ |
|
179 |
aNode collapse. |
|
180 |
invalidate := true |
|
181 |
] |
|
182 |
]. |
|
183 |
invalidate == true ifTrue:[self recomputeList] |
|
184 |
! |
|
185 |
||
509 | 186 |
expand |
187 |
"expand the root |
|
188 |
" |
|
189 |
self expand:root |
|
190 |
! |
|
191 |
||
458 | 192 |
expand:something |
193 |
"expand a node or collection of nodes |
|
194 |
" |
|
195 |
|invalidate| |
|
196 |
||
197 |
self each:something do:[:aNode| |
|
198 |
aNode isExpandable ifTrue:[ |
|
199 |
aNode expand. |
|
200 |
invalidate := true |
|
201 |
] |
|
202 |
]. |
|
203 |
invalidate == true ifTrue:[self recomputeList] |
|
204 |
! ! |
|
205 |
||
206 |
!SelectionInTree methodsFor:'adding & removing'! |
|
207 |
||
208 |
add:something after:aChild |
|
209 |
"add a node or collection of nodes to parent after a child |
|
210 |
" |
|
211 |
"add a node or collection of nodes to after a child |
|
212 |
" |
|
213 |
aChild notNil ifTrue:[ |
|
214 |
aChild parent add:something after:aChild. |
|
215 |
self recomputeList |
|
216 |
] |
|
217 |
! |
|
218 |
||
219 |
add:something afterIndex:anIndex below:aParent |
|
220 |
"add a node or collection of nodes to parent after an index |
|
221 |
" |
|
222 |
aParent add:something afterIndex:anIndex. |
|
223 |
self recomputeList |
|
224 |
||
225 |
! |
|
226 |
||
227 |
add:something before:aChild |
|
228 |
"add a node or collection of nodes to before a child |
|
229 |
" |
|
230 |
aChild notNil ifTrue:[ |
|
231 |
aChild parent add:something before:aChild. |
|
232 |
self recomputeList |
|
233 |
] |
|
234 |
! |
|
235 |
||
236 |
add:something beforeIndex:anIndex below:aParent |
|
237 |
"add a node or collection of nodes to parent before an index |
|
238 |
" |
|
239 |
aParent add:something beforeIndex:anIndex. |
|
240 |
self recomputeList |
|
241 |
||
242 |
! |
|
243 |
||
244 |
add:something below:aParent |
|
245 |
"add a node or collection of nodes to parent |
|
246 |
" |
|
247 |
aParent add:something. |
|
248 |
self recomputeList |
|
249 |
||
250 |
! |
|
251 |
||
252 |
remove:something |
|
253 |
"remove a node or collection of nodes |
|
254 |
" |
|
255 |
|invalidate| |
|
256 |
||
257 |
self each:something do:[:aNode| |
|
258 |
aNode parent notNil ifTrue:[ |
|
259 |
aNode parent remove:aNode. |
|
260 |
invalidate := true |
|
261 |
] |
|
262 |
]. |
|
263 |
invalidate == true ifTrue:[self recomputeList]. |
|
264 |
^ something |
|
265 |
! |
|
266 |
||
267 |
removeIndex:something |
|
268 |
"remove a node at index or collection of indexed nodes |
|
269 |
" |
|
270 |
|invalidate node| |
|
271 |
||
272 |
something isCollection ifFalse:[ |
|
273 |
(something isNil or:[something == 0]) ifFalse:[ |
|
274 |
^ self remove:(list at:something) |
|
275 |
]. |
|
276 |
^ nil |
|
277 |
]. |
|
278 |
||
279 |
(SortedCollection withAll:something) reverseDo:[:anIndex| |
|
280 |
node := list at:anIndex. |
|
281 |
||
282 |
node parent notNil ifTrue:[ |
|
283 |
node parent remove:node. |
|
284 |
invalidate := true |
|
285 |
] |
|
286 |
]. |
|
287 |
invalidate == true ifTrue:[self recomputeList]. |
|
288 |
! |
|
289 |
||
290 |
removeSelection |
|
291 |
"remove selected nodes |
|
292 |
" |
|
293 |
self removeIndex:(self selectionIndex). |
|
294 |
self selectionIndex:nil |
|
295 |
! ! |
|
296 |
||
758 | 297 |
!SelectionInTree methodsFor:'change & update'! |
298 |
||
299 |
invalidate |
|
300 |
"called; something changed what requires a redraw but no recomputation. |
|
301 |
for example a name |
|
302 |
" |
|
303 |
self dependents do:[:aDependent| |
|
304 |
aDependent isView ifTrue:[ aDependent invalidate ] |
|
305 |
]. |
|
306 |
||
307 |
||
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
308 |
! |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
309 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
310 |
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
|
311 |
|
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
312 |
self dependents do:[:aDependent| |
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
313 |
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
|
314 |
] |
758 | 315 |
! ! |
316 |
||
458 | 317 |
!SelectionInTree methodsFor:'enumerating'! |
318 |
||
319 |
each:something do:aBlock |
|
320 |
"evaluate a block for something or in case of a collection for each |
|
321 |
element in the collection |
|
322 |
" |
|
323 |
something notNil ifTrue:[ |
|
324 |
something isCollection ifTrue:[something do:[:el|aBlock value:el]] |
|
325 |
ifFalse:[aBlock value:something] |
|
326 |
] |
|
327 |
||
328 |
! ! |
|
329 |
||
496 | 330 |
!SelectionInTree methodsFor:'initialization'! |
331 |
||
332 |
initialize |
|
333 |
super initialize. |
|
334 |
showRoot := true. |
|
335 |
! ! |
|
336 |
||
458 | 337 |
!SelectionInTree methodsFor:'private'! |
338 |
||
339 |
recomputeList |
|
340 |
"Travers the tree and build a new list." |
|
341 |
||
342 |
list := OrderedCollection new. |
|
343 |
||
344 |
root notNil ifTrue:[ |
|
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
345 |
showRoot ifTrue:[ |
496 | 346 |
list add:root |
347 |
]. |
|
458 | 348 |
root recomputeList:list |
349 |
]. |
|
585 | 350 |
self changed:#list. |
458 | 351 |
! ! |
352 |
||
353 |
!SelectionInTree methodsFor:'selection'! |
|
354 |
||
355 |
selection |
|
356 |
"get the selection or nil |
|
357 |
" |
|
358 |
^ self selectionIndex |
|
359 |
! |
|
360 |
||
361 |
selection:indexesOrNil |
|
362 |
"set the selection |
|
363 |
" |
|
364 |
self selectionIndex:indexesOrNil |
|
365 |
! |
|
366 |
||
367 |
selectionIndex |
|
368 |
"get the selection or nil |
|
369 |
" |
|
370 |
^ selection |
|
371 |
! |
|
372 |
||
373 |
selectionIndex:indexesOrNil |
|
374 |
"set the selection |
|
375 |
" |
|
496 | 376 |
|oldSel| |
377 |
||
378 |
oldSel := selection. |
|
379 |
self setSelectionIndex:indexesOrNil. |
|
380 |
||
381 |
oldSel = selection ifFalse:[ |
|
585 | 382 |
self changed:#selectionIndex |
496 | 383 |
] |
384 |
! |
|
385 |
||
386 |
setSelection:indexesOrNil |
|
387 |
"set the selection without raising a notification |
|
388 |
" |
|
389 |
self setSelectionIndex:indexesOrNil |
|
390 |
! |
|
391 |
||
392 |
setSelectionIndex:indexesOrNil |
|
393 |
"set the selection without raising a notification |
|
394 |
" |
|
458 | 395 |
|indexes| |
396 |
||
397 |
indexes := indexesOrNil. |
|
398 |
||
399 |
indexes size == 0 ifTrue:[ |
|
400 |
(indexes isCollection or:[indexes == 0]) ifTrue:[ |
|
401 |
indexes := nil |
|
402 |
] |
|
403 |
]. |
|
496 | 404 |
selection := indexes |
458 | 405 |
|
406 |
! ! |
|
407 |
||
408 |
!SelectionInTree class methodsFor:'documentation'! |
|
409 |
||
410 |
version |
|
762
df337e82f064
supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents:
758
diff
changeset
|
411 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTree.st,v 1.9 1998-02-14 16:15:32 tz Exp $' |
458 | 412 |
! ! |