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