author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sun, 23 Jun 2019 23:04:24 +0000 | |
branch | jv |
changeset 6071 | 5182891c9a14 |
parent 5309 | badbe0ef991c |
child 5727 | 246a1c42ce5e |
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 |
||
359 | 433 |
| kids | |
84 | 434 |
|
359 | 435 |
kids := self allChildren. |
436 |
kids do: [:kid | kid parent: nil ]. |
|
435 | 437 |
children := childCollectionClass new. |
359 | 438 |
|
439 |
"Modified: 10.10.1994 / 16:13:34 / W.Olberding" |
|
440 |
"Modified: 15.4.1997 / 16:50:01 / cg" |
|
441 |
! |
|
84 | 442 |
|
443 |
removeChild: anObjectOfMyKind |
|
359 | 444 |
"remove anObjectOfMyKind from my children" |
84 | 445 |
|
446 |
anObjectOfMyKind parent: nil. |
|
359 | 447 |
children remove: anObjectOfMyKind. |
84 | 448 |
|
359 | 449 |
"Modified: 10.10.1994 / 16:13:34 / W.Olberding" |
450 |
"Modified: 15.4.1997 / 16:50:23 / cg" |
|
84 | 451 |
! |
452 |
||
453 |
removeYourself |
|
454 |
"remove me and all my children" |
|
455 |
||
456 |
parent isNil ifTrue: [^nil]. |
|
457 |
parent removeChild: self. |
|
458 |
||
359 | 459 |
"Modified: 10.10.1994 / 16:13:34 / W.Olberding" |
460 |
"Modified: 15.4.1997 / 16:52:33 / cg" |
|
461 |
! |
|
84 | 462 |
|
463 |
withAllChildren |
|
464 |
"Answer me, my immediate children and all my grandchildren |
|
465 |
-- in hierachical order and alphabeticaly sorted by name within one level." |
|
466 |
||
467 |
| kids | |
|
468 |
kids := OrderedCollection with: self . |
|
469 |
self addAllChildrenTo: kids. |
|
470 |
^kids. |
|
471 |
||
2102 | 472 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
473 |
! |
|
84 | 474 |
|
253 | 475 |
withAllShownChildren |
476 |
"Answer me, my immediate children and all my grandchildren which are |
|
477 |
currently not hidden. |
|
478 |
-- in hierachical order and alphabeticaly sorted by name within one level." |
|
84 | 479 |
|
480 |
| kids | |
|
253 | 481 |
kids := OrderedCollection with: self . |
482 |
self addAllShownChildrenTo: kids. |
|
483 |
^kids. |
|
84 | 484 |
|
2102 | 485 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
486 |
! ! |
|
84 | 487 |
|
442 | 488 |
!HierarchyNode methodsFor:'hierarchy sequencable operations'! |
489 |
||
490 |
addChildAndSubChildren:aHierarchyNode after:aChild |
|
491 |
"add aHierarchyNode to my children after an existing child or at end" |
|
492 |
||
493 |
|node index| |
|
494 |
||
495 |
node := aHierarchyNode copyWithParent:self. |
|
496 |
||
497 |
(index := self indexOfChild:aChild) == 0 ifTrue:[ |
|
498 |
self children add:node |
|
499 |
] ifFalse:[ |
|
500 |
self children add:node afterIndex:index |
|
501 |
]. |
|
502 |
! |
|
503 |
||
504 |
addChildAndSubChildren:aHierarchyNode at:anIndex |
|
505 |
"add aHierarchyNode to my children at an index or at end" |
|
506 |
||
507 |
|node cseq| |
|
508 |
||
509 |
node := aHierarchyNode copyWithParent:self. |
|
510 |
cseq := self children. |
|
511 |
||
512 |
(cseq isSequenceable and:[cseq size >= anIndex]) ifTrue:[ |
|
513 |
cseq add:node beforeIndex:anIndex |
|
514 |
] ifFalse:[ |
|
515 |
cseq add:node |
|
516 |
] |
|
517 |
! |
|
518 |
||
519 |
indexOfChild:aChild |
|
520 |
|seq| |
|
521 |
||
522 |
aChild notNil ifTrue:[ |
|
523 |
seq := self children. |
|
524 |
seq isSequenceable ifTrue:[ |
|
525 |
^ seq findFirst:[:c| c == aChild ] |
|
526 |
] |
|
527 |
]. |
|
528 |
^ 0 |
|
529 |
! ! |
|
530 |
||
2499 | 531 |
!HierarchyNode methodsFor:'initialization & release'! |
84 | 532 |
|
533 |
initialize |
|
359 | 534 |
"init some defaults" |
84 | 535 |
|
536 |
" name |
|
359 | 537 |
id |
538 |
parent --" |
|
539 |
||
435 | 540 |
childCollectionClass := Set. |
359 | 541 |
children := Set new. |
542 |
||
84 | 543 |
" contents := Set new." |
544 |
||
359 | 545 |
disabled := false. |
546 |
hide := false. |
|
547 |
level := 0. "=root" |
|
548 |
||
549 |
"Modified: 10.10.1994 / 16:13:35 / W.Olberding" |
|
550 |
"Modified: 15.4.1997 / 16:50:44 / cg" |
|
551 |
! ! |
|
84 | 552 |
|
253 | 553 |
!HierarchyNode methodsFor:'private'! |
554 |
||
359 | 555 |
addAllChildrenTo:aCollection |
556 |
"Add all my children in hierachical and alphabetical order |
|
557 |
to aCollection." |
|
558 |
||
559 |
|myChildren| |
|
84 | 560 |
|
435 | 561 |
"/ myChildren := children asSortedCollection:[:x :y | x name < y name ]. |
562 |
myChildren := self children. |
|
359 | 563 |
myChildren do:[:aChild | |
564 |
aCollection addLast: aChild. |
|
565 |
aChild addAllChildrenTo:aCollection. |
|
566 |
]. |
|
84 | 567 |
|
359 | 568 |
"Modified: 10.10.1994 / 16:13:35 / W.Olberding" |
569 |
"Modified: 15.4.1997 / 16:47:53 / cg" |
|
570 |
! |
|
84 | 571 |
|
253 | 572 |
addAllShownChildrenTo: aCollection |
359 | 573 |
"Add all my children in hierachical and alphabetical order |
574 |
if they are not hidden." |
|
575 |
||
576 |
|myChildren| |
|
84 | 577 |
|
359 | 578 |
hide ifTrue: [^self]. |
435 | 579 |
"/ myChildren := self children asSortedCollection:[:x :y | x name < y name ]. |
580 |
myChildren := self children. |
|
359 | 581 |
myChildren do: [:aChild | |
582 |
aCollection addLast: aChild. |
|
583 |
aChild addAllShownChildrenTo: aCollection. |
|
584 |
]. |
|
84 | 585 |
|
359 | 586 |
"Modified: 10.10.1994 / 16:13:35 / W.Olberding" |
587 |
"Modified: 15.4.1997 / 16:53:08 / cg" |
|
588 |
! ! |
|
84 | 589 |
|
253 | 590 |
!HierarchyNode methodsFor:'queries'! |
84 | 591 |
|
253 | 592 |
childrenHidden |
593 |
"Answer true if my children shall be hidden |
|
594 |
in hierachical printouts etc." |
|
595 |
||
596 |
^hide. |
|
597 |
||
2102 | 598 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
599 |
! |
|
253 | 600 |
|
601 |
childrenShown |
|
602 |
"Answer true if my children shall be shown |
|
603 |
in hierachical printouts etc." |
|
604 |
||
605 |
^hide not. |
|
606 |
||
2102 | 607 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
608 |
! |
|
253 | 609 |
|
610 |
hasChildren |
|
611 |
||
612 |
^children size > 0. |
|
613 |
||
2102 | 614 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
615 |
! |
|
253 | 616 |
|
617 |
isCollapsable |
|
618 |
"Answer true if I have shown children" |
|
619 |
||
620 |
self hasChildren ifTrue: [ ^hide == false ]. |
|
621 |
^false. |
|
622 |
||
2102 | 623 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
624 |
! |
|
253 | 625 |
|
626 |
isExpandable |
|
627 |
"Answer true if I have hidden children" |
|
628 |
||
629 |
self hasChildren ifTrue: [ ^hide == true ]. |
|
630 |
^false. |
|
631 |
||
2102 | 632 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding" |
633 |
! ! |
|
253 | 634 |
|
359 | 635 |
!HierarchyNode class methodsFor:'documentation'! |
253 | 636 |
|
637 |
version |
|
5309 | 638 |
^ '$Header$' |
3906 | 639 |
! |
640 |
||
641 |
version_CVS |
|
5309 | 642 |
^ '$Header$' |
253 | 643 |
! ! |
4480 | 644 |