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