84
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by AEG Industry Automation
|
|
3 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
4 |
All Rights Reserved
|
|
5 |
|
|
6 |
This software is furnished under a license and may be used
|
|
7 |
only in accordance with the terms of that license and with the
|
|
8 |
inclusion of the above copyright notice. This software may not
|
|
9 |
be provided or otherwise made available to, or used by, any
|
|
10 |
other person. No title to or ownership of the software is
|
|
11 |
hereby transferred.
|
|
12 |
"
|
|
13 |
|
1818
|
14 |
"{ Package: 'stx:libwidg2' }"
|
|
15 |
|
84
|
16 |
Model subclass:#SelectionInHierarchy
|
252
|
17 |
instanceVariableNames:'root list selection'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Interface-Support-Models'
|
84
|
21 |
!
|
|
22 |
|
360
|
23 |
!SelectionInHierarchy class methodsFor:'documentation'!
|
84
|
24 |
|
254
|
25 |
copyright
|
84
|
26 |
"
|
|
27 |
COPYRIGHT (c) 1994 by AEG Industry Automation
|
|
28 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
29 |
All Rights Reserved
|
|
30 |
|
|
31 |
This software is furnished under a license and may be used
|
|
32 |
only in accordance with the terms of that license and with the
|
|
33 |
inclusion of the above copyright notice. This software may not
|
|
34 |
be provided or otherwise made available to, or used by, any
|
|
35 |
other person. No title to or ownership of the software is
|
|
36 |
hereby transferred.
|
|
37 |
"
|
|
38 |
!
|
|
39 |
|
|
40 |
documentation
|
|
41 |
"
|
|
42 |
model for a selection in a hierarchical list.
|
|
43 |
See examples in SelectionInHierarchyView.
|
252
|
44 |
|
1189
|
45 |
Notice: this class was provided for free by a customer
|
|
46 |
It is more or less obsoleted by SelectionInTree, which provides
|
|
47 |
similar (but more sphisticated) functionality.
|
|
48 |
SelectionInHierarchy remains in the system for backward compatibility.
|
|
49 |
|
252
|
50 |
[Author:]
|
|
51 |
W. Olberding AEG Factory Automation
|
|
52 |
|
|
53 |
[See also:]
|
360
|
54 |
HierarchyNode
|
254
|
55 |
SelectionInHierarchyView
|
1191
|
56 |
SelectionInTree SelectionInTreeView TreeItem
|
84
|
57 |
"
|
|
58 |
! !
|
|
59 |
|
|
60 |
!SelectionInHierarchy methodsFor:'accessing'!
|
|
61 |
|
254
|
62 |
getHierarchyNodeForContents: something
|
360
|
63 |
"return the hierarchyNode whose contents is something"
|
254
|
64 |
|
451
|
65 |
root notNil ifTrue:[
|
|
66 |
root allChildren do:[:each| (each contents = something) ifTrue:[^each] ]
|
254
|
67 |
].
|
360
|
68 |
^ nil
|
|
69 |
!
|
254
|
70 |
|
|
71 |
list
|
360
|
72 |
"Answer a collection of nodes representing the
|
|
73 |
list of currently viewed objects."
|
252
|
74 |
|
360
|
75 |
^list
|
254
|
76 |
|
360
|
77 |
"Modified: 10.10.1994 / 16:13:36 / W.Olberding"
|
|
78 |
"Modified: 15.4.1997 / 16:29:26 / cg"
|
|
79 |
!
|
254
|
80 |
|
451
|
81 |
root: aHierarchyNode
|
|
82 |
"Set the root object - this means initialization."
|
254
|
83 |
|
451
|
84 |
root := aHierarchyNode.
|
|
85 |
selection := nil.
|
|
86 |
self setNewList.
|
|
87 |
!
|
252
|
88 |
|
254
|
89 |
selectedPath
|
451
|
90 |
"Answer the pathName to the currently selected node."
|
|
91 |
|
|
92 |
|node|
|
84
|
93 |
|
451
|
94 |
(node := self selectedNode) isNil ifFalse:[
|
|
95 |
^ node pathName
|
|
96 |
].
|
|
97 |
^ ''
|
|
98 |
!
|
254
|
99 |
|
|
100 |
setHideToChildren: aBoolean startingAt: aHierarchyNode
|
|
101 |
|
|
102 |
"set the hide-Falg to aBoolean starting at aHierarchyNode down"
|
252
|
103 |
|
451
|
104 |
root notNil ifTrue:[
|
|
105 |
root allChildren do:[:each| each hide:aBoolean].
|
|
106 |
self setNewList.
|
|
107 |
]
|
|
108 |
!
|
252
|
109 |
|
254
|
110 |
showCompleteHierarchyStartingAtNode: aHierarchyNode
|
|
111 |
"Set the hide-Flag to false for the hierarchy starting at aHierarchyNode"
|
252
|
112 |
|
254
|
113 |
| |
|
|
114 |
aHierarchyNode isNil ifTrue: [^self].
|
|
115 |
aHierarchyNode hideToFalseForPath.
|
|
116 |
self setNewList.
|
84
|
117 |
|
|
118 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding"! !
|
|
119 |
|
1818
|
120 |
!SelectionInHierarchy methodsFor:'accessing-sequencable'!
|
442
|
121 |
|
|
122 |
addChildAndSubChildren:aHierarchyNode below:existingHierarchyNode after:aChild
|
|
123 |
"Add a new HierarchyNode to the tree."
|
|
124 |
|
|
125 |
existingHierarchyNode addChildAndSubChildren:aHierarchyNode after:aChild.
|
|
126 |
self setNewList.
|
|
127 |
!
|
|
128 |
|
|
129 |
addChildAndSubChildren:aHierarchyNode below:existingHierarchyNode at:anIndex
|
|
130 |
|
|
131 |
existingHierarchyNode addChildAndSubChildren:aHierarchyNode at:anIndex.
|
|
132 |
self setNewList.
|
|
133 |
! !
|
|
134 |
|
451
|
135 |
!SelectionInHierarchy methodsFor:'adding & removing'!
|
|
136 |
|
|
137 |
add:aChild below:aParent
|
|
138 |
"add a new HierarchyNode to the tree."
|
|
139 |
|
|
140 |
aParent addChild:aChild.
|
|
141 |
self setNewList.
|
|
142 |
!
|
|
143 |
|
|
144 |
add: aChild belowIndex:aParentIndex
|
|
145 |
"Add a new HierarchyNode to the tree below the node
|
|
146 |
which is found in the list at anIndex."
|
|
147 |
|
|
148 |
|parent|
|
|
149 |
|
|
150 |
parent := list at:aParentIndex ifAbsent:[ ^ nil ].
|
|
151 |
self add:aChild below:parent
|
|
152 |
!
|
|
153 |
|
|
154 |
remove:aHierarchyNode
|
|
155 |
"Remove aHierarchyNode and all its children. "
|
|
156 |
|
|
157 |
aHierarchyNode removeYourself.
|
|
158 |
self setNewList.
|
|
159 |
^aHierarchyNode
|
|
160 |
!
|
|
161 |
|
|
162 |
removeBelow: existingHierarchyNode
|
|
163 |
"Remove all children below an existingHierarchyNode ."
|
|
164 |
|
|
165 |
existingHierarchyNode hasChildren ifTrue:[
|
|
166 |
existingHierarchyNode removeAllChildren.
|
|
167 |
self setNewList
|
|
168 |
].
|
|
169 |
!
|
|
170 |
|
|
171 |
removeBelowIndex: anIndex
|
|
172 |
"Remove all the children of aHierarchyNode
|
|
173 |
which is found in the list at anIndex."
|
|
174 |
|
|
175 |
| existingHierarchyNode |
|
|
176 |
existingHierarchyNode := list at: anIndex ifAbsent: [^nil].
|
|
177 |
^self removeBelow:existingHierarchyNode.
|
|
178 |
|
|
179 |
"Modified: 10.10.94 / 16:13:37 / W.Olberding"
|
|
180 |
!
|
|
181 |
|
|
182 |
removeIndex: anIndex
|
|
183 |
"Remove the HierarchyNode and all its children
|
|
184 |
which is found in the list at anIndex."
|
|
185 |
|
|
186 |
| existingHierarchyNode |
|
|
187 |
existingHierarchyNode := list at: anIndex ifAbsent: [^nil].
|
|
188 |
^self remove: existingHierarchyNode.
|
|
189 |
|
|
190 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding"! !
|
|
191 |
|
84
|
192 |
!SelectionInHierarchy methodsFor:'hierarchy manipulation'!
|
|
193 |
|
254
|
194 |
collapse
|
451
|
195 |
"If possible, collapse the tree at the currently selected node.
|
|
196 |
The tree structure can be restored again with #expand. "
|
|
197 |
|
|
198 |
|node|
|
84
|
199 |
|
451
|
200 |
(node := self selectedNode) notNil ifTrue:[
|
|
201 |
node isCollapsable ifTrue:[
|
|
202 |
node collapse.
|
|
203 |
self setNewList
|
|
204 |
]
|
|
205 |
]
|
|
206 |
!
|
252
|
207 |
|
254
|
208 |
collapseAll
|
451
|
209 |
"If possible, collapse the tree at the currently selected node.
|
|
210 |
A latter #expand will show the next hierarchy level"
|
|
211 |
|
|
212 |
|node|
|
254
|
213 |
|
451
|
214 |
(node := self selectedNode) notNil ifTrue:[
|
|
215 |
node isCollapsable ifTrue:[
|
|
216 |
node collapseAll.
|
|
217 |
self setNewList
|
|
218 |
]
|
|
219 |
]
|
|
220 |
!
|
84
|
221 |
|
254
|
222 |
expand
|
451
|
223 |
"If possible, expand the tree
|
|
224 |
at the currently selected node."
|
|
225 |
|
|
226 |
|node|
|
254
|
227 |
|
451
|
228 |
(node := self selectedNode) notNil ifTrue:[
|
|
229 |
node isExpandable ifTrue:[
|
|
230 |
node expand.
|
|
231 |
self setNewList
|
|
232 |
]
|
|
233 |
]
|
|
234 |
!
|
254
|
235 |
|
|
236 |
expandAll
|
451
|
237 |
"If possible, expand the tree compleately to all leaves
|
|
238 |
at the currently selected node."
|
|
239 |
|
|
240 |
|node|
|
84
|
241 |
|
451
|
242 |
(node := self selectedNode) notNil ifTrue:[
|
|
243 |
node expandAll.
|
|
244 |
self setNewList
|
|
245 |
]
|
|
246 |
!
|
254
|
247 |
|
|
248 |
hideShow
|
451
|
249 |
"If possible, expand or collaps the tree
|
|
250 |
at the currently selected node."
|
254
|
251 |
|
451
|
252 |
|node|
|
254
|
253 |
|
451
|
254 |
(node := self selectedNode) notNil ifTrue:[
|
|
255 |
node isExpandable ifTrue:[
|
|
256 |
node expand
|
|
257 |
] ifFalse:[
|
|
258 |
node isCollapsable ifFalse:[ ^ self ].
|
|
259 |
node collapse
|
|
260 |
].
|
|
261 |
self setNewList
|
|
262 |
]
|
|
263 |
! !
|
84
|
264 |
|
252
|
265 |
!SelectionInHierarchy methodsFor:'private'!
|
84
|
266 |
|
254
|
267 |
setNewList
|
451
|
268 |
"Travers the tree and build a new list."
|
254
|
269 |
|
451
|
270 |
root notNil ifTrue:[
|
|
271 |
list := root withAllShownChildren
|
|
272 |
] ifFalse:[
|
|
273 |
list := #()
|
|
274 |
].
|
|
275 |
self changed:#list.
|
|
276 |
! !
|
252
|
277 |
|
|
278 |
!SelectionInHierarchy methodsFor:'selection'!
|
|
279 |
|
|
280 |
doubleClickSelection: anIndex
|
451
|
281 |
"Set the current selected object to be the element
|
|
282 |
at anIndex of the selection list.
|
|
283 |
Also expand or collapse the tree at that point."
|
|
284 |
|
|
285 |
self selectionIndex:anIndex.
|
|
286 |
self hideShow.
|
|
287 |
!
|
252
|
288 |
|
451
|
289 |
selectedNode
|
|
290 |
"returns current selected node or nil
|
|
291 |
"
|
|
292 |
(selection isNil or:[selection == 0]) ifFalse:[
|
|
293 |
^ list at:selection
|
|
294 |
].
|
|
295 |
^ nil
|
252
|
296 |
!
|
|
297 |
|
|
298 |
selection
|
451
|
299 |
"get the selection or nil
|
|
300 |
"
|
|
301 |
^ self selectionIndex
|
252
|
302 |
!
|
|
303 |
|
451
|
304 |
selection:anIndexOrNil
|
|
305 |
"set the selection
|
|
306 |
"
|
|
307 |
self selectionIndex:anIndexOrNil
|
252
|
308 |
!
|
|
309 |
|
|
310 |
selectionIndex
|
451
|
311 |
"get the selection or nil
|
|
312 |
"
|
252
|
313 |
^ selection
|
|
314 |
!
|
|
315 |
|
451
|
316 |
selectionIndex:anIndexOrNil
|
|
317 |
"set the selection
|
|
318 |
"
|
|
319 |
anIndexOrNil == selection ifFalse:[
|
|
320 |
anIndexOrNil == 0 ifTrue:[
|
|
321 |
selection isNil ifTrue:[^ self ].
|
|
322 |
selection := nil
|
|
323 |
] ifFalse:[
|
|
324 |
selection := anIndexOrNil
|
|
325 |
].
|
252
|
326 |
self changed: #selection.
|
451
|
327 |
]
|
252
|
328 |
! !
|
|
329 |
|
|
330 |
!SelectionInHierarchy methodsFor:'testing & debugging'!
|
|
331 |
|
254
|
332 |
root
|
451
|
333 |
"get the root node
|
|
334 |
"
|
|
335 |
^ root
|
|
336 |
! !
|
252
|
337 |
|
360
|
338 |
!SelectionInHierarchy class methodsFor:'documentation'!
|
252
|
339 |
|
|
340 |
version
|
1818
|
341 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInHierarchy.st,v 1.12 2000-08-21 22:45:20 cg Exp $'
|
252
|
342 |
! !
|