author | Claus Gittinger <cg@exept.de> |
Sat, 11 Nov 1995 17:30:31 +0100 | |
changeset 86 | 4d7dbb5f1719 |
parent 84 | 4478ea2d40c2 |
child 118 | 2821a094ba30 |
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 |
||
14 |
Object subclass:#HierarchyNode |
|
15 |
instanceVariableNames:'name id parent children contents disabled hide level' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Interface-Support' |
|
19 |
! |
|
20 |
||
21 |
!HierarchyNode class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1994 by AEG Industry Automation |
|
26 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
version |
|
86
4d7dbb5f1719
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
84
diff
changeset
|
39 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchyNode.st,v 1.2 1995-11-11 16:29:00 cg Exp $' |
84 | 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. |
|
49 |
" |
|
50 |
! |
|
51 |
||
52 |
!HierarchyNode class methodsFor:'instance creation'! |
|
53 |
||
54 |
newAsTreeFromSmalltalkClass: aClass |
|
55 |
||
56 |
"create a tree of nodes with aClass and all its |
|
57 |
subclasses as contents." |
|
58 |
||
59 |
|newInst| |
|
60 |
newInst := super new initialize. |
|
61 |
newInst name: aClass name. |
|
62 |
newInst contents: aClass. |
|
63 |
newInst level: aClass allSuperclasses size. |
|
64 |
aClass subclasses do: [ :aSubClass | |
|
65 |
newInst addChild: (self newAsTreeFromSmalltalkClass: aSubClass). |
|
66 |
]. |
|
67 |
^newInst |
|
68 |
! |
|
69 |
||
70 |
newWithName: aString |
|
71 |
||
72 |
|newInst| |
|
73 |
newInst := super new initialize. |
|
74 |
newInst name: aString. |
|
75 |
^newInst |
|
76 |
! |
|
77 |
||
78 |
new |
|
79 |
||
80 |
^super new initialize |
|
81 |
! |
|
82 |
||
83 |
newWithName: aString andId: anId |
|
84 |
||
85 |
|newInst| |
|
86 |
newInst := super new initialize. |
|
87 |
newInst name: aString. |
|
88 |
newInst id: anId. |
|
89 |
^newInst |
|
90 |
! ! |
|
91 |
||
92 |
!HierarchyNode methodsFor:'accessing'! |
|
93 |
||
94 |
contents |
|
95 |
"Answer the contents of me (e.g. a set of items)" |
|
96 |
||
97 |
^contents |
|
98 |
||
99 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
100 |
||
101 |
name |
|
102 |
"return name" |
|
103 |
||
104 |
^ name |
|
105 |
||
106 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
107 |
||
108 |
level |
|
109 |
"answer the level in hierarchy (0=root)" |
|
110 |
||
111 |
^level |
|
112 |
||
113 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
114 |
||
115 |
contents: anObject |
|
116 |
"Set the contents of me to any object (e.g. a set of items)" |
|
117 |
||
118 |
^contents:= anObject |
|
119 |
||
120 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
121 |
||
122 |
hide: aBoolean |
|
123 |
||
124 |
"Set hide to aBoolean" |
|
125 |
||
126 |
hide:= aBoolean |
|
127 |
||
128 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
129 |
||
130 |
level: anInteger |
|
131 |
"set the level in hierarchy (0=root)" |
|
132 |
||
133 |
level := anInteger. |
|
134 |
||
135 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
136 |
||
137 |
hideToFalseForPath |
|
138 |
"set the hide-flag to false" |
|
139 |
||
140 |
hide:= false. |
|
141 |
parent isNil ifTrue: [^self]. |
|
142 |
parent hideToFalseForPath |
|
143 |
||
144 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
145 |
||
146 |
parent:something |
|
147 |
"set parent" |
|
148 |
||
149 |
parent := something. |
|
150 |
||
151 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
152 |
||
153 |
name: aString |
|
154 |
"set the name that identifys me within my parent's context." |
|
155 |
||
156 |
name := aString. |
|
157 |
||
158 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
159 |
||
160 |
id |
|
161 |
"return id" |
|
162 |
||
163 |
^ id |
|
164 |
||
165 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
166 |
||
167 |
id:something |
|
168 |
"set id" |
|
169 |
||
170 |
id := something. |
|
171 |
||
172 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
173 |
||
174 |
children: aCollectionWithElementsOfMyKind |
|
175 |
"set my children" |
|
176 |
||
177 |
aCollectionWithElementsOfMyKind do: [:child | |
|
178 |
child parent: self. |
|
179 |
child level: level +1. |
|
180 |
]. |
|
181 |
children := aCollectionWithElementsOfMyKind. |
|
182 |
||
183 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
184 |
||
185 |
disabled |
|
186 |
"return disabled" |
|
187 |
||
188 |
^ disabled |
|
189 |
||
190 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
191 |
||
192 |
disabled: aBool |
|
193 |
"set disabled" |
|
194 |
||
195 |
disabled := aBool. |
|
196 |
||
197 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
198 |
||
199 |
pathName |
|
200 |
"return a full path name to me" |
|
201 |
||
202 |
parent isNil ifTrue: [^ (self delimiterString), name]. |
|
203 |
^parent pathName, (self delimiterString), name. |
|
204 |
||
205 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! ! |
|
206 |
||
207 |
!HierarchyNode methodsFor:'queries'! |
|
208 |
||
209 |
hasChildren |
|
210 |
||
211 |
^children size > 0. |
|
212 |
||
213 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
214 |
||
215 |
isExpandable |
|
216 |
"Answer true if I have hidden children" |
|
217 |
||
218 |
self hasChildren ifTrue: [ ^hide == true ]. |
|
219 |
^false. |
|
220 |
||
221 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
222 |
||
223 |
isCollapsable |
|
224 |
"Answer true if I have shown children" |
|
225 |
||
226 |
self hasChildren ifTrue: [ ^hide == false ]. |
|
227 |
^false. |
|
228 |
||
229 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
230 |
||
231 |
childrenHidden |
|
232 |
"Answer true if my children shall be hidden |
|
233 |
in hierachical printouts etc." |
|
234 |
||
235 |
^hide. |
|
236 |
||
237 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! |
|
238 |
||
239 |
childrenShown |
|
240 |
"Answer true if my children shall be shown |
|
241 |
in hierachical printouts etc." |
|
242 |
||
243 |
^hide not. |
|
244 |
||
245 |
"Modified: 10.10.94 / 16:13:33 / W.Olberding"! ! |
|
246 |
||
247 |
!HierarchyNode methodsFor:'hierarchy operations'! |
|
248 |
||
249 |
withAllShownChildren |
|
250 |
"Answer me, my immediate children and all my grandchildren which are |
|
251 |
currently not hidden. |
|
252 |
-- in hierachical order and alphabeticaly sorted by name within one level." |
|
253 |
||
254 |
| kids | |
|
255 |
kids := OrderedCollection with: self . |
|
256 |
self addAllShownChildrenTo: kids. |
|
257 |
^kids. |
|
258 |
||
259 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"! |
|
260 |
||
261 |
allChildren |
|
262 |
"Answer my immediate children plus all my grandchildren |
|
263 |
-- in hierachical order and alphabeticaly sorted by name within one level." |
|
264 |
||
265 |
| kids | |
|
266 |
kids := OrderedCollection new. |
|
267 |
self addAllChildrenTo: kids. |
|
268 |
^kids. |
|
269 |
||
270 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"! |
|
271 |
||
272 |
addChild: anObjectOfMyKind |
|
273 |
"add anObjectOfMyKind to my children" |
|
274 |
||
275 |
anObjectOfMyKind parent: self. |
|
276 |
anObjectOfMyKind level: level +1. |
|
277 |
children add: anObjectOfMyKind. |
|
278 |
||
279 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"! |
|
280 |
||
281 |
expand |
|
282 |
"Show my immediate children in hierachical printouts." |
|
283 |
||
284 |
hide := false. |
|
285 |
||
286 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"! |
|
287 |
||
288 |
collapse |
|
289 |
"Hide my children in hierachical printouts." |
|
290 |
||
291 |
hide := true |
|
292 |
||
293 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"! |
|
294 |
||
295 |
removeChild: anObjectOfMyKind |
|
296 |
"remove anObjectOfMyKind from my children" |
|
297 |
||
298 |
anObjectOfMyKind parent: nil. |
|
299 |
children rehash. |
|
300 |
children remove: anObjectOfMyKind. |
|
301 |
||
302 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding" |
|
303 |
! |
|
304 |
||
305 |
removeYourself |
|
306 |
"remove me and all my children" |
|
307 |
||
308 |
parent isNil ifTrue: [^nil]. |
|
309 |
parent removeChild: self. |
|
310 |
||
311 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"! |
|
312 |
||
313 |
withAllChildren |
|
314 |
"Answer me, my immediate children and all my grandchildren |
|
315 |
-- in hierachical order and alphabeticaly sorted by name within one level." |
|
316 |
||
317 |
| kids | |
|
318 |
kids := OrderedCollection with: self . |
|
319 |
self addAllChildrenTo: kids. |
|
320 |
^kids. |
|
321 |
||
322 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"! |
|
323 |
||
324 |
parent |
|
325 |
"return parent" |
|
326 |
||
327 |
^ parent |
|
328 |
||
329 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"! |
|
330 |
||
331 |
children |
|
332 |
"Answer my immediate children." |
|
333 |
||
334 |
^ children |
|
335 |
||
336 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"! |
|
337 |
||
338 |
addChildren: aCollectionWithElementsOfMyKind |
|
339 |
"add aCollectionWithElementsOfMyKind to my children" |
|
340 |
||
341 |
aCollectionWithElementsOfMyKind do: [:child | |
|
342 |
child parent: self. |
|
343 |
child level: level +1. |
|
344 |
]. |
|
345 |
children addAll: aCollectionWithElementsOfMyKind. |
|
346 |
||
347 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"! |
|
348 |
||
349 |
allParents |
|
350 |
"return all my parents (next first - root last)" |
|
351 |
||
352 |
parent isNil ifTrue: [ ^OrderedCollection new: 0 ] |
|
353 |
ifFalse: [ ^parent, parent allParents ]. |
|
354 |
||
355 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"! |
|
356 |
||
357 |
expandAll |
|
358 |
"Show my children and all grand children in hierachical printouts." |
|
359 |
||
360 |
hide := false. |
|
361 |
children do: [ :kid | kid expandAll ]. |
|
362 |
||
363 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"! |
|
364 |
||
365 |
collapseAll |
|
366 |
"Hide my children and all my grandchildren in hierachical printouts." |
|
367 |
||
368 |
hide := true. |
|
369 |
children do: [ :kid | kid collapseAll ]. |
|
370 |
||
371 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"! |
|
372 |
||
373 |
removeAllChildren |
|
374 |
"Remove all children of me from the tree, i.e. let them |
|
375 |
forget myself as parent." |
|
376 |
||
377 |
| kids | |
|
378 |
kids := self allChildren. |
|
379 |
kids do: [:kid | kid parent: nil ]. |
|
380 |
children := Set new. |
|
381 |
||
382 |
"Modified: 10.10.94 / 16:13:34 / W.Olberding"! ! |
|
383 |
||
384 |
!HierarchyNode methodsFor:'private'! |
|
385 |
||
386 |
addAllShownChildrenTo: aCollection |
|
387 |
"Add all my children in hierachical and alphabetical order |
|
388 |
if they are not hidden." |
|
389 |
||
390 |
|myChildren| |
|
391 |
hide ifTrue: [^self]. |
|
392 |
myChildren := children asSortedCollection: |
|
393 |
[:x :y | x name < y name ]. |
|
394 |
myChildren do: [:aChild | |
|
395 |
aCollection addLast: aChild. |
|
396 |
aChild addAllShownChildrenTo: aCollection. |
|
397 |
]. |
|
398 |
||
399 |
"Modified: 10.10.94 / 16:13:35 / W.Olberding"! |
|
400 |
||
401 |
addAllChildrenTo: aCollection |
|
402 |
"Add all my children in hierachical and alphabetical order." |
|
403 |
||
404 |
|myChildren| |
|
405 |
myChildren := children asSortedCollection: |
|
406 |
[:x :y | x name < y name ]. |
|
407 |
myChildren do: [:aChild | |
|
408 |
aCollection addLast: aChild. |
|
409 |
aChild addAllChildrenTo: aCollection. |
|
410 |
]. |
|
411 |
||
412 |
"Modified: 10.10.94 / 16:13:35 / W.Olberding"! ! |
|
413 |
||
414 |
!HierarchyNode methodsFor:'initialize-release'! |
|
415 |
||
416 |
initialize |
|
417 |
"init some defaults" |
|
418 |
||
419 |
" name |
|
420 |
id |
|
421 |
parent --" |
|
422 |
children := Set new. |
|
423 |
" contents := Set new." |
|
424 |
disabled := false. |
|
425 |
hide := false. |
|
426 |
level := 0. "=root" |
|
427 |
||
428 |
"Modified: 10.10.94 / 16:13:35 / W.Olberding"! ! |
|
429 |
||
430 |
!HierarchyNode methodsFor:'constants'! |
|
431 |
||
432 |
delimiter |
|
433 |
"Answer the delimiter character" |
|
434 |
||
435 |
^$/ |
|
436 |
||
437 |
"Modified: 10.10.94 / 16:13:35 / W.Olberding"! |
|
438 |
||
439 |
delimiterString |
|
440 |
"Answer the delimiter character asString" |
|
441 |
||
442 |
^self delimiter asString |
|
443 |
||
444 |
"Modified: 10.10.94 / 16:13:35 / W.Olberding"! ! |
|
445 |
||
446 |