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
|
496
|
16 |
instanceVariableNames:'root list selection showRoot'
|
458
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Interface-Support-Models'
|
|
20 |
!
|
|
21 |
|
|
22 |
!SelectionInTree class methodsFor:'documentation'!
|
|
23 |
|
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
|
|
27 |
All Rights Reserved
|
|
28 |
|
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
|
|
37 |
|
|
38 |
!
|
|
39 |
|
|
40 |
documentation
|
|
41 |
"
|
|
42 |
list and selection holder for hierarchical list structures. Used
|
|
43 |
to buildup file-trees, class tress etc.
|
|
44 |
|
|
45 |
Especially suited for use with SelectionInTreeView.
|
|
46 |
|
|
47 |
[See also:]
|
|
48 |
TreeItem
|
|
49 |
SelectionInTreeView
|
|
50 |
|
|
51 |
[Author:]
|
|
52 |
W. Olberding
|
|
53 |
Claus Atzkern
|
|
54 |
"
|
|
55 |
! !
|
|
56 |
|
|
57 |
!SelectionInTree methodsFor:'accessing'!
|
|
58 |
|
|
59 |
list
|
|
60 |
"get list oc currently shown objects
|
|
61 |
"
|
|
62 |
^ list
|
|
63 |
!
|
|
64 |
|
|
65 |
root
|
|
66 |
"get the root node
|
|
67 |
"
|
|
68 |
^ root
|
|
69 |
!
|
|
70 |
|
|
71 |
root:aRootNode
|
|
72 |
"set a new root and recompute list
|
|
73 |
"
|
496
|
74 |
root := aRootNode.
|
|
75 |
self recomputeList.
|
|
76 |
|
|
77 |
! !
|
491
|
78 |
|
496
|
79 |
!SelectionInTree methodsFor:'accessing behavior'!
|
|
80 |
|
|
81 |
showRoot
|
|
82 |
"list with or without root
|
|
83 |
"
|
|
84 |
^ showRoot
|
491
|
85 |
!
|
|
86 |
|
496
|
87 |
showRoot:aState
|
|
88 |
"list with or without root
|
491
|
89 |
"
|
496
|
90 |
aState ~~ showRoot ifTrue:[
|
|
91 |
showRoot := aState.
|
491
|
92 |
|
496
|
93 |
root notNil ifTrue:[
|
|
94 |
aState ifTrue:[list addFirst:root]
|
|
95 |
ifFalse:[list removeFirst].
|
491
|
96 |
|
496
|
97 |
self changed:#list.
|
491
|
98 |
].
|
|
99 |
].
|
458
|
100 |
! !
|
|
101 |
|
|
102 |
!SelectionInTree methodsFor:'accessing hierarchy'!
|
|
103 |
|
|
104 |
collapse:something
|
|
105 |
"collapse a node or collection of nodes
|
|
106 |
"
|
|
107 |
|invalidate|
|
|
108 |
|
|
109 |
self each:something do:[:aNode|
|
|
110 |
aNode isCollapsable ifTrue:[
|
|
111 |
aNode collapse.
|
|
112 |
invalidate := true
|
|
113 |
]
|
|
114 |
].
|
|
115 |
invalidate == true ifTrue:[self recomputeList]
|
|
116 |
!
|
|
117 |
|
|
118 |
expand:something
|
|
119 |
"expand a node or collection of nodes
|
|
120 |
"
|
|
121 |
|invalidate|
|
|
122 |
|
|
123 |
self each:something do:[:aNode|
|
|
124 |
aNode isExpandable ifTrue:[
|
|
125 |
aNode expand.
|
|
126 |
invalidate := true
|
|
127 |
]
|
|
128 |
].
|
|
129 |
invalidate == true ifTrue:[self recomputeList]
|
|
130 |
! !
|
|
131 |
|
|
132 |
!SelectionInTree methodsFor:'adding & removing'!
|
|
133 |
|
|
134 |
add:something after:aChild
|
|
135 |
"add a node or collection of nodes to parent after a child
|
|
136 |
"
|
|
137 |
"add a node or collection of nodes to after a child
|
|
138 |
"
|
|
139 |
aChild notNil ifTrue:[
|
|
140 |
aChild parent add:something after:aChild.
|
|
141 |
self recomputeList
|
|
142 |
]
|
|
143 |
!
|
|
144 |
|
|
145 |
add:something afterIndex:anIndex below:aParent
|
|
146 |
"add a node or collection of nodes to parent after an index
|
|
147 |
"
|
|
148 |
aParent add:something afterIndex:anIndex.
|
|
149 |
self recomputeList
|
|
150 |
|
|
151 |
!
|
|
152 |
|
|
153 |
add:something before:aChild
|
|
154 |
"add a node or collection of nodes to before a child
|
|
155 |
"
|
|
156 |
aChild notNil ifTrue:[
|
|
157 |
aChild parent add:something before:aChild.
|
|
158 |
self recomputeList
|
|
159 |
]
|
|
160 |
!
|
|
161 |
|
|
162 |
add:something beforeIndex:anIndex below:aParent
|
|
163 |
"add a node or collection of nodes to parent before an index
|
|
164 |
"
|
|
165 |
aParent add:something beforeIndex:anIndex.
|
|
166 |
self recomputeList
|
|
167 |
|
|
168 |
!
|
|
169 |
|
|
170 |
add:something below:aParent
|
|
171 |
"add a node or collection of nodes to parent
|
|
172 |
"
|
|
173 |
aParent add:something.
|
|
174 |
self recomputeList
|
|
175 |
|
|
176 |
!
|
|
177 |
|
|
178 |
remove:something
|
|
179 |
"remove a node or collection of nodes
|
|
180 |
"
|
|
181 |
|invalidate|
|
|
182 |
|
|
183 |
self each:something do:[:aNode|
|
|
184 |
aNode parent notNil ifTrue:[
|
|
185 |
aNode parent remove:aNode.
|
|
186 |
invalidate := true
|
|
187 |
]
|
|
188 |
].
|
|
189 |
invalidate == true ifTrue:[self recomputeList].
|
|
190 |
^ something
|
|
191 |
!
|
|
192 |
|
|
193 |
removeIndex:something
|
|
194 |
"remove a node at index or collection of indexed nodes
|
|
195 |
"
|
|
196 |
|invalidate node|
|
|
197 |
|
|
198 |
something isCollection ifFalse:[
|
|
199 |
(something isNil or:[something == 0]) ifFalse:[
|
|
200 |
^ self remove:(list at:something)
|
|
201 |
].
|
|
202 |
^ nil
|
|
203 |
].
|
|
204 |
|
|
205 |
(SortedCollection withAll:something) reverseDo:[:anIndex|
|
|
206 |
node := list at:anIndex.
|
|
207 |
|
|
208 |
node parent notNil ifTrue:[
|
|
209 |
node parent remove:node.
|
|
210 |
invalidate := true
|
|
211 |
]
|
|
212 |
].
|
|
213 |
invalidate == true ifTrue:[self recomputeList].
|
|
214 |
!
|
|
215 |
|
|
216 |
removeSelection
|
|
217 |
"remove selected nodes
|
|
218 |
"
|
|
219 |
self removeIndex:(self selectionIndex).
|
|
220 |
self selectionIndex:nil
|
|
221 |
! !
|
|
222 |
|
|
223 |
!SelectionInTree methodsFor:'enumerating'!
|
|
224 |
|
|
225 |
each:something do:aBlock
|
|
226 |
"evaluate a block for something or in case of a collection for each
|
|
227 |
element in the collection
|
|
228 |
"
|
|
229 |
something notNil ifTrue:[
|
|
230 |
something isCollection ifTrue:[something do:[:el|aBlock value:el]]
|
|
231 |
ifFalse:[aBlock value:something]
|
|
232 |
]
|
|
233 |
|
|
234 |
! !
|
|
235 |
|
496
|
236 |
!SelectionInTree methodsFor:'initialization'!
|
|
237 |
|
|
238 |
initialize
|
|
239 |
super initialize.
|
|
240 |
showRoot := true.
|
|
241 |
! !
|
|
242 |
|
458
|
243 |
!SelectionInTree methodsFor:'private'!
|
|
244 |
|
|
245 |
recomputeList
|
|
246 |
"Travers the tree and build a new list."
|
|
247 |
|
482
|
248 |
self updateList.
|
|
249 |
self changed:#list.
|
|
250 |
!
|
|
251 |
|
|
252 |
updateList
|
|
253 |
"Travers the tree and build a new list.; no notification raised"
|
|
254 |
|
458
|
255 |
list := OrderedCollection new.
|
|
256 |
|
|
257 |
root notNil ifTrue:[
|
496
|
258 |
showRoot ifTrue:[
|
|
259 |
list add:root
|
|
260 |
].
|
458
|
261 |
root recomputeList:list
|
|
262 |
].
|
|
263 |
! !
|
|
264 |
|
|
265 |
!SelectionInTree methodsFor:'selection'!
|
|
266 |
|
|
267 |
selection
|
|
268 |
"get the selection or nil
|
|
269 |
"
|
|
270 |
^ self selectionIndex
|
|
271 |
!
|
|
272 |
|
|
273 |
selection:indexesOrNil
|
|
274 |
"set the selection
|
|
275 |
"
|
|
276 |
self selectionIndex:indexesOrNil
|
|
277 |
!
|
|
278 |
|
|
279 |
selectionIndex
|
|
280 |
"get the selection or nil
|
|
281 |
"
|
|
282 |
^ selection
|
|
283 |
!
|
|
284 |
|
|
285 |
selectionIndex:indexesOrNil
|
|
286 |
"set the selection
|
|
287 |
"
|
496
|
288 |
|oldSel|
|
|
289 |
|
|
290 |
oldSel := selection.
|
|
291 |
self setSelectionIndex:indexesOrNil.
|
|
292 |
|
|
293 |
oldSel = selection ifFalse:[
|
|
294 |
self changed:#selection
|
|
295 |
]
|
|
296 |
!
|
|
297 |
|
|
298 |
setSelection:indexesOrNil
|
|
299 |
"set the selection without raising a notification
|
|
300 |
"
|
|
301 |
self setSelectionIndex:indexesOrNil
|
|
302 |
!
|
|
303 |
|
|
304 |
setSelectionIndex:indexesOrNil
|
|
305 |
"set the selection without raising a notification
|
|
306 |
"
|
458
|
307 |
|indexes|
|
|
308 |
|
|
309 |
indexes := indexesOrNil.
|
|
310 |
|
|
311 |
indexes size == 0 ifTrue:[
|
|
312 |
(indexes isCollection or:[indexes == 0]) ifTrue:[
|
|
313 |
indexes := nil
|
|
314 |
]
|
|
315 |
].
|
496
|
316 |
selection := indexes
|
458
|
317 |
|
|
318 |
! !
|
|
319 |
|
|
320 |
!SelectionInTree class methodsFor:'documentation'!
|
|
321 |
|
|
322 |
version
|
496
|
323 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTree.st,v 1.4 1997-08-15 09:26:23 ca Exp $'
|
458
|
324 |
! !
|