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