author | Claus Gittinger <cg@exept.de> |
Mon, 27 May 2019 18:28:14 +0200 | |
changeset 6056 | 9698742110a7 |
parent 5734 | 707c76ff2d5f |
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 |
" |
|
2102 | 13 |
"{ Package: 'stx:libwidg2' }" |
14 |
||
5309 | 15 |
"{ NameSpace: Smalltalk }" |
16 |
||
84 | 17 |
Object subclass:#HierarchyNode |
435 | 18 |
instanceVariableNames:'name id parent children contents disabled hide level |
19 |
childCollectionClass' |
|
253 | 20 |
classVariableNames:'' |
21 |
poolDictionaries:'' |
|
22 |
category:'Interface-Support' |
|
84 | 23 |
! |
24 |
||
359 | 25 |
!HierarchyNode class methodsFor:'documentation'! |
84 | 26 |
|
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1994 by AEG Industry Automation |
|
30 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
31 |
All Rights Reserved |
|
32 |
||
33 |
This software is furnished under a license and may be used |
|
34 |
only in accordance with the terms of that license and with the |
|
35 |
inclusion of the above copyright notice. This software may not |
|
36 |
be provided or otherwise made available to, or used by, any |
|
37 |
other person. No title to or ownership of the software is |
|
38 |
hereby transferred. |
|
39 |
" |
|
40 |
! |
|
41 |
||
42 |
documentation |
|
43 |
" |
|
44 |
class to build up tree like structures to represent |
|
45 |
file-trees, class tress etc. |
|
46 |
Especially suited for use with SelectionInHierarchy and |
|
47 |
SelectionInHierarchyView. |
|
48 |
See examples in SelectionInHierarchyView. |
|
253 | 49 |
|
5309 | 50 |
Notice: this class (together with SelectionInHierarchy and |
1192 | 51 |
SelectionInHierarchyView) has been obsoleted by |
52 |
corresponding SelectionInTree* classes. |
|
53 |
These provide similar (but more) functionality. |
|
54 |
||
253 | 55 |
[Author:] |
56 |
W. Olberding AEG Factory Automation |
|
57 |
||
58 |
[See also:] |
|
59 |
SelectionInHierarchy |
|
60 |
SelectionInHierarchyView |
|
1192 | 61 |
SelectionInTree SelectionInTreeView TreeItem |
84 | 62 |
" |
118 | 63 |
! ! |
84 | 64 |
|
359 | 65 |
!HierarchyNode class methodsFor:'instance creation'! |
253 | 66 |
|
67 |
new |
|
3906 | 68 |
^ self basicNew initialize |
253 | 69 |
! |
84 | 70 |
|
359 | 71 |
newAsTreeFromSmalltalkClass:aClass |
72 |
"create a tree of nodes with aClass and all its |
|
73 |
subclasses as contents." |
|
84 | 74 |
|
359 | 75 |
^ self |
76 |
newAsTreeFromSmalltalkClass:aClass |
|
77 |
level:(aClass allSuperclasses size). |
|
78 |
||
79 |
"Modified: 15.4.1997 / 16:34:23 / cg" |
|
84 | 80 |
! |
81 |
||
359 | 82 |
newAsTreeFromSmalltalkClass:aClass level:level |
83 |
"create a tree of nodes with aClass and all its |
|
84 |
subclasses as contents. Set the initial level as given." |
|
85 |
||
447
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
86 |
|newInst clsName| |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
87 |
|
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
88 |
aClass isNil ifTrue:[ |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
89 |
"/ nil subclasses requested |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
90 |
clsName := 'nil' |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
91 |
] ifFalse:[ |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
92 |
"/ regular tree requested |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
93 |
clsName := aClass name |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
94 |
]. |
359 | 95 |
|
3906 | 96 |
newInst := self new. |
447
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
97 |
newInst name:clsName. |
359 | 98 |
newInst contents:aClass. |
99 |
newInst level:level. |
|
438 | 100 |
newInst childCollectionClass:OrderedCollection. |
447
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
101 |
|
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
102 |
aClass isNil ifTrue:[ |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
103 |
((Smalltalk allClasses select:[:cls | cls superclass isNil]) |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
104 |
asSortedCollection:[:a :b | a name < b name]) |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
105 |
do:[:aSubClass | |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
106 |
newInst addChild:(self newAsTreeFromSmalltalkClass:aSubClass level:level+1). |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
107 |
] |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
108 |
] ifFalse:[ |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
109 |
(aClass subclasses asSortedCollection:[:a :b | a name < b name]) |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
110 |
do:[:aSubClass | |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
111 |
newInst addChild:(self newAsTreeFromSmalltalkClass:aSubClass level:level+1). |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
112 |
] |
359 | 113 |
]. |
114 |
^newInst |
|
84 | 115 |
|
359 | 116 |
"Created: 15.4.1997 / 16:33:52 / cg" |
447
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
117 |
"Modified: 3.7.1997 / 12:25:03 / cg" |
359 | 118 |
! |
119 |
||
120 |
newWithName:aString |
|
121 |
"create a new node with a name" |
|
122 |
||
123 |
|newInst| |
|
124 |
||
3906 | 125 |
newInst := self new. |
359 | 126 |
newInst name: aString. |
127 |
^newInst |
|
128 |
||
129 |
"Modified: 15.4.1997 / 16:32:06 / cg" |
|
84 | 130 |
! |
131 |
||
132 |
newWithName: aString andId: anId |
|
359 | 133 |
"create a new node with a name and id" |
84 | 134 |
|
359 | 135 |
|newInst| |
136 |
||
3906 | 137 |
newInst := self new. |
359 | 138 |
newInst name: aString. |
139 |
newInst id: anId. |
|
140 |
^newInst |
|
141 |
||
142 |
"Modified: 15.4.1997 / 16:32:22 / cg" |
|
84 | 143 |
! ! |
144 |
||
145 |
!HierarchyNode methodsFor:'accessing'! |
|
146 |
||
435 | 147 |
childCollectionClass:aCollectionClass |
148 |
"set the class of the child-collection. |
|
149 |
Default is Set." |
|
150 |
||
151 |
childCollectionClass := aCollectionClass. |
|
152 |
children := aCollectionClass withAll:children. |
|
153 |
! |
|
154 |
||
359 | 155 |
children |
156 |
"Answer my immediate children." |
|
157 |
||
158 |
^ children |
|
159 |
||
2102 | 160 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
161 |
! |
|
359 | 162 |
|
163 |
children:aCollectionWithElementsOfMyKind |
|
253 | 164 |
"set my children" |
165 |
||
359 | 166 |
aCollectionWithElementsOfMyKind do:[:child | |
167 |
child parent: self. |
|
168 |
child level: level + 1. |
|
253 | 169 |
]. |
359 | 170 |
children := aCollectionWithElementsOfMyKind. |
253 | 171 |
|
359 | 172 |
"Modified: 10.10.1994 / 16:13:33 / W.Olberding" |
173 |
"Modified: 15.4.1997 / 16:48:38 / cg" |
|
174 |
! |
|
253 | 175 |
|
84 | 176 |
contents |
177 |
"Answer the contents of me (e.g. a set of items)" |
|
178 |
||
179 |
^contents |
|
180 |
||
2102 | 181 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
182 |
! |
|
84 | 183 |
|
184 |
contents: anObject |
|
185 |
"Set the contents of me to any object (e.g. a set of items)" |
|
186 |
||
4480 | 187 |
contents:= anObject |
84 | 188 |
|
4480 | 189 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
2102 | 190 |
! |
84 | 191 |
|
253 | 192 |
disabled |
193 |
"return disabled" |
|
194 |
||
195 |
^ disabled |
|
196 |
||
2102 | 197 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
198 |
! |
|
253 | 199 |
|
200 |
disabled: aBool |
|
201 |
"set disabled" |
|
202 |
||
203 |
disabled := aBool. |
|
204 |
||
2102 | 205 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
206 |
! |
|
253 | 207 |
|
84 | 208 |
hide: aBoolean |
209 |
||
210 |
"Set hide to aBoolean" |
|
211 |
||
212 |
hide:= aBoolean |
|
213 |
||
2102 | 214 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
215 |
! |
|
84 | 216 |
|
217 |
hideToFalseForPath |
|
218 |
"set the hide-flag to false" |
|
219 |
||
220 |
hide:= false. |
|
221 |
parent isNil ifTrue: [^self]. |
|
222 |
parent hideToFalseForPath |
|
223 |
||
2102 | 224 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
225 |
! |
|
84 | 226 |
|
227 |
id |
|
228 |
"return id" |
|
229 |
||
230 |
^ id |
|
231 |
||
2102 | 232 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
233 |
! |
|
84 | 234 |
|
235 |
id:something |
|
236 |
"set id" |
|
237 |
||
238 |
id := something. |
|
239 |
||
2102 | 240 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
241 |
! |
|
84 | 242 |
|
253 | 243 |
level |
244 |
"answer the level in hierarchy (0=root)" |
|
245 |
||
246 |
^level |
|
84 | 247 |
|
2102 | 248 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
249 |
! |
|
253 | 250 |
|
251 |
level: anInteger |
|
252 |
"set the level in hierarchy (0=root)" |
|
253 |
||
254 |
level := anInteger. |
|
84 | 255 |
|
2102 | 256 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
257 |
! |
|
84 | 258 |
|
253 | 259 |
name |
260 |
"return name" |
|
84 | 261 |
|
253 | 262 |
^ name |
84 | 263 |
|
2102 | 264 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
265 |
! |
|
84 | 266 |
|
253 | 267 |
name: aString |
268 |
"set the name that identifys me within my parent's context." |
|
269 |
||
270 |
name := aString. |
|
84 | 271 |
|
2102 | 272 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
273 |
! |
|
253 | 274 |
|
435 | 275 |
ordered:aBoolean |
276 |
"set/clear the children-are-ordered flag. |
|
277 |
If unordered (the default), children are kept in a set; |
|
278 |
if ordered, they are kept in an orderedCollection." |
|
279 |
||
280 |
aBoolean ifTrue:[ |
|
281 |
children := children asOrderedCollection |
|
282 |
] ifFalse:[ |
|
283 |
children := children asSet |
|
284 |
]. |
|
285 |
! |
|
286 |
||
253 | 287 |
parent:something |
288 |
"set parent" |
|
289 |
||
290 |
parent := something. |
|
84 | 291 |
|
2102 | 292 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
293 |
! |
|
84 | 294 |
|
295 |
pathName |
|
296 |
"return a full path name to me" |
|
297 |
||
359 | 298 |
|n| |
84 | 299 |
|
359 | 300 |
n := self delimiterString , name. |
301 |
parent isNil ifTrue: [^ n]. |
|
302 |
^ parent pathName , n. |
|
303 |
||
304 |
"Modified: 10.10.1994 / 16:13:33 / W.Olberding" |
|
305 |
"Modified: 15.4.1997 / 16:52:02 / cg" |
|
306 |
! ! |
|
84 | 307 |
|
253 | 308 |
!HierarchyNode methodsFor:'constants'! |
84 | 309 |
|
253 | 310 |
delimiter |
311 |
"Answer the delimiter character" |
|
84 | 312 |
|
253 | 313 |
^$/ |
84 | 314 |
|
2102 | 315 |
"Modified: 10.10.94 / 16:13:35 / W.Olberding" |
316 |
! |
|
84 | 317 |
|
253 | 318 |
delimiterString |
319 |
"Answer the delimiter character asString" |
|
84 | 320 |
|
253 | 321 |
^self delimiter asString |
84 | 322 |
|
2102 | 323 |
"Modified: 10.10.94 / 16:13:35 / W.Olberding" |
324 |
! ! |
|
84 | 325 |
|
2102 | 326 |
!HierarchyNode methodsFor:'copying'! |
439 | 327 |
|
328 |
copyWithParent:aParent |
|
566 | 329 |
|node| |
439 | 330 |
|
331 |
node := self copy. |
|
332 |
node parent:aParent. |
|
333 |
node level:((aParent level) + 1). |
|
334 |
node children:(children collect:[:aChild| aChild copyWithParent:self]). |
|
335 |
^ node |
|
336 |
! ! |
|
337 |
||
84 | 338 |
!HierarchyNode methodsFor:'hierarchy operations'! |
339 |
||
359 | 340 |
addChild:anObjectOfMyKind |
253 | 341 |
"add anObjectOfMyKind to my children" |
342 |
||
343 |
anObjectOfMyKind parent: self. |
|
344 |
anObjectOfMyKind level: level +1. |
|
359 | 345 |
self children add:anObjectOfMyKind. |
253 | 346 |
|
359 | 347 |
"Modified: 10.10.1994 / 16:13:34 / W.Olberding" |
348 |
"Modified: 15.4.1997 / 16:49:17 / cg" |
|
349 |
! |
|
84 | 350 |
|
253 | 351 |
addChildren: aCollectionWithElementsOfMyKind |
352 |
"add aCollectionWithElementsOfMyKind to my children" |
|
353 |
||
359 | 354 |
aCollectionWithElementsOfMyKind do:[:child | |
355 |
child parent: self. |
|
356 |
child level: level +1. |
|
253 | 357 |
]. |
359 | 358 |
self children addAll:aCollectionWithElementsOfMyKind. |
84 | 359 |
|
359 | 360 |
"Modified: 10.10.1994 / 16:13:34 / W.Olberding" |
361 |
"Modified: 15.4.1997 / 16:49:03 / cg" |
|
362 |
! |
|
84 | 363 |
|
364 |
allChildren |
|
365 |
"Answer my immediate children plus all my grandchildren |
|
366 |
-- in hierachical order and alphabeticaly sorted by name within one level." |
|
367 |
||
368 |
| kids | |
|
369 |
kids := OrderedCollection new. |
|
370 |
self addAllChildrenTo: kids. |
|
371 |
^kids. |
|
372 |
||
2102 | 373 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
374 |
! |
|
84 | 375 |
|
253 | 376 |
allParents |
377 |
"return all my parents (next first - root last)" |
|
378 |
||
379 |
parent isNil ifTrue: [ ^OrderedCollection new: 0 ] |
|
380 |
ifFalse: [ ^parent, parent allParents ]. |
|
381 |
||
2102 | 382 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
383 |
! |
|
253 | 384 |
|
385 |
collapse |
|
386 |
"Hide my children in hierachical printouts." |
|
387 |
||
388 |
hide := true |
|
389 |
||
2102 | 390 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
391 |
! |
|
253 | 392 |
|
393 |
collapseAll |
|
359 | 394 |
"Hide my children and all my grandchildren in hierachical printouts." |
253 | 395 |
|
359 | 396 |
hide := true. |
397 |
self children do: [:kid | kid collapseAll ]. |
|
84 | 398 |
|
359 | 399 |
"Modified: 10.10.1994 / 16:13:34 / W.Olberding" |
400 |
"Modified: 15.4.1997 / 16:49:34 / cg" |
|
401 |
! |
|
84 | 402 |
|
403 |
expand |
|
404 |
"Show my immediate children in hierachical printouts." |
|
405 |
||
406 |
hide := false. |
|
407 |
||
2102 | 408 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
409 |
! |
|
84 | 410 |
|
253 | 411 |
expandAll |
359 | 412 |
"Show my children and all grand children in hierachical printouts." |
253 | 413 |
|
359 | 414 |
hide := false. |
415 |
self children do: [:kid | kid expandAll ]. |
|
253 | 416 |
|
359 | 417 |
"Modified: 10.10.1994 / 16:13:34 / W.Olberding" |
418 |
"Modified: 15.4.1997 / 16:49:48 / cg" |
|
419 |
! |
|
253 | 420 |
|
421 |
parent |
|
422 |
"return parent" |
|
84 | 423 |
|
253 | 424 |
^ parent |
425 |
||
2102 | 426 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
427 |
! |
|
253 | 428 |
|
429 |
removeAllChildren |
|
430 |
"Remove all children of me from the tree, i.e. let them |
|
431 |
forget myself as parent." |
|
432 |
||
5727 | 433 |
self allChildren do: [:kid | kid parent: nil ]. |
435 | 434 |
children := childCollectionClass new. |
359 | 435 |
|
5727 | 436 |
"Modified: / 10-10-1994 / 16:13:34 / W.Olberding" |
437 |
"Modified: / 15-04-1997 / 16:50:01 / cg" |
|
438 |
"Modified: / 23-03-2018 / 15:48:21 / stefan" |
|
359 | 439 |
! |
84 | 440 |
|
441 |
removeChild: anObjectOfMyKind |
|
359 | 442 |
"remove anObjectOfMyKind from my children" |
84 | 443 |
|
444 |
anObjectOfMyKind parent: nil. |
|
359 | 445 |
children remove: anObjectOfMyKind. |
84 | 446 |
|
359 | 447 |
"Modified: 10.10.1994 / 16:13:34 / W.Olberding" |
448 |
"Modified: 15.4.1997 / 16:50:23 / cg" |
|
84 | 449 |
! |
450 |
||
451 |
removeYourself |
|
452 |
"remove me and all my children" |
|
453 |
||
454 |
parent isNil ifTrue: [^nil]. |
|
455 |
parent removeChild: self. |
|
456 |
||
359 | 457 |
"Modified: 10.10.1994 / 16:13:34 / W.Olberding" |
458 |
"Modified: 15.4.1997 / 16:52:33 / cg" |
|
459 |
! |
|
84 | 460 |
|
461 |
withAllChildren |
|
462 |
"Answer me, my immediate children and all my grandchildren |
|
463 |
-- in hierachical order and alphabeticaly sorted by name within one level." |
|
464 |
||
465 |
| kids | |
|
466 |
kids := OrderedCollection with: self . |
|
467 |
self addAllChildrenTo: kids. |
|
468 |
^kids. |
|
469 |
||
2102 | 470 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
471 |
! |
|
84 | 472 |
|
253 | 473 |
withAllShownChildren |
474 |
"Answer me, my immediate children and all my grandchildren which are |
|
475 |
currently not hidden. |
|
476 |
-- in hierachical order and alphabeticaly sorted by name within one level." |
|
84 | 477 |
|
478 |
| kids | |
|
253 | 479 |
kids := OrderedCollection with: self . |
480 |
self addAllShownChildrenTo: kids. |
|
481 |
^kids. |
|
84 | 482 |
|
2102 | 483 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
484 |
! ! |
|
84 | 485 |
|
442 | 486 |
!HierarchyNode methodsFor:'hierarchy sequencable operations'! |
487 |
||
488 |
addChildAndSubChildren:aHierarchyNode after:aChild |
|
489 |
"add aHierarchyNode to my children after an existing child or at end" |
|
490 |
||
491 |
|node index| |
|
492 |
||
493 |
node := aHierarchyNode copyWithParent:self. |
|
494 |
||
495 |
(index := self indexOfChild:aChild) == 0 ifTrue:[ |
|
496 |
self children add:node |
|
497 |
] ifFalse:[ |
|
498 |
self children add:node afterIndex:index |
|
499 |
]. |
|
500 |
! |
|
501 |
||
502 |
addChildAndSubChildren:aHierarchyNode at:anIndex |
|
503 |
"add aHierarchyNode to my children at an index or at end" |
|
504 |
||
505 |
|node cseq| |
|
506 |
||
507 |
node := aHierarchyNode copyWithParent:self. |
|
508 |
cseq := self children. |
|
509 |
||
510 |
(cseq isSequenceable and:[cseq size >= anIndex]) ifTrue:[ |
|
511 |
cseq add:node beforeIndex:anIndex |
|
512 |
] ifFalse:[ |
|
513 |
cseq add:node |
|
514 |
] |
|
515 |
! |
|
516 |
||
517 |
indexOfChild:aChild |
|
518 |
|seq| |
|
519 |
||
520 |
aChild notNil ifTrue:[ |
|
521 |
seq := self children. |
|
522 |
seq isSequenceable ifTrue:[ |
|
523 |
^ seq findFirst:[:c| c == aChild ] |
|
524 |
] |
|
525 |
]. |
|
526 |
^ 0 |
|
527 |
! ! |
|
528 |
||
2499 | 529 |
!HierarchyNode methodsFor:'initialization & release'! |
84 | 530 |
|
531 |
initialize |
|
359 | 532 |
"init some defaults" |
84 | 533 |
|
534 |
" name |
|
359 | 535 |
id |
536 |
parent --" |
|
537 |
||
435 | 538 |
childCollectionClass := Set. |
359 | 539 |
children := Set new. |
540 |
||
84 | 541 |
" contents := Set new." |
542 |
||
359 | 543 |
disabled := false. |
544 |
hide := false. |
|
545 |
level := 0. "=root" |
|
546 |
||
547 |
"Modified: 10.10.1994 / 16:13:35 / W.Olberding" |
|
548 |
"Modified: 15.4.1997 / 16:50:44 / cg" |
|
549 |
! ! |
|
84 | 550 |
|
253 | 551 |
!HierarchyNode methodsFor:'private'! |
552 |
||
359 | 553 |
addAllChildrenTo:aCollection |
554 |
"Add all my children in hierachical and alphabetical order |
|
555 |
to aCollection." |
|
556 |
||
557 |
|myChildren| |
|
84 | 558 |
|
435 | 559 |
"/ myChildren := children asSortedCollection:[:x :y | x name < y name ]. |
560 |
myChildren := self children. |
|
359 | 561 |
myChildren do:[:aChild | |
562 |
aCollection addLast: aChild. |
|
563 |
aChild addAllChildrenTo:aCollection. |
|
564 |
]. |
|
84 | 565 |
|
359 | 566 |
"Modified: 10.10.1994 / 16:13:35 / W.Olberding" |
567 |
"Modified: 15.4.1997 / 16:47:53 / cg" |
|
568 |
! |
|
84 | 569 |
|
253 | 570 |
addAllShownChildrenTo: aCollection |
359 | 571 |
"Add all my children in hierachical and alphabetical order |
572 |
if they are not hidden." |
|
573 |
||
574 |
|myChildren| |
|
84 | 575 |
|
359 | 576 |
hide ifTrue: [^self]. |
435 | 577 |
"/ myChildren := self children asSortedCollection:[:x :y | x name < y name ]. |
578 |
myChildren := self children. |
|
359 | 579 |
myChildren do: [:aChild | |
580 |
aCollection addLast: aChild. |
|
581 |
aChild addAllShownChildrenTo: aCollection. |
|
582 |
]. |
|
84 | 583 |
|
359 | 584 |
"Modified: 10.10.1994 / 16:13:35 / W.Olberding" |
585 |
"Modified: 15.4.1997 / 16:53:08 / cg" |
|
586 |
! ! |
|
84 | 587 |
|
253 | 588 |
!HierarchyNode methodsFor:'queries'! |
84 | 589 |
|
253 | 590 |
childrenHidden |
591 |
"Answer true if my children shall be hidden |
|
592 |
in hierachical printouts etc." |
|
593 |
||
594 |
^hide. |
|
595 |
||
2102 | 596 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
597 |
! |
|
253 | 598 |
|
599 |
childrenShown |
|
600 |
"Answer true if my children shall be shown |
|
601 |
in hierachical printouts etc." |
|
602 |
||
603 |
^hide not. |
|
604 |
||
2102 | 605 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
606 |
! |
|
253 | 607 |
|
608 |
hasChildren |
|
5734 | 609 |
^ children notEmptyOrNil. |
253 | 610 |
|
5734 | 611 |
"Modified: / 10-10-1994 / 16:13:33 / W.Olberding" |
612 |
"Modified: / 17-04-2018 / 17:44:00 / stefan" |
|
2102 | 613 |
! |
253 | 614 |
|
615 |
isCollapsable |
|
616 |
"Answer true if I have shown children" |
|
617 |
||
618 |
self hasChildren ifTrue: [ ^hide == false ]. |
|
619 |
^false. |
|
620 |
||
2102 | 621 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
622 |
! |
|
253 | 623 |
|
624 |
isExpandable |
|
625 |
"Answer true if I have hidden children" |
|
626 |
||
627 |
self hasChildren ifTrue: [ ^hide == true ]. |
|
628 |
^false. |
|
629 |
||
2102 | 630 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
631 |
! ! |
|
253 | 632 |
|
359 | 633 |
!HierarchyNode class methodsFor:'documentation'! |
253 | 634 |
|
635 |
version |
|
5309 | 636 |
^ '$Header$' |
3906 | 637 |
! |
638 |
||
639 |
version_CVS |
|
5309 | 640 |
^ '$Header$' |
253 | 641 |
! ! |
4480 | 642 |