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