author | Claus Gittinger <cg@exept.de> |
Fri, 09 Feb 1996 02:42:03 +0100 | |
changeset 125 | db1c1a8e0384 |
parent 86 | 4d7dbb5f1719 |
child 252 | 4db843d36c46 |
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 |
" |
|
13 |
||
14 |
Model subclass:#SelectionInHierarchy |
|
15 |
instanceVariableNames:'root list selection' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Interface-Support-Models' |
|
19 |
! |
|
20 |
||
21 |
!SelectionInHierarchy class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
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 |
version |
|
86
4d7dbb5f1719
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
84
diff
changeset
|
39 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInHierarchy.st,v 1.2 1995-11-11 16:29:20 cg Exp $' |
84 | 40 |
! |
41 |
||
42 |
documentation |
|
43 |
" |
|
44 |
model for a selection in a hierarchical list. |
|
45 |
See examples in SelectionInHierarchyView. |
|
46 |
" |
|
47 |
! ! |
|
48 |
||
49 |
!SelectionInHierarchy methodsFor:'accessing'! |
|
50 |
||
51 |
list |
|
52 |
"Answer a collection of nodes representing the |
|
53 |
list of currently viewed objects." |
|
54 |
||
55 |
^list |
|
56 |
||
57 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding"! |
|
58 |
||
59 |
getHierarchyNodeForContents: something |
|
60 |
||
61 |
"return the hierarchyNode wich contents is something" |
|
62 |
||
63 |
|allNodes| |
|
64 |
||
65 |
allNodes:= root allChildren. |
|
66 |
allNodes do: [:each| |
|
67 |
(each contents = something) ifTrue:[^each]. |
|
68 |
]. |
|
69 |
^nil |
|
70 |
||
71 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding"! |
|
72 |
||
73 |
showCompleteHierarchyStartingAtNode: aHierarchyNode |
|
74 |
"Set the hide-Flag to false for the hierarchy starting at aHierarchyNode" |
|
75 |
||
76 |
| | |
|
77 |
aHierarchyNode isNil ifTrue: [^self]. |
|
78 |
aHierarchyNode hideToFalseForPath. |
|
79 |
self setNewList. |
|
80 |
||
81 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding"! |
|
82 |
||
83 |
setHideToChildren: aBoolean startingAt: aHierarchyNode |
|
84 |
||
85 |
"set the hide-Falg to aBoolean starting at aHierarchyNode down" |
|
86 |
||
87 |
|allNodes| |
|
88 |
||
89 |
allNodes:= root allChildren. |
|
90 |
allNodes do: [:each| |
|
91 |
each hide: aBoolean |
|
92 |
]. |
|
93 |
self setNewList. |
|
94 |
||
95 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding"! |
|
96 |
||
97 |
root: aHierarchyNode |
|
98 |
"Set the root object - this means initialization." |
|
99 |
||
100 |
root := aHierarchyNode. |
|
101 |
self initialize. |
|
102 |
||
103 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding"! |
|
104 |
||
105 |
remove: aHierarchyNode |
|
106 |
"Remove aHierarchyNode and all its children. " |
|
107 |
||
108 |
aHierarchyNode removeYourself. |
|
109 |
self setNewList. |
|
110 |
^aHierarchyNode |
|
111 |
||
112 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding"! |
|
113 |
||
114 |
add: aHierarchyNode below: existingHierarchyNode |
|
115 |
"Add a new HierarchyNode to the tree." |
|
116 |
||
117 |
||
118 |
existingHierarchyNode addChild: aHierarchyNode. |
|
119 |
self setNewList. |
|
120 |
||
121 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding"! |
|
122 |
||
123 |
selectedPath |
|
124 |
"Answer the pathName to the currently selected node." |
|
125 |
||
126 |
| selectedNode | |
|
127 |
selection isNil ifTrue: [^String new]. |
|
128 |
selectedNode := list at: selection ifAbsent: [^String new]. |
|
129 |
^selectedNode pathName. |
|
130 |
||
131 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding"! |
|
132 |
||
133 |
add: aHierarchyNode belowIndex: anIndex |
|
134 |
"Add a new HierarchyNode to the tree below the node |
|
135 |
which is found in the list at anIndex." |
|
136 |
||
137 |
| existingHierarchyNode | |
|
138 |
existingHierarchyNode := list at: anIndex ifAbsent: [^nil]. |
|
139 |
self add: aHierarchyNode below: existingHierarchyNode |
|
140 |
||
141 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding"! |
|
142 |
||
143 |
removeIndex: anIndex |
|
144 |
"Remove the HierarchyNode and all its children |
|
145 |
which is found in the list at anIndex." |
|
146 |
||
147 |
| existingHierarchyNode | |
|
148 |
existingHierarchyNode := list at: anIndex ifAbsent: [^nil]. |
|
149 |
^self remove: existingHierarchyNode. |
|
150 |
||
151 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding"! |
|
152 |
||
153 |
removeBelow: existingHierarchyNode |
|
154 |
"Remove all children below an existingHierarchyNode ." |
|
155 |
||
156 |
||
157 |
existingHierarchyNode removeAllChildren. |
|
158 |
self setNewList. |
|
159 |
||
160 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding"! |
|
161 |
||
162 |
removeBelowIndex: anIndex |
|
163 |
"Remove all the children of aHierarchyNode |
|
164 |
which is found in the list at anIndex." |
|
165 |
||
166 |
| existingHierarchyNode | |
|
167 |
existingHierarchyNode := list at: anIndex ifAbsent: [^nil]. |
|
168 |
^self removeBelow: existingHierarchyNode. |
|
169 |
||
170 |
"Modified: 10.10.94 / 16:13:37 / W.Olberding"! ! |
|
171 |
||
172 |
!SelectionInHierarchy methodsFor:'selection'! |
|
173 |
||
174 |
selection |
|
175 |
"Answer the current selection as |
|
176 |
anIndex of the selection list." |
|
177 |
||
178 |
^selection |
|
179 |
||
180 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding"! |
|
181 |
||
182 |
selection: anIndex |
|
183 |
"Set the current selected object to be the element |
|
184 |
at anIndex of the selection list." |
|
185 |
||
186 |
anIndex isNil |
|
187 |
ifTrue: [ selection := 0] |
|
188 |
ifFalse: [ |
|
189 |
(selection = anIndex) |
|
190 |
ifTrue: [^nil] |
|
191 |
ifFalse: [selection := anIndex ]. |
|
192 |
]. |
|
193 |
self changed: #selection. |
|
194 |
||
195 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding"! |
|
196 |
||
197 |
doubleClickSelection: anIndex |
|
198 |
"Set the current selected object to be the element |
|
199 |
at anIndex of the selection list. |
|
200 |
Also expand or collapse the tree at that point." |
|
201 |
||
202 |
self selection: anIndex. |
|
203 |
self hideShow. |
|
204 |
||
205 |
"Modified: 10.10.94 / 16:13:36 / W.Olberding"! ! |
|
206 |
||
207 |
!SelectionInHierarchy methodsFor:'private'! |
|
208 |
||
209 |
setNewList |
|
210 |
"Travers the tree and build a new list." |
|
211 |
||
212 |
list := root withAllShownChildren. |
|
213 |
self changed: #list. |
|
214 |
||
215 |
"Modified: 10.10.94 / 16:13:37 / W.Olberding"! ! |
|
216 |
||
217 |
!SelectionInHierarchy methodsFor:'hierarchy manipulation'! |
|
218 |
||
219 |
hideShow |
|
220 |
"If possible, expand or collaps the tree |
|
221 |
at the currently selected node." |
|
222 |
||
223 |
| selectedNode | |
|
224 |
selectedNode := list at: selection. |
|
225 |
selectedNode isExpandable ifTrue: [ selectedNode expand. |
|
226 |
^self setNewList. ]. |
|
227 |
selectedNode isCollapsable ifTrue: [ selectedNode collapse. |
|
228 |
^self setNewList. ]. |
|
229 |
||
230 |
"Modified: 10.10.94 / 16:13:37 / W.Olberding"! |
|
231 |
||
232 |
expand |
|
233 |
"If possible, expand the tree |
|
234 |
at the currently selected node." |
|
235 |
||
236 |
| selectedNode | |
|
237 |
selectedNode := list at: selection. |
|
238 |
selectedNode isExpandable ifTrue: [ selectedNode expand. |
|
239 |
^self setNewList. ]. |
|
240 |
||
241 |
"Modified: 10.10.94 / 16:13:37 / W.Olberding"! |
|
242 |
||
243 |
collapse |
|
244 |
"If possible, collapse the tree at the currently selected node. |
|
245 |
The tree structure can be restored again with #expand. " |
|
246 |
||
247 |
| selectedNode | |
|
248 |
selectedNode := list at: selection. |
|
249 |
selectedNode isCollapsable ifTrue: [ selectedNode collapse. |
|
250 |
^self setNewList. ]. |
|
251 |
||
252 |
"Modified: 10.10.94 / 16:13:37 / W.Olberding"! |
|
253 |
||
254 |
expandAll |
|
255 |
"If possible, expand the tree compleately to all leaves |
|
256 |
at the currently selected node." |
|
257 |
||
258 |
| selectedNode | |
|
259 |
selectedNode := list at: selection. |
|
260 |
selectedNode expandAll. |
|
261 |
^self setNewList. |
|
262 |
||
263 |
"Modified: 10.10.94 / 16:13:37 / W.Olberding"! |
|
264 |
||
265 |
collapseAll |
|
266 |
"If possible, collapse the tree at the currently selected node. |
|
267 |
A latter #expand will show the next hierarchy level" |
|
268 |
||
269 |
| selectedNode | |
|
270 |
selectedNode := list at: selection. |
|
271 |
selectedNode isCollapsable ifTrue: [ selectedNode collapseAll. |
|
272 |
^self setNewList. ]. |
|
273 |
||
274 |
"Modified: 10.10.94 / 16:13:37 / W.Olberding"! ! |
|
275 |
||
276 |
!SelectionInHierarchy methodsFor:'testing & debugging'! |
|
277 |
||
278 |
root |
|
279 |
||
280 |
^root |
|
281 |
||
282 |
"Modified: 10.10.94 / 16:13:37 / W.Olberding"! ! |
|
283 |
||
284 |
!SelectionInHierarchy methodsFor:'initialization'! |
|
285 |
||
286 |
initialize |
|
287 |
||
288 |
" nodes := Set new. ***" |
|
289 |
selection := nil. |
|
290 |
self setNewList. |
|
291 |
||
292 |
"Modified: 10.10.94 / 16:13:37 / W.Olberding"! ! |
|
293 |
||
294 |