author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 30 May 2018 09:34:26 +0100 | |
branch | jv |
changeset 5814 | 70d07365a2d4 |
parent 3874 | 9accac7cbf67 |
child 5459 | 9f38d94ea752 |
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 |
||
84 | 15 |
Model subclass:#SelectionInHierarchy |
252 | 16 |
instanceVariableNames:'root list selection' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Interface-Support-Models' |
|
84 | 20 |
! |
21 |
||
360 | 22 |
!SelectionInHierarchy class methodsFor:'documentation'! |
84 | 23 |
|
254 | 24 |
copyright |
84 | 25 |
" |
26 |
COPYRIGHT (c) 1994 by AEG Industry Automation |
|
27 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
41 |
model for a selection in a hierarchical list. |
|
42 |
See examples in SelectionInHierarchyView. |
|
252 | 43 |
|
1189 | 44 |
Notice: this class was provided for free by a customer |
45 |
It is more or less obsoleted by SelectionInTree, which provides |
|
46 |
similar (but more sphisticated) functionality. |
|
47 |
SelectionInHierarchy remains in the system for backward compatibility. |
|
48 |
||
252 | 49 |
[Author:] |
50 |
W. Olberding AEG Factory Automation |
|
51 |
||
52 |
[See also:] |
|
360 | 53 |
HierarchyNode |
254 | 54 |
SelectionInHierarchyView |
1191 | 55 |
SelectionInTree SelectionInTreeView TreeItem |
84 | 56 |
" |
57 |
! ! |
|
58 |
||
59 |
!SelectionInHierarchy methodsFor:'accessing'! |
|
60 |
||
254 | 61 |
getHierarchyNodeForContents: something |
360 | 62 |
"return the hierarchyNode whose contents is something" |
254 | 63 |
|
451 | 64 |
root notNil ifTrue:[ |
2928 | 65 |
^ root allChildren detect:[:each| (each contents = something)] ifNone:nil. |
254 | 66 |
]. |
360 | 67 |
^ nil |
68 |
! |
|
254 | 69 |
|
70 |
list |
|
360 | 71 |
"Answer a collection of nodes representing the |
72 |
list of currently viewed objects." |
|
252 | 73 |
|
360 | 74 |
^list |
254 | 75 |
|
360 | 76 |
"Modified: 10.10.1994 / 16:13:36 / W.Olberding" |
77 |
"Modified: 15.4.1997 / 16:29:26 / cg" |
|
78 |
! |
|
254 | 79 |
|
451 | 80 |
root: aHierarchyNode |
81 |
"Set the root object - this means initialization." |
|
254 | 82 |
|
451 | 83 |
root := aHierarchyNode. |
84 |
selection := nil. |
|
85 |
self setNewList. |
|
86 |
! |
|
252 | 87 |
|
254 | 88 |
selectedPath |
451 | 89 |
"Answer the pathName to the currently selected node." |
90 |
||
91 |
|node| |
|
84 | 92 |
|
451 | 93 |
(node := self selectedNode) isNil ifFalse:[ |
94 |
^ node pathName |
|
95 |
]. |
|
96 |
^ '' |
|
97 |
! |
|
254 | 98 |
|
99 |
setHideToChildren: aBoolean startingAt: aHierarchyNode |
|
100 |
||
101 |
"set the hide-Falg to aBoolean starting at aHierarchyNode down" |
|
252 | 102 |
|
451 | 103 |
root notNil ifTrue:[ |
104 |
root allChildren do:[:each| each hide:aBoolean]. |
|
105 |
self setNewList. |
|
106 |
] |
|
107 |
! |
|
252 | 108 |
|
254 | 109 |
showCompleteHierarchyStartingAtNode: aHierarchyNode |
110 |
"Set the hide-Flag to false for the hierarchy starting at aHierarchyNode" |
|
252 | 111 |
|
254 | 112 |
| | |
113 |
aHierarchyNode isNil ifTrue: [^self]. |
|
114 |
aHierarchyNode hideToFalseForPath. |
|
115 |
self setNewList. |
|
84 | 116 |
|
2928 | 117 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding" |
118 |
! ! |
|
84 | 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 |
||
2928 | 190 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding" |
191 |
! ! |
|
451 | 192 |
|
84 | 193 |
!SelectionInHierarchy methodsFor:'hierarchy manipulation'! |
194 |
||
254 | 195 |
collapse |
451 | 196 |
"If possible, collapse the tree at the currently selected node. |
197 |
The tree structure can be restored again with #expand. " |
|
198 |
||
199 |
|node| |
|
84 | 200 |
|
451 | 201 |
(node := self selectedNode) notNil ifTrue:[ |
202 |
node isCollapsable ifTrue:[ |
|
203 |
node collapse. |
|
204 |
self setNewList |
|
205 |
] |
|
206 |
] |
|
207 |
! |
|
252 | 208 |
|
254 | 209 |
collapseAll |
451 | 210 |
"If possible, collapse the tree at the currently selected node. |
211 |
A latter #expand will show the next hierarchy level" |
|
212 |
||
213 |
|node| |
|
254 | 214 |
|
451 | 215 |
(node := self selectedNode) notNil ifTrue:[ |
216 |
node isCollapsable ifTrue:[ |
|
217 |
node collapseAll. |
|
218 |
self setNewList |
|
219 |
] |
|
220 |
] |
|
221 |
! |
|
84 | 222 |
|
254 | 223 |
expand |
451 | 224 |
"If possible, expand the tree |
225 |
at the currently selected node." |
|
226 |
||
227 |
|node| |
|
254 | 228 |
|
451 | 229 |
(node := self selectedNode) notNil ifTrue:[ |
230 |
node isExpandable ifTrue:[ |
|
231 |
node expand. |
|
232 |
self setNewList |
|
233 |
] |
|
234 |
] |
|
235 |
! |
|
254 | 236 |
|
237 |
expandAll |
|
451 | 238 |
"If possible, expand the tree compleately to all leaves |
239 |
at the currently selected node." |
|
240 |
||
241 |
|node| |
|
84 | 242 |
|
451 | 243 |
(node := self selectedNode) notNil ifTrue:[ |
244 |
node expandAll. |
|
245 |
self setNewList |
|
246 |
] |
|
247 |
! |
|
254 | 248 |
|
249 |
hideShow |
|
451 | 250 |
"If possible, expand or collaps the tree |
251 |
at the currently selected node." |
|
254 | 252 |
|
451 | 253 |
|node| |
254 | 254 |
|
451 | 255 |
(node := self selectedNode) notNil ifTrue:[ |
256 |
node isExpandable ifTrue:[ |
|
257 |
node expand |
|
258 |
] ifFalse:[ |
|
259 |
node isCollapsable ifFalse:[ ^ self ]. |
|
260 |
node collapse |
|
261 |
]. |
|
262 |
self setNewList |
|
263 |
] |
|
264 |
! ! |
|
84 | 265 |
|
252 | 266 |
!SelectionInHierarchy methodsFor:'private'! |
84 | 267 |
|
254 | 268 |
setNewList |
451 | 269 |
"Travers the tree and build a new list." |
254 | 270 |
|
451 | 271 |
root notNil ifTrue:[ |
272 |
list := root withAllShownChildren |
|
273 |
] ifFalse:[ |
|
274 |
list := #() |
|
275 |
]. |
|
276 |
self changed:#list. |
|
277 |
! ! |
|
252 | 278 |
|
279 |
!SelectionInHierarchy methodsFor:'selection'! |
|
280 |
||
281 |
doubleClickSelection: anIndex |
|
451 | 282 |
"Set the current selected object to be the element |
283 |
at anIndex of the selection list. |
|
284 |
Also expand or collapse the tree at that point." |
|
285 |
||
286 |
self selectionIndex:anIndex. |
|
287 |
self hideShow. |
|
288 |
! |
|
252 | 289 |
|
451 | 290 |
selectedNode |
291 |
"returns current selected node or nil |
|
292 |
" |
|
293 |
(selection isNil or:[selection == 0]) ifFalse:[ |
|
294 |
^ list at:selection |
|
295 |
]. |
|
296 |
^ nil |
|
252 | 297 |
! |
298 |
||
299 |
selection |
|
451 | 300 |
"get the selection or nil |
301 |
" |
|
302 |
^ self selectionIndex |
|
252 | 303 |
! |
304 |
||
451 | 305 |
selection:anIndexOrNil |
3874
9accac7cbf67
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2928
diff
changeset
|
306 |
"set the selection" |
9accac7cbf67
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2928
diff
changeset
|
307 |
|
451 | 308 |
self selectionIndex:anIndexOrNil |
252 | 309 |
! |
310 |
||
311 |
selectionIndex |
|
451 | 312 |
"get the selection or nil |
313 |
" |
|
252 | 314 |
^ selection |
315 |
! |
|
316 |
||
451 | 317 |
selectionIndex:anIndexOrNil |
318 |
"set the selection |
|
319 |
" |
|
320 |
anIndexOrNil == selection ifFalse:[ |
|
321 |
anIndexOrNil == 0 ifTrue:[ |
|
322 |
selection isNil ifTrue:[^ self ]. |
|
323 |
selection := nil |
|
324 |
] ifFalse:[ |
|
325 |
selection := anIndexOrNil |
|
326 |
]. |
|
252 | 327 |
self changed: #selection. |
451 | 328 |
] |
252 | 329 |
! ! |
330 |
||
331 |
!SelectionInHierarchy methodsFor:'testing & debugging'! |
|
332 |
||
254 | 333 |
root |
451 | 334 |
"get the root node |
335 |
" |
|
336 |
^ root |
|
337 |
! ! |
|
252 | 338 |
|
360 | 339 |
!SelectionInHierarchy class methodsFor:'documentation'! |
252 | 340 |
|
341 |
version |
|
3874
9accac7cbf67
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2928
diff
changeset
|
342 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInHierarchy.st,v 1.14 2010-02-01 12:20:22 cg Exp $' |
9accac7cbf67
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2928
diff
changeset
|
343 |
! |
9accac7cbf67
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2928
diff
changeset
|
344 |
|
9accac7cbf67
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2928
diff
changeset
|
345 |
version_CVS |
9accac7cbf67
comment/format in: #selection:
Claus Gittinger <cg@exept.de>
parents:
2928
diff
changeset
|
346 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInHierarchy.st,v 1.14 2010-02-01 12:20:22 cg Exp $' |
252 | 347 |
! ! |