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