author | Claus Gittinger <cg@exept.de> |
Fri, 14 Dec 2001 11:57:44 +0100 | |
changeset 2071 | 7c58c73eff49 |
parent 2038 | 81b3b590c9d8 |
child 2102 | aa58c7d922fe |
permissions | -rw-r--r-- |
457 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
||
14 |
||
15 |
||
1818 | 16 |
"{ Package: 'stx:libwidg2' }" |
17 |
||
457 | 18 |
Object subclass:#TreeItem |
795 | 19 |
instanceVariableNames:'name tree parent children contents hide readChildren' |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
20 |
classVariableNames:'UnknownContents' |
795 | 21 |
poolDictionaries:'' |
22 |
category:'Interface-Support' |
|
457 | 23 |
! |
24 |
||
25 |
!TreeItem class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1997 by eXept Software AG / 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 |
||
42 |
! |
|
43 |
||
44 |
documentation |
|
45 |
" |
|
46 |
class to build up trees like structures to represent |
|
47 |
file-trees, class tress etc. |
|
48 |
||
49 |
Especially suited for use with SelectionInTree and |
|
50 |
SelectionInTreeView. |
|
51 |
||
52 |
[Author:] |
|
53 |
W. Olberding |
|
54 |
Claus Atzkern |
|
55 |
||
56 |
[See also:] |
|
57 |
SelectionInTree |
|
58 |
SelectionInTreeView |
|
59 |
||
60 |
" |
|
61 |
||
62 |
||
63 |
||
64 |
! ! |
|
65 |
||
66 |
!TreeItem class methodsFor:'instance creation'! |
|
67 |
||
768
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
68 |
contents:aContents |
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
69 |
|node| |
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
70 |
|
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
71 |
node := self new. |
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
72 |
node contents:aContents. |
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
73 |
^ node |
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
74 |
! |
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
75 |
|
506 | 76 |
name:aName |
77 |
^ self name:aName contents:nil |
|
78 |
! |
|
79 |
||
457 | 80 |
name:aName contents:aContents |
81 |
|node| |
|
82 |
||
83 |
node := self new. |
|
84 |
node name:aName. |
|
85 |
node contents:aContents. |
|
86 |
^ node |
|
87 |
! |
|
88 |
||
506 | 89 |
name:aName value:aContents |
90 |
^ self name:aName contents:aContents |
|
91 |
! |
|
92 |
||
457 | 93 |
new |
94 |
^ self basicNew initialize |
|
95 |
! ! |
|
96 |
||
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
97 |
!TreeItem class methodsFor:'class initialization'! |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
98 |
|
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
99 |
initialize |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
100 |
UnknownContents isNil ifTrue:[ |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
101 |
UnknownContents := Object new. |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
102 |
] |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
103 |
|
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
104 |
" |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
105 |
self initialize |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
106 |
" |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
107 |
! ! |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
108 |
|
786 | 109 |
!TreeItem class methodsFor:'default icons'! |
110 |
||
111 |
keysAndIcons |
|
112 |
"returns an IdentityDictionary containing a list of images and keys used |
|
113 |
by any file entry; could be redefined by subclass |
|
114 |
" |
|
115 |
^ nil |
|
116 |
||
117 |
! ! |
|
118 |
||
457 | 119 |
!TreeItem class methodsFor:'example - instance creation'! |
120 |
||
121 |
newAsTreeFromSmalltalkClass:aClass |
|
122 |
"create a tree of nodes with aClass and all its |
|
123 |
subclasses as contents. Set the initial level as given." |
|
124 |
||
125 |
|newInst clsName| |
|
126 |
||
127 |
aClass isNil ifTrue:[ |
|
128 |
"/ nil subclasses requested |
|
129 |
clsName := 'nil' |
|
130 |
] ifFalse:[ |
|
131 |
"/ regular tree requested |
|
132 |
clsName := aClass name |
|
133 |
]. |
|
134 |
||
135 |
newInst := super new initialize. |
|
136 |
newInst name:clsName. |
|
137 |
||
138 |
aClass isNil ifTrue:[ |
|
139 |
((Smalltalk allClasses select:[:cls | cls superclass isNil]) |
|
140 |
asSortedCollection:[:a :b | a name < b name]) |
|
141 |
do:[:aSubClass | |
|
142 |
newInst add:(self newAsTreeFromSmalltalkClass:aSubClass). |
|
143 |
] |
|
144 |
] ifFalse:[ |
|
145 |
(aClass subclasses asSortedCollection:[:a :b | a name < b name]) |
|
146 |
do:[:aSubClass | |
|
147 |
newInst add:(self newAsTreeFromSmalltalkClass:aSubClass). |
|
148 |
] |
|
149 |
]. |
|
150 |
^newInst |
|
151 |
||
506 | 152 |
" |
153 |
|top model sel root| |
|
154 |
||
155 |
root := TreeItem newAsTreeFromSmalltalkClass:ByteArray. |
|
156 |
root expand. |
|
157 |
model := SelectionInTree new root:root. |
|
158 |
top := StandardSystemView new. |
|
159 |
top extent:300@300. |
|
160 |
||
161 |
sel := SelectionInTreeView new. |
|
162 |
sel model: model. |
|
163 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
|
164 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
165 |
top open. |
|
166 |
" |
|
457 | 167 |
! ! |
168 |
||
169 |
!TreeItem methodsFor:'accessing'! |
|
170 |
||
171 |
contents |
|
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
172 |
"get the contents; |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
173 |
usually, the contents is computed lazily i.e. #retrieveContents |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
174 |
is invoked when the contents has not yet been set. |
457 | 175 |
" |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
176 |
contents == UnknownContents ifTrue:[ |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
177 |
self retrieveContents |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
178 |
]. |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
179 |
^contents |
457 | 180 |
! |
181 |
||
182 |
contents:something |
|
183 |
"set contents |
|
184 |
" |
|
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
185 |
contents := something |
457 | 186 |
! |
187 |
||
1172 | 188 |
editor |
189 |
"returns an editor on the editable value or nil |
|
506 | 190 |
" |
191 |
^ nil |
|
192 |
! |
|
193 |
||
457 | 194 |
hide |
195 |
^ hide |
|
196 |
! |
|
197 |
||
198 |
hide:aBoolean |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
199 |
"set hide flag |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
200 |
" |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
201 |
hide:= aBoolean |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
202 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
203 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
204 |
icon |
786 | 205 |
"get the icon |
766 | 206 |
" |
772 | 207 |
^self retrieveAndEvaluate: #iconAction |
208 |
||
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
209 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
210 |
|
457 | 211 |
level |
212 |
"get level |
|
213 |
" |
|
786 | 214 |
|p |
215 |
lv "{ Class:SmallInteger }" |
|
216 |
| |
|
217 |
lv := 1. |
|
218 |
p := self. |
|
219 |
||
220 |
[ (p := p parent) notNil ] whileTrue:[ lv := lv + 1 ]. |
|
221 |
^ lv |
|
457 | 222 |
! |
223 |
||
1172 | 224 |
middleButtonMenu |
225 |
"returns the middleButtonMenu of the item or nil |
|
226 |
" |
|
227 |
^ nil |
|
228 |
! |
|
229 |
||
457 | 230 |
name |
231 |
"get name |
|
772 | 232 |
" |
786 | 233 |
name isNil ifTrue:[ |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
234 |
self retrieveLabel |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
235 |
]. |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
236 |
^name |
457 | 237 |
! |
238 |
||
239 |
name:aString |
|
240 |
"set name |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
241 |
" |
457 | 242 |
name := aString. |
243 |
! |
|
244 |
||
245 |
parent |
|
246 |
"get parent |
|
247 |
" |
|
248 |
^ parent |
|
249 |
! |
|
250 |
||
251 |
parent:something |
|
252 |
"set parent |
|
253 |
" |
|
254 |
parent := something. |
|
506 | 255 |
! |
256 |
||
257 |
value |
|
258 |
"get contents |
|
259 |
" |
|
260 |
^ self contents |
|
261 |
! |
|
262 |
||
263 |
value:something |
|
264 |
"set contents |
|
265 |
" |
|
266 |
self contents:something |
|
457 | 267 |
! ! |
268 |
||
1818 | 269 |
!TreeItem methodsFor:'accessing-children'! |
1172 | 270 |
|
271 |
basicLastChild |
|
272 |
"returns the last child without checking for valid sequence |
|
273 |
" |
|
274 |
^ children last |
|
275 |
! |
|
276 |
||
277 |
children |
|
278 |
"get list of children |
|
279 |
" |
|
280 |
(readChildren and:[children isEmpty]) ifTrue:[ |
|
281 |
self retrieveChildren |
|
282 |
]. |
|
283 |
^children |
|
284 |
! |
|
285 |
||
286 |
children:aCollection |
|
287 |
"set children |
|
1208 | 288 |
" |
289 |
aCollection isNil ifTrue:[ |
|
290 |
children removeAll |
|
291 |
] ifFalse:[ |
|
292 |
aCollection notNil ifTrue:[ |
|
293 |
aCollection do:[:child| child parent:self ]. |
|
294 |
readChildren := false |
|
295 |
]. |
|
296 |
children := aCollection |
|
297 |
] |
|
1172 | 298 |
! |
299 |
||
300 |
firstChild |
|
301 |
"returns first child in sequence |
|
302 |
" |
|
303 |
self children notEmpty ifTrue:[ |
|
304 |
^ children at:1 |
|
305 |
]. |
|
306 |
^ nil |
|
307 |
||
308 |
! |
|
309 |
||
310 |
lastChild |
|
311 |
"returns last child in sequence |
|
312 |
" |
|
313 |
self children notEmpty ifTrue:[ |
|
314 |
^ children last |
|
315 |
]. |
|
316 |
^ nil |
|
317 |
||
318 |
! |
|
319 |
||
320 |
readChildren:aBoolean |
|
321 |
"set read children flag |
|
322 |
" |
|
323 |
readChildren:= aBoolean |
|
324 |
! ! |
|
325 |
||
1818 | 326 |
!TreeItem methodsFor:'accessing-dimensions'! |
1172 | 327 |
|
328 |
childrenWidthOn:aDevice |
|
329 |
"returns the maximum name length of my children |
|
330 |
" |
|
331 |
|max name| |
|
332 |
||
333 |
max := 0. |
|
334 |
||
335 |
children do:[:aChild| |
|
336 |
(name := aChild name) notNil ifTrue:[ |
|
337 |
max := max max:(name widthOn:aDevice) |
|
338 |
] |
|
339 |
]. |
|
340 |
^ max |
|
341 |
! ! |
|
342 |
||
1818 | 343 |
!TreeItem methodsFor:'accessing-hierarchy'! |
457 | 344 |
|
345 |
collapse |
|
469 | 346 |
"hide all my children |
347 |
" |
|
772 | 348 |
hide := true |
457 | 349 |
! |
350 |
||
351 |
collapseAll |
|
469 | 352 |
"hide all my children and sub children |
457 | 353 |
" |
841 | 354 |
hide := true. |
457 | 355 |
|
841 | 356 |
children notEmpty ifTrue:[ |
357 |
children do:[:aChild| aChild collapseAll] |
|
834 | 358 |
] |
359 |
! |
|
360 |
||
469 | 361 |
expand |
362 |
"show all my children |
|
363 |
" |
|
772 | 364 |
hide := false |
457 | 365 |
! |
366 |
||
367 |
expandAll |
|
368 |
"show all my children and sub children |
|
369 |
" |
|
841 | 370 |
hide := false. |
834 | 371 |
|
841 | 372 |
self children notEmpty ifTrue:[ |
373 |
children do:[:aChild| aChild expandAll ] |
|
374 |
] |
|
457 | 375 |
! ! |
376 |
||
1818 | 377 |
!TreeItem methodsFor:'accessing-model'! |
786 | 378 |
|
379 |
model |
|
380 |
"get my model (an instance of selection in tree) or nil |
|
381 |
" |
|
382 |
^ parent notNil ifTrue:[parent model] ifFalse:[tree] |
|
383 |
! |
|
384 |
||
385 |
model:aSelectionInTree |
|
386 |
"set my model (an instance of selection in tree) or nil |
|
387 |
" |
|
388 |
tree:= aSelectionInTree |
|
389 |
! |
|
390 |
||
391 |
tree |
|
392 |
"get my model (an instance of selection in tree) or nil |
|
393 |
" |
|
394 |
^ self model |
|
395 |
! |
|
396 |
||
397 |
tree:aSelectionInTree |
|
398 |
"set my model (an instance of selection in tree) or nil |
|
399 |
" |
|
400 |
self model:aSelectionInTree |
|
401 |
! ! |
|
402 |
||
457 | 403 |
!TreeItem methodsFor:'adding & removing'! |
404 |
||
405 |
add:something |
|
406 |
"add a child or collection of children add end |
|
407 |
" |
|
469 | 408 |
self add:something beforeIndex:(self children size + 1) |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
409 |
|
457 | 410 |
! |
411 |
||
412 |
add:something after:aChild |
|
413 |
"add a child or collection of children add end |
|
414 |
" |
|
415 |
self add:something afterIndex:(self indexOfChild:aChild) |
|
416 |
! |
|
417 |
||
418 |
add:something afterIndex:anIndex |
|
419 |
"add a child or collection after an index |
|
420 |
" |
|
421 |
self add:something beforeIndex:(anIndex + 1) |
|
422 |
! |
|
423 |
||
424 |
add:something before:aChild |
|
425 |
"add a child or collection of children add end |
|
426 |
" |
|
427 |
self add:something beforeIndex:(self indexOfChild:aChild) |
|
428 |
! |
|
429 |
||
430 |
add:something beforeIndex:anIndex |
|
431 |
"add a child or collection before an index |
|
432 |
" |
|
469 | 433 |
|idx children| |
434 |
||
435 |
children := self children. |
|
457 | 436 |
|
437 |
(idx := anIndex) > children size ifTrue:[ |
|
438 |
idx := children size + 1 |
|
439 |
] ifFalse:[ |
|
440 |
idx == 0 ifTrue:[idx := 1] |
|
441 |
]. |
|
442 |
||
443 |
self each:something do:[:el| |
|
444 |
children add:el beforeIndex:idx. |
|
445 |
el parent:self. |
|
446 |
el allWithParentAndChildrenDo:[:aParent :aChild| aChild parent:aParent ]. |
|
447 |
idx := idx + 1. |
|
448 |
] |
|
449 |
! |
|
450 |
||
909 | 451 |
addFirst: something |
452 |
"add a child at the beginning |
|
453 |
" |
|
454 |
self add:something beforeIndex:1 |
|
455 |
! |
|
456 |
||
457 | 457 |
remove:something |
458 |
"remove a child or collection of children |
|
459 |
" |
|
858 | 460 |
self each:something do:[:aChild| self removeChild:aChild ]. |
457 | 461 |
^ something |
462 |
! |
|
463 |
||
464 |
removeAll |
|
465 |
"remove all children |
|
466 |
" |
|
467 |
self childrenDo:[:aChild| aChild parent:nil ]. |
|
469 | 468 |
self children removeAll. |
858 | 469 |
! |
470 |
||
471 |
removeChild:aChild |
|
472 |
"remove a aChild |
|
473 |
" |
|
474 |
|item| |
|
475 |
||
476 |
(item := self children remove:aChild ifAbsent:nil) notNil ifTrue:[ |
|
477 |
item parent:nil |
|
478 |
]. |
|
479 |
^ item |
|
480 |
! |
|
481 |
||
482 |
removeIndex:anIndex |
|
483 |
"remove child at index |
|
484 |
" |
|
485 |
^ self removeChild:(self childAt:anIndex) |
|
457 | 486 |
! ! |
487 |
||
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
488 |
!TreeItem methodsFor:'change & update'! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
489 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
490 |
changed |
786 | 491 |
"node changed; raise notification to model |
492 |
" |
|
493 |
self changed:#value |
|
784 | 494 |
! |
495 |
||
786 | 496 |
changed:what |
497 |
"node changed; raise notification to model |
|
498 |
" |
|
499 |
|model| |
|
784 | 500 |
|
795 | 501 |
what == #value |
982
d94684e7fe9f
sending #changed to a tree item should not invoke retrieving children
tz
parents:
909
diff
changeset
|
502 |
ifTrue: [self retrieveLabel] |
795 | 503 |
ifFalse: [what == #children ifTrue: [self retrieveChildren]]. |
786 | 504 |
|
505 |
(model := self model) notNil ifTrue:[ |
|
795 | 506 |
model update:what with:nil from:self |
786 | 507 |
] |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
508 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
509 |
|
2038 | 510 |
changedSelected |
511 |
"called if the node is selected |
|
512 |
" |
|
513 |
! |
|
514 |
||
786 | 515 |
update:something with:aParameter from:anItem |
516 |
"raise change notification to my model |
|
517 |
" |
|
518 |
|m| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
519 |
|
786 | 520 |
(m := self model) notNil ifTrue:[ |
521 |
m update:something with:aParameter from:anItem |
|
522 |
] |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
523 |
! ! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
524 |
|
506 | 525 |
!TreeItem methodsFor:'converting'! |
526 |
||
527 |
fromLiteralArrayEncoding:aLiteralEncodedArray |
|
786 | 528 |
"read my contents from a aLiteralEncodedArray. |
529 |
" |
|
506 | 530 |
|narg| |
531 |
||
532 |
( (aLiteralEncodedArray size > 0) |
|
533 |
and:[(name := aLiteralEncodedArray at:1) isString]) ifFalse:[ |
|
534 |
^ nil |
|
535 |
]. |
|
536 |
narg := aLiteralEncodedArray at:2 ifAbsent:nil. |
|
537 |
||
538 |
name isSymbol ifTrue:[ |
|
539 |
(narg isArray and:[aLiteralEncodedArray size == 2]) ifTrue:[ |
|
540 |
^ self fromLiteralArrayEncoding:narg |
|
541 |
]. |
|
542 |
^ nil |
|
543 |
]. |
|
544 |
||
545 |
narg isArray ifFalse:[ |
|
546 |
contents := narg. |
|
547 |
narg := aLiteralEncodedArray at:3 ifAbsent:nil. |
|
548 |
]. |
|
549 |
||
550 |
narg isArray ifTrue:[ |
|
551 |
children := OrderedCollection new. |
|
552 |
||
553 |
narg do:[:aSubArray||aChild| |
|
554 |
children add:(aChild := TreeItem new). |
|
555 |
aChild fromLiteralArrayEncoding:aSubArray. |
|
556 |
aChild parent:self. |
|
557 |
] |
|
558 |
] |
|
559 |
||
560 |
||
561 |
||
562 |
! |
|
563 |
||
564 |
literalArrayEncoding |
|
786 | 565 |
"return myself encoded as a literal array |
566 |
" |
|
567 |
|array childs size noChld| |
|
506 | 568 |
|
569 |
contents isString ifTrue:[size := 2] |
|
570 |
ifFalse:[size := 1]. |
|
571 |
||
786 | 572 |
noChld := self numberOfChildren. |
573 |
||
574 |
noChld == 0 ifTrue:[ |
|
506 | 575 |
array := Array new:size |
576 |
] ifFalse:[ |
|
786 | 577 |
array := Array new:size + 1. |
578 |
childs := Array new:noChld. |
|
506 | 579 |
array at:(size + 1) put:childs. |
580 |
||
581 |
self children keysAndValuesDo:[:i :aChild| |
|
582 |
childs at:i put:(aChild literalArrayEncoding) |
|
583 |
] |
|
584 |
]. |
|
585 |
array at:1 put:(name ? ''). |
|
586 |
||
587 |
contents isString ifTrue:[ |
|
588 |
array at:2 put:contents |
|
589 |
]. |
|
590 |
parent isNil ifTrue:[ |
|
591 |
array := Array with:#TreeItem with:array. |
|
592 |
]. |
|
593 |
^ array |
|
594 |
||
595 |
||
596 |
! ! |
|
597 |
||
457 | 598 |
!TreeItem methodsFor:'copy'! |
599 |
||
600 |
copy |
|
601 |
|node| |
|
602 |
||
603 |
node := self species new. |
|
604 |
||
605 |
node name:(name copy). |
|
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
606 |
contents ~~ UnknownContents ifTrue:[ |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
607 |
node contents:(contents copy). |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
608 |
] ifFalse:[ |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
609 |
node contents:UnknownContents |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
610 |
]. |
469 | 611 |
node children:(self children collect:[:c| c copy]). |
786 | 612 |
node readChildren:readChildren. |
457 | 613 |
^ node |
614 |
! ! |
|
615 |
||
616 |
!TreeItem methodsFor:'enumerating'! |
|
617 |
||
618 |
allChildrenDo:aOneArgBlock |
|
619 |
"evaluate a block on each children and subchildren |
|
620 |
" |
|
469 | 621 |
self children do:[:aChild| |
457 | 622 |
aOneArgBlock value:aChild. |
623 |
aChild allChildrenDo:aOneArgBlock |
|
624 |
] |
|
625 |
! |
|
626 |
||
627 |
allWithParentAndChildrenDo:aTwoArgBlock |
|
628 |
self childrenDo:[:aChild| |
|
629 |
aTwoArgBlock value:self value:aChild. |
|
630 |
aChild allWithParentAndChildrenDo:aTwoArgBlock |
|
631 |
] |
|
632 |
! |
|
633 |
||
634 |
childrenDo:aOneArgBlock |
|
635 |
"evaluate a block on each children( excluding sub-children ) |
|
636 |
" |
|
837 | 637 |
self children do:aOneArgBlock |
457 | 638 |
! |
639 |
||
1241 | 640 |
detectParent:aBlock |
641 |
"evaluate aBlock for my parent-chain; return the parent for which it returns true" |
|
642 |
||
643 |
|p| |
|
644 |
||
645 |
p := parent. |
|
646 |
[p notNil] whileTrue:[ |
|
647 |
(aBlock value:p) ifTrue:[^ p]. |
|
648 |
p := p parent |
|
649 |
]. |
|
650 |
^ nil |
|
651 |
||
652 |
! |
|
653 |
||
837 | 654 |
each:something do:aOneArgBlock |
457 | 655 |
"evaluate a block for something or in case of a collection for each |
656 |
element in the collection |
|
657 |
" |
|
658 |
something notNil ifTrue:[ |
|
837 | 659 |
something isCollection ifTrue:[something do:aOneArgBlock] |
660 |
ifFalse:[aOneArgBlock value:something] |
|
457 | 661 |
] |
662 |
||
663 |
! ! |
|
664 |
||
665 |
!TreeItem methodsFor:'initialize-release'! |
|
666 |
||
667 |
initialize |
|
668 |
"setup defaults |
|
669 |
" |
|
506 | 670 |
super initialize. |
671 |
||
457 | 672 |
children := OrderedCollection new. |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
673 |
readChildren := hide := true. |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
674 |
contents := UnknownContents. |
457 | 675 |
! ! |
676 |
||
1825 | 677 |
!TreeItem methodsFor:'printing & storing'! |
1172 | 678 |
|
679 |
asString |
|
680 |
"sometimes used by the SelectionInListView to get the name |
|
681 |
" |
|
682 |
^ name notNil ifTrue:[name] ifFalse:[self name] |
|
683 |
||
684 |
! |
|
685 |
||
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
686 |
displayString |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
687 |
^ self class name , '(' , self printString , ')' |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
688 |
! |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
689 |
|
1172 | 690 |
printString |
691 |
"sometimes used by the SelectionInListView to get the name |
|
692 |
" |
|
693 |
^ name notNil ifTrue:[name] ifFalse:[self name] |
|
694 |
||
695 |
! |
|
696 |
||
697 |
printableEditValue |
|
698 |
"returns the printable edit value or nil |
|
699 |
" |
|
700 |
^ nil |
|
701 |
! ! |
|
702 |
||
457 | 703 |
!TreeItem methodsFor:'queries'! |
704 |
||
1172 | 705 |
canEdit |
706 |
"returns true if field is editable |
|
707 |
" |
|
708 |
^ false |
|
709 |
! |
|
710 |
||
457 | 711 |
hasChildren |
786 | 712 |
"returns true if any child exists |
457 | 713 |
" |
786 | 714 |
^ self children notEmpty |
457 | 715 |
! |
716 |
||
834 | 717 |
hasChildrenWithSubChildren |
718 |
"returns true if any child exists and has children too |
|
719 |
" |
|
720 |
self children do:[:aChild| |
|
721 |
aChild hasChildren ifTrue:[^ true]. |
|
722 |
]. |
|
723 |
^ false |
|
724 |
||
725 |
! |
|
726 |
||
727 |
hasExpandedChildren |
|
728 |
"returns true if any of my children is expanded |
|
729 |
" |
|
730 |
children notEmpty ifTrue:[ |
|
731 |
children do:[:aChild| aChild hidden ifFalse:[^ true] ] |
|
732 |
]. |
|
733 |
^ false |
|
734 |
! |
|
735 |
||
457 | 736 |
hidden |
786 | 737 |
"returns true if node is not visible |
738 |
" |
|
457 | 739 |
^ hide |
740 |
! |
|
741 |
||
742 |
isCollapsable |
|
743 |
"is collabsable; children existing and shown |
|
744 |
" |
|
469 | 745 |
^ (self hasChildren and:[hide == false]) |
457 | 746 |
! |
747 |
||
569 | 748 |
isContainedByParent:aParent |
749 |
"returns true if contained in subtree of a parent |
|
750 |
" |
|
751 |
|p| |
|
752 |
||
753 |
p := parent. |
|
754 |
||
755 |
[p notNil] whileTrue:[ |
|
756 |
p == aParent ifTrue:[^ true ]. |
|
757 |
p := p parent |
|
758 |
]. |
|
759 |
^ false |
|
760 |
! |
|
761 |
||
457 | 762 |
isExpandable |
763 |
"is expandable; children existing and hidden |
|
764 |
" |
|
469 | 765 |
^ (self hasChildren and:[hide == true]) |
457 | 766 |
|
767 |
! |
|
768 |
||
1205 | 769 |
isExpanded |
770 |
"return true if I am expanded" |
|
771 |
^ hide not |
|
772 |
||
773 |
! |
|
774 |
||
472 | 775 |
numberOfChildren |
786 | 776 |
"returns number of children |
777 |
" |
|
472 | 778 |
^ self children size |
779 |
! |
|
780 |
||
841 | 781 |
showIndicator |
782 |
"returns true if children exists |
|
783 |
" |
|
784 |
^ self hasChildren |
|
785 |
! |
|
786 |
||
787 |
shown |
|
788 |
"returns true if node is visible |
|
789 |
" |
|
790 |
^ hide not |
|
791 |
! ! |
|
792 |
||
793 |
!TreeItem methodsFor:'recomputation'! |
|
794 |
||
858 | 795 |
addVisibleChildrenTo:aList |
796 |
"add all visible children and sub-children to the list |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
797 |
" |
838 | 798 |
|item |
799 |
size "{ Class: SmallInteger }" |
|
800 |
idx "{ Class: SmallInteger }" |
|
801 |
| |
|
802 |
||
457 | 803 |
hide ifFalse:[ |
841 | 804 |
readChildren ifTrue:[ |
805 |
self children |
|
806 |
]. |
|
849 | 807 |
(size := children size) ~~ 0 ifTrue:[ |
838 | 808 |
idx := 1. |
809 |
size timesRepeat:[ |
|
810 |
aList add:(item := children at:idx). |
|
858 | 811 |
item addVisibleChildrenTo:aList. |
838 | 812 |
idx := idx + 1. |
813 |
] |
|
457 | 814 |
] |
815 |
] |
|
841 | 816 |
|
457 | 817 |
|
569 | 818 |
|
858 | 819 |
! |
820 |
||
821 |
numberOfAllVisibleChildren |
|
822 |
"returns number of all visible children including all the children of children |
|
823 |
" |
|
824 |
|total "{ Class: SmallInteger }"| |
|
825 |
||
826 |
hide ifTrue:[ |
|
827 |
^ 0 |
|
828 |
]. |
|
829 |
readChildren ifTrue:[ self children ]. |
|
830 |
||
831 |
(total := children size) ~~ 0 ifTrue:[ |
|
832 |
children do:[:aChild| total := total + aChild numberOfAllVisibleChildren ]. |
|
833 |
]. |
|
834 |
^ total |
|
835 |
||
836 |
||
837 |
||
457 | 838 |
! ! |
839 |
||
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
840 |
!TreeItem methodsFor:'retrieving'! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
841 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
842 |
childrenAction |
786 | 843 |
"get children action block |
844 |
" |
|
845 |
|m| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
846 |
|
786 | 847 |
^ (m := self model) notNil ifTrue:[m childrenAction] ifFalse:[nil] |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
848 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
849 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
850 |
contentsAction |
786 | 851 |
"get contents action block |
852 |
" |
|
853 |
|m| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
854 |
|
786 | 855 |
^ (m := self model) notNil ifTrue:[m contentsAction] ifFalse:[nil] |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
856 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
857 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
858 |
iconAction |
786 | 859 |
"get icon action block |
860 |
" |
|
861 |
|m| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
862 |
|
786 | 863 |
^ (m := self model) notNil ifTrue:[m iconAction] ifFalse:[nil] |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
864 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
865 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
866 |
labelAction |
786 | 867 |
"get label action block |
868 |
" |
|
869 |
|m| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
870 |
|
786 | 871 |
^ (m := self model) notNil ifTrue:[m labelAction] ifFalse:[nil] |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
872 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
873 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
874 |
retrieveAll |
786 | 875 |
"retrieve all values from model |
876 |
" |
|
784 | 877 |
self "retrieveContents;" retrieveLabel; retrieveChildren |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
878 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
879 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
880 |
retrieveAndEvaluate: aBlockSymbol |
1279 | 881 |
"retrieve a specific value from model; if no model exists, nil is returned |
786 | 882 |
" |
2071
7c58c73eff49
use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents:
2038
diff
changeset
|
883 |
|arg model| |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
884 |
|
786 | 885 |
(model := self model) isNil ifTrue:[ |
886 |
^ nil |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
887 |
]. |
786 | 888 |
arg := model perform:aBlockSymbol. |
889 |
||
890 |
arg isBlock ifFalse:[ |
|
891 |
^ arg value |
|
892 |
]. |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
893 |
|
2071
7c58c73eff49
use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents:
2038
diff
changeset
|
894 |
^ arg valueWithOptionalArgument:self |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
895 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
896 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
897 |
retrieveChildren |
786 | 898 |
"retrieve children from model |
899 |
" |
|
900 |
|retChildren cls| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
901 |
|
786 | 902 |
retChildren := self retrieveAndEvaluate:#childrenAction. |
903 |
||
904 |
retChildren notNil ifTrue:[ |
|
905 |
retChildren isCollection ifFalse: [retChildren := OrderedCollection with:retChildren]. |
|
906 |
cls := self class. |
|
907 |
||
908 |
self children: (retChildren collect: |
|
768
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
909 |
[:obj| |
786 | 910 |
(obj isKindOf:cls) ifTrue:[obj] |
911 |
ifFalse:[cls new contents:obj] |
|
768
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
912 |
]). |
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
913 |
readChildren := false. |
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
914 |
]. |
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
915 |
|
786 | 916 |
^ children |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
917 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
918 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
919 |
retrieveContents |
786 | 920 |
"retrieve contents value from model; |
921 |
" |
|
922 |
|cont| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
923 |
|
786 | 924 |
(cont := self retrieveAndEvaluate: #contentsAction) isNil ifTrue:[ |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
925 |
contents == UnknownContents ifTrue:[ |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
926 |
cont := '' |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
927 |
] |
786 | 928 |
]. |
929 |
^ contents := cont |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
930 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
931 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
932 |
retrieveLabel |
786 | 933 |
"retrieve label from model |
934 |
" |
|
935 |
|n| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
936 |
|
786 | 937 |
(n := self retrieveAndEvaluate:#labelAction) isNil ifTrue:[ |
938 |
n := name ? '' |
|
939 |
]. |
|
940 |
^ name := n |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
941 |
! ! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
942 |
|
479 | 943 |
!TreeItem methodsFor:'searching'! |
944 |
||
1172 | 945 |
childAt:anIndex |
1551 | 946 |
"get child at an index or nil" |
947 |
||
948 |
^ self children at:anIndex ifAbsent:nil |
|
1172 | 949 |
! |
950 |
||
479 | 951 |
detectChild:aOneArgBlock |
1551 | 952 |
"evaluate the block on each child; |
953 |
returns the child's node or nil. |
|
954 |
This searches my children only - not walking down sublevels. |
|
479 | 955 |
" |
1551 | 956 |
|
479 | 957 |
^ self children detect:aOneArgBlock ifNone:nil |
958 |
||
959 |
! |
|
960 |
||
849 | 961 |
detectChild:aTwoArgBlock arguments:args |
962 |
"detect a child the evaluation of the block returns true. The |
|
963 |
first argument to the block is the item, the second argument |
|
1551 | 964 |
the value derived from the argument list at node-level ... |
965 |
I.e. for each sublevel, a different block arg can be specified. |
|
966 |
The number of arguments also defines the search level. |
|
1552 | 967 |
i.e. if you pass (1 to:10) as args, the block will get the sub-level |
968 |
as second argument and stop the search after 10 levels. |
|
849 | 969 |
" |
1551 | 970 |
|
849 | 971 |
^ self detectChild:aTwoArgBlock arguments:args index:1 |
972 |
! |
|
973 |
||
1551 | 974 |
detectFirstChild:anOneArgBlock |
975 |
"detect the first child which evaluation of anOneArgBlock returns true. |
|
976 |
Recursively walks down the node-tree. |
|
977 |
" |
|
978 |
|node children| |
|
979 |
||
980 |
(anOneArgBlock value:self) ifTrue:[ |
|
981 |
^ self. |
|
982 |
]. |
|
983 |
(children := self children) notEmpty ifTrue:[ |
|
984 |
children do:[:aChild | |
|
985 |
(node := aChild detectFirstChild:anOneArgBlock) notNil ifTrue:[ |
|
986 |
^ node |
|
987 |
] |
|
988 |
] |
|
989 |
]. |
|
990 |
^ nil |
|
991 |
! |
|
992 |
||
993 |
indexOfChild:aChild |
|
994 |
"get index of a child or 0 |
|
995 |
" |
|
996 |
^ aChild notNil ifTrue:[self children identityIndexOf:aChild] |
|
997 |
ifFalse:[0] |
|
998 |
! ! |
|
999 |
||
1000 |
!TreeItem methodsFor:'searching - private'! |
|
1001 |
||
849 | 1002 |
detectChild:aTwoArgBlock arguments:args index:idxArgs |
1552 | 1003 |
"helper for limited search. |
1004 |
detect a child the evaluation of the block returns true. The |
|
849 | 1005 |
first argument to the block is the item, the second argument |
1551 | 1006 |
the value derived from the argument list at an index. |
1007 |
This one recursively walks down the tree searching for a node. |
|
849 | 1008 |
" |
1009 |
|num node| |
|
1010 |
||
1011 |
(num := args size) >= idxArgs ifTrue:[ |
|
1012 |
(aTwoArgBlock value:self value:(args at:idxArgs)) ifFalse:[ |
|
1013 |
^ nil |
|
1014 |
]. |
|
1015 |
||
1016 |
idxArgs == num ifTrue:[ |
|
1017 |
^ self |
|
1018 |
]. |
|
1019 |
||
1020 |
self children notEmpty ifTrue:[ |
|
1021 |
num := idxArgs + 1. |
|
1022 |
||
1023 |
children do:[:aChild| |
|
1024 |
node := aChild detectChild:aTwoArgBlock arguments:args index:num. |
|
1025 |
||
1026 |
node notNil ifTrue:[ |
|
1027 |
^ node |
|
1028 |
] |
|
1029 |
] |
|
1030 |
] |
|
1031 |
]. |
|
1032 |
^ nil |
|
479 | 1033 |
! ! |
1034 |
||
457 | 1035 |
!TreeItem class methodsFor:'documentation'! |
1036 |
||
1037 |
version |
|
2071
7c58c73eff49
use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents:
2038
diff
changeset
|
1038 |
^ '$Header: /cvs/stx/stx/libwidg2/TreeItem.st,v 1.39 2001-12-14 10:57:44 cg Exp $' |
457 | 1039 |
! ! |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
1040 |
TreeItem initialize! |