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