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