author | Claus Gittinger <cg@exept.de> |
Fri, 06 May 2016 18:07:42 +0200 | |
changeset 5076 | 9d8cf635a6cb |
parent 4480 | 879db1acef5a |
child 5309 | badbe0ef991c |
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 |
||
84 | 15 |
Object subclass:#HierarchyNode |
435 | 16 |
instanceVariableNames:'name id parent children contents disabled hide level |
17 |
childCollectionClass' |
|
253 | 18 |
classVariableNames:'' |
19 |
poolDictionaries:'' |
|
20 |
category:'Interface-Support' |
|
84 | 21 |
! |
22 |
||
359 | 23 |
!HierarchyNode class methodsFor:'documentation'! |
84 | 24 |
|
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1994 by AEG Industry Automation |
|
28 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
! |
|
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
class to build up tree like structures to represent |
|
43 |
file-trees, class tress etc. |
|
44 |
Especially suited for use with SelectionInHierarchy and |
|
45 |
SelectionInHierarchyView. |
|
46 |
See examples in SelectionInHierarchyView. |
|
253 | 47 |
|
1192 | 48 |
Notce: this class (together with SelectionInHierarchy and |
49 |
SelectionInHierarchyView) has been obsoleted by |
|
50 |
corresponding SelectionInTree* classes. |
|
51 |
These provide similar (but more) functionality. |
|
52 |
||
253 | 53 |
[Author:] |
54 |
W. Olberding AEG Factory Automation |
|
55 |
||
56 |
[See also:] |
|
57 |
SelectionInHierarchy |
|
58 |
SelectionInHierarchyView |
|
1192 | 59 |
SelectionInTree SelectionInTreeView TreeItem |
84 | 60 |
" |
118 | 61 |
! ! |
84 | 62 |
|
359 | 63 |
!HierarchyNode class methodsFor:'instance creation'! |
253 | 64 |
|
65 |
new |
|
3906 | 66 |
^ self basicNew initialize |
253 | 67 |
! |
84 | 68 |
|
359 | 69 |
newAsTreeFromSmalltalkClass:aClass |
70 |
"create a tree of nodes with aClass and all its |
|
71 |
subclasses as contents." |
|
84 | 72 |
|
359 | 73 |
^ self |
74 |
newAsTreeFromSmalltalkClass:aClass |
|
75 |
level:(aClass allSuperclasses size). |
|
76 |
||
77 |
"Modified: 15.4.1997 / 16:34:23 / cg" |
|
84 | 78 |
! |
79 |
||
359 | 80 |
newAsTreeFromSmalltalkClass:aClass level:level |
81 |
"create a tree of nodes with aClass and all its |
|
82 |
subclasses as contents. Set the initial level as given." |
|
83 |
||
447
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
84 |
|newInst clsName| |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
85 |
|
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
86 |
aClass isNil ifTrue:[ |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
87 |
"/ nil subclasses requested |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
88 |
clsName := 'nil' |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
89 |
] ifFalse:[ |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
90 |
"/ regular tree requested |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
91 |
clsName := aClass name |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
92 |
]. |
359 | 93 |
|
3906 | 94 |
newInst := self new. |
447
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
95 |
newInst name:clsName. |
359 | 96 |
newInst contents:aClass. |
97 |
newInst level:level. |
|
438 | 98 |
newInst childCollectionClass:OrderedCollection. |
447
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
99 |
|
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
100 |
aClass isNil ifTrue:[ |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
101 |
((Smalltalk allClasses select:[:cls | cls superclass isNil]) |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
102 |
asSortedCollection:[:a :b | a name < b name]) |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
103 |
do:[:aSubClass | |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
104 |
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
|
105 |
] |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
106 |
] ifFalse:[ |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
107 |
(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
|
108 |
do:[:aSubClass | |
705b618eb324
changed #newAsTreeFromSmalltalk to handle nil-superclass tree
Claus Gittinger <cg@exept.de>
parents:
442
diff
changeset
|
109 |
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
|
110 |
] |
359 | 111 |
]. |
112 |
^newInst |
|
84 | 113 |
|
359 | 114 |
"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
|
115 |
"Modified: 3.7.1997 / 12:25:03 / cg" |
359 | 116 |
! |
117 |
||
118 |
newWithName:aString |
|
119 |
"create a new node with a name" |
|
120 |
||
121 |
|newInst| |
|
122 |
||
3906 | 123 |
newInst := self new. |
359 | 124 |
newInst name: aString. |
125 |
^newInst |
|
126 |
||
127 |
"Modified: 15.4.1997 / 16:32:06 / cg" |
|
84 | 128 |
! |
129 |
||
130 |
newWithName: aString andId: anId |
|
359 | 131 |
"create a new node with a name and id" |
84 | 132 |
|
359 | 133 |
|newInst| |
134 |
||
3906 | 135 |
newInst := self new. |
359 | 136 |
newInst name: aString. |
137 |
newInst id: anId. |
|
138 |
^newInst |
|
139 |
||
140 |
"Modified: 15.4.1997 / 16:32:22 / cg" |
|
84 | 141 |
! ! |
142 |
||
143 |
!HierarchyNode methodsFor:'accessing'! |
|
144 |
||
435 | 145 |
childCollectionClass:aCollectionClass |
146 |
"set the class of the child-collection. |
|
147 |
Default is Set." |
|
148 |
||
149 |
childCollectionClass := aCollectionClass. |
|
150 |
children := aCollectionClass withAll:children. |
|
151 |
! |
|
152 |
||
359 | 153 |
children |
154 |
"Answer my immediate children." |
|
155 |
||
156 |
^ children |
|
157 |
||
2102 | 158 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
159 |
! |
|
359 | 160 |
|
161 |
children:aCollectionWithElementsOfMyKind |
|
253 | 162 |
"set my children" |
163 |
||
359 | 164 |
aCollectionWithElementsOfMyKind do:[:child | |
165 |
child parent: self. |
|
166 |
child level: level + 1. |
|
253 | 167 |
]. |
359 | 168 |
children := aCollectionWithElementsOfMyKind. |
253 | 169 |
|
359 | 170 |
"Modified: 10.10.1994 / 16:13:33 / W.Olberding" |
171 |
"Modified: 15.4.1997 / 16:48:38 / cg" |
|
172 |
! |
|
253 | 173 |
|
84 | 174 |
contents |
175 |
"Answer the contents of me (e.g. a set of items)" |
|
176 |
||
177 |
^contents |
|
178 |
||
2102 | 179 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
180 |
! |
|
84 | 181 |
|
182 |
contents: anObject |
|
183 |
"Set the contents of me to any object (e.g. a set of items)" |
|
184 |
||
4480 | 185 |
contents:= anObject |
84 | 186 |
|
4480 | 187 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
2102 | 188 |
! |
84 | 189 |
|
253 | 190 |
disabled |
191 |
"return disabled" |
|
192 |
||
193 |
^ disabled |
|
194 |
||
2102 | 195 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
196 |
! |
|
253 | 197 |
|
198 |
disabled: aBool |
|
199 |
"set disabled" |
|
200 |
||
201 |
disabled := aBool. |
|
202 |
||
2102 | 203 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
204 |
! |
|
253 | 205 |
|
84 | 206 |
hide: aBoolean |
207 |
||
208 |
"Set hide to aBoolean" |
|
209 |
||
210 |
hide:= aBoolean |
|
211 |
||
2102 | 212 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
213 |
! |
|
84 | 214 |
|
215 |
hideToFalseForPath |
|
216 |
"set the hide-flag to false" |
|
217 |
||
218 |
hide:= false. |
|
219 |
parent isNil ifTrue: [^self]. |
|
220 |
parent hideToFalseForPath |
|
221 |
||
2102 | 222 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
223 |
! |
|
84 | 224 |
|
225 |
id |
|
226 |
"return id" |
|
227 |
||
228 |
^ id |
|
229 |
||
2102 | 230 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
231 |
! |
|
84 | 232 |
|
233 |
id:something |
|
234 |
"set id" |
|
235 |
||
236 |
id := something. |
|
237 |
||
2102 | 238 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
239 |
! |
|
84 | 240 |
|
253 | 241 |
level |
242 |
"answer the level in hierarchy (0=root)" |
|
243 |
||
244 |
^level |
|
84 | 245 |
|
2102 | 246 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
247 |
! |
|
253 | 248 |
|
249 |
level: anInteger |
|
250 |
"set the level in hierarchy (0=root)" |
|
251 |
||
252 |
level := anInteger. |
|
84 | 253 |
|
2102 | 254 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
255 |
! |
|
84 | 256 |
|
253 | 257 |
name |
258 |
"return name" |
|
84 | 259 |
|
253 | 260 |
^ name |
84 | 261 |
|
2102 | 262 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
263 |
! |
|
84 | 264 |
|
253 | 265 |
name: aString |
266 |
"set the name that identifys me within my parent's context." |
|
267 |
||
268 |
name := aString. |
|
84 | 269 |
|
2102 | 270 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
271 |
! |
|
253 | 272 |
|
435 | 273 |
ordered:aBoolean |
274 |
"set/clear the children-are-ordered flag. |
|
275 |
If unordered (the default), children are kept in a set; |
|
276 |
if ordered, they are kept in an orderedCollection." |
|
277 |
||
278 |
aBoolean ifTrue:[ |
|
279 |
children := children asOrderedCollection |
|
280 |
] ifFalse:[ |
|
281 |
children := children asSet |
|
282 |
]. |
|
283 |
! |
|
284 |
||
253 | 285 |
parent:something |
286 |
"set parent" |
|
287 |
||
288 |
parent := something. |
|
84 | 289 |
|
2102 | 290 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
291 |
! |
|
84 | 292 |
|
293 |
pathName |
|
294 |
"return a full path name to me" |
|
295 |
||
359 | 296 |
|n| |
84 | 297 |
|
359 | 298 |
n := self delimiterString , name. |
299 |
parent isNil ifTrue: [^ n]. |
|
300 |
^ parent pathName , n. |
|
301 |
||
302 |
"Modified: 10.10.1994 / 16:13:33 / W.Olberding" |
|
303 |
"Modified: 15.4.1997 / 16:52:02 / cg" |
|
304 |
! ! |
|
84 | 305 |
|
253 | 306 |
!HierarchyNode methodsFor:'constants'! |
84 | 307 |
|
253 | 308 |
delimiter |
309 |
"Answer the delimiter character" |
|
84 | 310 |
|
253 | 311 |
^$/ |
84 | 312 |
|
2102 | 313 |
"Modified: 10.10.94 / 16:13:35 / W.Olberding" |
314 |
! |
|
84 | 315 |
|
253 | 316 |
delimiterString |
317 |
"Answer the delimiter character asString" |
|
84 | 318 |
|
253 | 319 |
^self delimiter asString |
84 | 320 |
|
2102 | 321 |
"Modified: 10.10.94 / 16:13:35 / W.Olberding" |
322 |
! ! |
|
84 | 323 |
|
2102 | 324 |
!HierarchyNode methodsFor:'copying'! |
439 | 325 |
|
326 |
copyWithParent:aParent |
|
566 | 327 |
|node| |
439 | 328 |
|
329 |
node := self copy. |
|
330 |
node parent:aParent. |
|
331 |
node level:((aParent level) + 1). |
|
332 |
node children:(children collect:[:aChild| aChild copyWithParent:self]). |
|
333 |
^ node |
|
334 |
! ! |
|
335 |
||
84 | 336 |
!HierarchyNode methodsFor:'hierarchy operations'! |
337 |
||
359 | 338 |
addChild:anObjectOfMyKind |
253 | 339 |
"add anObjectOfMyKind to my children" |
340 |
||
341 |
anObjectOfMyKind parent: self. |
|
342 |
anObjectOfMyKind level: level +1. |
|
359 | 343 |
self children add:anObjectOfMyKind. |
253 | 344 |
|
359 | 345 |
"Modified: 10.10.1994 / 16:13:34 / W.Olberding" |
346 |
"Modified: 15.4.1997 / 16:49:17 / cg" |
|
347 |
! |
|
84 | 348 |
|
253 | 349 |
addChildren: aCollectionWithElementsOfMyKind |
350 |
"add aCollectionWithElementsOfMyKind to my children" |
|
351 |
||
359 | 352 |
aCollectionWithElementsOfMyKind do:[:child | |
353 |
child parent: self. |
|
354 |
child level: level +1. |
|
253 | 355 |
]. |
359 | 356 |
self children addAll:aCollectionWithElementsOfMyKind. |
84 | 357 |
|
359 | 358 |
"Modified: 10.10.1994 / 16:13:34 / W.Olberding" |
359 |
"Modified: 15.4.1997 / 16:49:03 / cg" |
|
360 |
! |
|
84 | 361 |
|
362 |
allChildren |
|
363 |
"Answer my immediate children plus all my grandchildren |
|
364 |
-- in hierachical order and alphabeticaly sorted by name within one level." |
|
365 |
||
366 |
| kids | |
|
367 |
kids := OrderedCollection new. |
|
368 |
self addAllChildrenTo: kids. |
|
369 |
^kids. |
|
370 |
||
2102 | 371 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
372 |
! |
|
84 | 373 |
|
253 | 374 |
allParents |
375 |
"return all my parents (next first - root last)" |
|
376 |
||
377 |
parent isNil ifTrue: [ ^OrderedCollection new: 0 ] |
|
378 |
ifFalse: [ ^parent, parent allParents ]. |
|
379 |
||
2102 | 380 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
381 |
! |
|
253 | 382 |
|
383 |
collapse |
|
384 |
"Hide my children in hierachical printouts." |
|
385 |
||
386 |
hide := true |
|
387 |
||
2102 | 388 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
389 |
! |
|
253 | 390 |
|
391 |
collapseAll |
|
359 | 392 |
"Hide my children and all my grandchildren in hierachical printouts." |
253 | 393 |
|
359 | 394 |
hide := true. |
395 |
self children do: [:kid | kid collapseAll ]. |
|
84 | 396 |
|
359 | 397 |
"Modified: 10.10.1994 / 16:13:34 / W.Olberding" |
398 |
"Modified: 15.4.1997 / 16:49:34 / cg" |
|
399 |
! |
|
84 | 400 |
|
401 |
expand |
|
402 |
"Show my immediate children in hierachical printouts." |
|
403 |
||
404 |
hide := false. |
|
405 |
||
2102 | 406 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
407 |
! |
|
84 | 408 |
|
253 | 409 |
expandAll |
359 | 410 |
"Show my children and all grand children in hierachical printouts." |
253 | 411 |
|
359 | 412 |
hide := false. |
413 |
self children do: [:kid | kid expandAll ]. |
|
253 | 414 |
|
359 | 415 |
"Modified: 10.10.1994 / 16:13:34 / W.Olberding" |
416 |
"Modified: 15.4.1997 / 16:49:48 / cg" |
|
417 |
! |
|
253 | 418 |
|
419 |
parent |
|
420 |
"return parent" |
|
84 | 421 |
|
253 | 422 |
^ parent |
423 |
||
2102 | 424 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
425 |
! |
|
253 | 426 |
|
427 |
removeAllChildren |
|
428 |
"Remove all children of me from the tree, i.e. let them |
|
429 |
forget myself as parent." |
|
430 |
||
359 | 431 |
| kids | |
84 | 432 |
|
359 | 433 |
kids := self allChildren. |
434 |
kids do: [:kid | kid parent: nil ]. |
|
435 | 435 |
children := childCollectionClass new. |
359 | 436 |
|
437 |
"Modified: 10.10.1994 / 16:13:34 / W.Olberding" |
|
438 |
"Modified: 15.4.1997 / 16:50:01 / cg" |
|
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 |
|
609 |
||
610 |
^children size > 0. |
|
611 |
||
2102 | 612 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
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 |
|
4480 | 636 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchyNode.st,v 1.17 2014-02-05 10:02:51 cg Exp $' |
3906 | 637 |
! |
638 |
||
639 |
version_CVS |
|
4480 | 640 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchyNode.st,v 1.17 2014-02-05 10:02:51 cg Exp $' |
253 | 641 |
! ! |
4480 | 642 |