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 |
Object subclass:#HierarchyNode
|
|
15 |
instanceVariableNames:'name id parent children contents disabled hide level'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Interface-Support'
|
|
19 |
!
|
|
20 |
|
|
21 |
!HierarchyNode 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
|
|
39 |
"
|
|
40 |
$Header: /cvs/stx/stx/libwidg2/HierarchyNode.st,v 1.1 1995-11-01 13:43:28 cg Exp $
|
|
41 |
"
|
|
42 |
!
|
|
43 |
|
|
44 |
documentation
|
|
45 |
"
|
|
46 |
class to build up tree like structures to represent
|
|
47 |
file-trees, class tress etc.
|
|
48 |
Especially suited for use with SelectionInHierarchy and
|
|
49 |
SelectionInHierarchyView.
|
|
50 |
See examples in SelectionInHierarchyView.
|
|
51 |
"
|
|
52 |
!
|
|
53 |
|
|
54 |
!HierarchyNode class methodsFor:'instance creation'!
|
|
55 |
|
|
56 |
newAsTreeFromSmalltalkClass: aClass
|
|
57 |
|
|
58 |
"create a tree of nodes with aClass and all its
|
|
59 |
subclasses as contents."
|
|
60 |
|
|
61 |
|newInst|
|
|
62 |
newInst := super new initialize.
|
|
63 |
newInst name: aClass name.
|
|
64 |
newInst contents: aClass.
|
|
65 |
newInst level: aClass allSuperclasses size.
|
|
66 |
aClass subclasses do: [ :aSubClass |
|
|
67 |
newInst addChild: (self newAsTreeFromSmalltalkClass: aSubClass).
|
|
68 |
].
|
|
69 |
^newInst
|
|
70 |
!
|
|
71 |
|
|
72 |
newWithName: aString
|
|
73 |
|
|
74 |
|newInst|
|
|
75 |
newInst := super new initialize.
|
|
76 |
newInst name: aString.
|
|
77 |
^newInst
|
|
78 |
!
|
|
79 |
|
|
80 |
new
|
|
81 |
|
|
82 |
^super new initialize
|
|
83 |
!
|
|
84 |
|
|
85 |
newWithName: aString andId: anId
|
|
86 |
|
|
87 |
|newInst|
|
|
88 |
newInst := super new initialize.
|
|
89 |
newInst name: aString.
|
|
90 |
newInst id: anId.
|
|
91 |
^newInst
|
|
92 |
! !
|
|
93 |
|
|
94 |
!HierarchyNode methodsFor:'accessing'!
|
|
95 |
|
|
96 |
contents
|
|
97 |
"Answer the contents of me (e.g. a set of items)"
|
|
98 |
|
|
99 |
^contents
|
|
100 |
|
|
101 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
102 |
|
|
103 |
name
|
|
104 |
"return name"
|
|
105 |
|
|
106 |
^ name
|
|
107 |
|
|
108 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
109 |
|
|
110 |
level
|
|
111 |
"answer the level in hierarchy (0=root)"
|
|
112 |
|
|
113 |
^level
|
|
114 |
|
|
115 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
116 |
|
|
117 |
contents: anObject
|
|
118 |
"Set the contents of me to any object (e.g. a set of items)"
|
|
119 |
|
|
120 |
^contents:= anObject
|
|
121 |
|
|
122 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
123 |
|
|
124 |
hide: aBoolean
|
|
125 |
|
|
126 |
"Set hide to aBoolean"
|
|
127 |
|
|
128 |
hide:= aBoolean
|
|
129 |
|
|
130 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
131 |
|
|
132 |
level: anInteger
|
|
133 |
"set the level in hierarchy (0=root)"
|
|
134 |
|
|
135 |
level := anInteger.
|
|
136 |
|
|
137 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
138 |
|
|
139 |
hideToFalseForPath
|
|
140 |
"set the hide-flag to false"
|
|
141 |
|
|
142 |
hide:= false.
|
|
143 |
parent isNil ifTrue: [^self].
|
|
144 |
parent hideToFalseForPath
|
|
145 |
|
|
146 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
147 |
|
|
148 |
parent:something
|
|
149 |
"set parent"
|
|
150 |
|
|
151 |
parent := something.
|
|
152 |
|
|
153 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
154 |
|
|
155 |
name: aString
|
|
156 |
"set the name that identifys me within my parent's context."
|
|
157 |
|
|
158 |
name := aString.
|
|
159 |
|
|
160 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
161 |
|
|
162 |
id
|
|
163 |
"return id"
|
|
164 |
|
|
165 |
^ id
|
|
166 |
|
|
167 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
168 |
|
|
169 |
id:something
|
|
170 |
"set id"
|
|
171 |
|
|
172 |
id := something.
|
|
173 |
|
|
174 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
175 |
|
|
176 |
children: aCollectionWithElementsOfMyKind
|
|
177 |
"set my children"
|
|
178 |
|
|
179 |
aCollectionWithElementsOfMyKind do: [:child |
|
|
180 |
child parent: self.
|
|
181 |
child level: level +1.
|
|
182 |
].
|
|
183 |
children := aCollectionWithElementsOfMyKind.
|
|
184 |
|
|
185 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
186 |
|
|
187 |
disabled
|
|
188 |
"return disabled"
|
|
189 |
|
|
190 |
^ disabled
|
|
191 |
|
|
192 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
193 |
|
|
194 |
disabled: aBool
|
|
195 |
"set disabled"
|
|
196 |
|
|
197 |
disabled := aBool.
|
|
198 |
|
|
199 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
200 |
|
|
201 |
pathName
|
|
202 |
"return a full path name to me"
|
|
203 |
|
|
204 |
parent isNil ifTrue: [^ (self delimiterString), name].
|
|
205 |
^parent pathName, (self delimiterString), name.
|
|
206 |
|
|
207 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! !
|
|
208 |
|
|
209 |
!HierarchyNode methodsFor:'queries'!
|
|
210 |
|
|
211 |
hasChildren
|
|
212 |
|
|
213 |
^children size > 0.
|
|
214 |
|
|
215 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
216 |
|
|
217 |
isExpandable
|
|
218 |
"Answer true if I have hidden children"
|
|
219 |
|
|
220 |
self hasChildren ifTrue: [ ^hide == true ].
|
|
221 |
^false.
|
|
222 |
|
|
223 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
224 |
|
|
225 |
isCollapsable
|
|
226 |
"Answer true if I have shown children"
|
|
227 |
|
|
228 |
self hasChildren ifTrue: [ ^hide == false ].
|
|
229 |
^false.
|
|
230 |
|
|
231 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
232 |
|
|
233 |
childrenHidden
|
|
234 |
"Answer true if my children shall be hidden
|
|
235 |
in hierachical printouts etc."
|
|
236 |
|
|
237 |
^hide.
|
|
238 |
|
|
239 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"!
|
|
240 |
|
|
241 |
childrenShown
|
|
242 |
"Answer true if my children shall be shown
|
|
243 |
in hierachical printouts etc."
|
|
244 |
|
|
245 |
^hide not.
|
|
246 |
|
|
247 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! !
|
|
248 |
|
|
249 |
!HierarchyNode methodsFor:'hierarchy operations'!
|
|
250 |
|
|
251 |
withAllShownChildren
|
|
252 |
"Answer me, my immediate children and all my grandchildren which are
|
|
253 |
currently not hidden.
|
|
254 |
-- in hierachical order and alphabeticaly sorted by name within one level."
|
|
255 |
|
|
256 |
| kids |
|
|
257 |
kids := OrderedCollection with: self .
|
|
258 |
self addAllShownChildrenTo: kids.
|
|
259 |
^kids.
|
|
260 |
|
|
261 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"!
|
|
262 |
|
|
263 |
allChildren
|
|
264 |
"Answer my immediate children plus all my grandchildren
|
|
265 |
-- in hierachical order and alphabeticaly sorted by name within one level."
|
|
266 |
|
|
267 |
| kids |
|
|
268 |
kids := OrderedCollection new.
|
|
269 |
self addAllChildrenTo: kids.
|
|
270 |
^kids.
|
|
271 |
|
|
272 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"!
|
|
273 |
|
|
274 |
addChild: anObjectOfMyKind
|
|
275 |
"add anObjectOfMyKind to my children"
|
|
276 |
|
|
277 |
anObjectOfMyKind parent: self.
|
|
278 |
anObjectOfMyKind level: level +1.
|
|
279 |
children add: anObjectOfMyKind.
|
|
280 |
|
|
281 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"!
|
|
282 |
|
|
283 |
expand
|
|
284 |
"Show my immediate children in hierachical printouts."
|
|
285 |
|
|
286 |
hide := false.
|
|
287 |
|
|
288 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"!
|
|
289 |
|
|
290 |
collapse
|
|
291 |
"Hide my children in hierachical printouts."
|
|
292 |
|
|
293 |
hide := true
|
|
294 |
|
|
295 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"!
|
|
296 |
|
|
297 |
removeChild: anObjectOfMyKind
|
|
298 |
"remove anObjectOfMyKind from my children"
|
|
299 |
|
|
300 |
anObjectOfMyKind parent: nil.
|
|
301 |
children rehash.
|
|
302 |
children remove: anObjectOfMyKind.
|
|
303 |
|
|
304 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"
|
|
305 |
!
|
|
306 |
|
|
307 |
removeYourself
|
|
308 |
"remove me and all my children"
|
|
309 |
|
|
310 |
parent isNil ifTrue: [^nil].
|
|
311 |
parent removeChild: self.
|
|
312 |
|
|
313 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"!
|
|
314 |
|
|
315 |
withAllChildren
|
|
316 |
"Answer me, my immediate children and all my grandchildren
|
|
317 |
-- in hierachical order and alphabeticaly sorted by name within one level."
|
|
318 |
|
|
319 |
| kids |
|
|
320 |
kids := OrderedCollection with: self .
|
|
321 |
self addAllChildrenTo: kids.
|
|
322 |
^kids.
|
|
323 |
|
|
324 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"!
|
|
325 |
|
|
326 |
parent
|
|
327 |
"return parent"
|
|
328 |
|
|
329 |
^ parent
|
|
330 |
|
|
331 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"!
|
|
332 |
|
|
333 |
children
|
|
334 |
"Answer my immediate children."
|
|
335 |
|
|
336 |
^ children
|
|
337 |
|
|
338 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"!
|
|
339 |
|
|
340 |
addChildren: aCollectionWithElementsOfMyKind
|
|
341 |
"add aCollectionWithElementsOfMyKind to my children"
|
|
342 |
|
|
343 |
aCollectionWithElementsOfMyKind do: [:child |
|
|
344 |
child parent: self.
|
|
345 |
child level: level +1.
|
|
346 |
].
|
|
347 |
children addAll: aCollectionWithElementsOfMyKind.
|
|
348 |
|
|
349 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"!
|
|
350 |
|
|
351 |
allParents
|
|
352 |
"return all my parents (next first - root last)"
|
|
353 |
|
|
354 |
parent isNil ifTrue: [ ^OrderedCollection new: 0 ]
|
|
355 |
ifFalse: [ ^parent, parent allParents ].
|
|
356 |
|
|
357 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"!
|
|
358 |
|
|
359 |
expandAll
|
|
360 |
"Show my children and all grand children in hierachical printouts."
|
|
361 |
|
|
362 |
hide := false.
|
|
363 |
children do: [ :kid | kid expandAll ].
|
|
364 |
|
|
365 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"!
|
|
366 |
|
|
367 |
collapseAll
|
|
368 |
"Hide my children and all my grandchildren in hierachical printouts."
|
|
369 |
|
|
370 |
hide := true.
|
|
371 |
children do: [ :kid | kid collapseAll ].
|
|
372 |
|
|
373 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"!
|
|
374 |
|
|
375 |
removeAllChildren
|
|
376 |
"Remove all children of me from the tree, i.e. let them
|
|
377 |
forget myself as parent."
|
|
378 |
|
|
379 |
| kids |
|
|
380 |
kids := self allChildren.
|
|
381 |
kids do: [:kid | kid parent: nil ].
|
|
382 |
children := Set new.
|
|
383 |
|
|
384 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"! !
|
|
385 |
|
|
386 |
!HierarchyNode methodsFor:'private'!
|
|
387 |
|
|
388 |
addAllShownChildrenTo: aCollection
|
|
389 |
"Add all my children in hierachical and alphabetical order
|
|
390 |
if they are not hidden."
|
|
391 |
|
|
392 |
|myChildren|
|
|
393 |
hide ifTrue: [^self].
|
|
394 |
myChildren := children asSortedCollection:
|
|
395 |
[:x :y | x name < y name ].
|
|
396 |
myChildren do: [:aChild |
|
|
397 |
aCollection addLast: aChild.
|
|
398 |
aChild addAllShownChildrenTo: aCollection.
|
|
399 |
].
|
|
400 |
|
|
401 |
"Modified: 10.10.94 / 16:13:35 / W.Olberding"!
|
|
402 |
|
|
403 |
addAllChildrenTo: aCollection
|
|
404 |
"Add all my children in hierachical and alphabetical order."
|
|
405 |
|
|
406 |
|myChildren|
|
|
407 |
myChildren := children asSortedCollection:
|
|
408 |
[:x :y | x name < y name ].
|
|
409 |
myChildren do: [:aChild |
|
|
410 |
aCollection addLast: aChild.
|
|
411 |
aChild addAllChildrenTo: aCollection.
|
|
412 |
].
|
|
413 |
|
|
414 |
"Modified: 10.10.94 / 16:13:35 / W.Olberding"! !
|
|
415 |
|
|
416 |
!HierarchyNode methodsFor:'initialize-release'!
|
|
417 |
|
|
418 |
initialize
|
|
419 |
"init some defaults"
|
|
420 |
|
|
421 |
" name
|
|
422 |
id
|
|
423 |
parent --"
|
|
424 |
children := Set new.
|
|
425 |
" contents := Set new."
|
|
426 |
disabled := false.
|
|
427 |
hide := false.
|
|
428 |
level := 0. "=root"
|
|
429 |
|
|
430 |
"Modified: 10.10.94 / 16:13:35 / W.Olberding"! !
|
|
431 |
|
|
432 |
!HierarchyNode methodsFor:'constants'!
|
|
433 |
|
|
434 |
delimiter
|
|
435 |
"Answer the delimiter character"
|
|
436 |
|
|
437 |
^$/
|
|
438 |
|
|
439 |
"Modified: 10.10.94 / 16:13:35 / W.Olberding"!
|
|
440 |
|
|
441 |
delimiterString
|
|
442 |
"Answer the delimiter character asString"
|
|
443 |
|
|
444 |
^self delimiter asString
|
|
445 |
|
|
446 |
"Modified: 10.10.94 / 16:13:35 / W.Olberding"! !
|
|
447 |
|
|
448 |
|