author | Claus Gittinger <cg@exept.de> |
Tue, 02 Nov 2010 22:00:38 +0100 | |
changeset 3961 | 6cd0b3929aa2 |
parent 3907 | 860a141af427 |
child 4140 | 267c46c27c2a |
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 |
||
3907
860a141af427
changed: #newAsTreeFromSmalltalkClass:
Claus Gittinger <cg@exept.de>
parents:
3699
diff
changeset
|
130 |
newInst := self new. |
457 | 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 |
name := aString. |
|
236 |
! |
|
237 |
||
238 |
parent |
|
239 |
"get parent |
|
240 |
" |
|
241 |
^ parent |
|
242 |
! |
|
243 |
||
244 |
parent:something |
|
245 |
"set parent |
|
246 |
" |
|
247 |
parent := something. |
|
506 | 248 |
! |
249 |
||
250 |
value |
|
251 |
"get contents |
|
252 |
" |
|
253 |
^ self contents |
|
254 |
! |
|
255 |
||
256 |
value:something |
|
257 |
"set contents |
|
258 |
" |
|
259 |
self contents:something |
|
457 | 260 |
! ! |
261 |
||
1818 | 262 |
!TreeItem methodsFor:'accessing-children'! |
1172 | 263 |
|
264 |
basicLastChild |
|
265 |
"returns the last child without checking for valid sequence |
|
266 |
" |
|
267 |
^ children last |
|
268 |
! |
|
269 |
||
270 |
children |
|
271 |
"get list of children |
|
272 |
" |
|
273 |
(readChildren and:[children isEmpty]) ifTrue:[ |
|
274 |
self retrieveChildren |
|
275 |
]. |
|
276 |
^children |
|
277 |
! |
|
278 |
||
279 |
children:aCollection |
|
280 |
"set children |
|
1208 | 281 |
" |
282 |
aCollection isNil ifTrue:[ |
|
283 |
children removeAll |
|
284 |
] ifFalse:[ |
|
285 |
aCollection notNil ifTrue:[ |
|
286 |
aCollection do:[:child| child parent:self ]. |
|
287 |
readChildren := false |
|
288 |
]. |
|
289 |
children := aCollection |
|
290 |
] |
|
1172 | 291 |
! |
292 |
||
293 |
firstChild |
|
294 |
"returns first child in sequence |
|
295 |
" |
|
296 |
self children notEmpty ifTrue:[ |
|
297 |
^ children at:1 |
|
298 |
]. |
|
299 |
^ nil |
|
300 |
||
301 |
! |
|
302 |
||
303 |
lastChild |
|
3699 | 304 |
"returns the last child in sequence" |
305 |
||
1172 | 306 |
self children notEmpty ifTrue:[ |
307 |
^ children last |
|
308 |
]. |
|
309 |
^ nil |
|
310 |
! |
|
311 |
||
312 |
readChildren:aBoolean |
|
313 |
"set read children flag |
|
314 |
" |
|
315 |
readChildren:= aBoolean |
|
316 |
! ! |
|
317 |
||
1818 | 318 |
!TreeItem methodsFor:'accessing-dimensions'! |
1172 | 319 |
|
320 |
childrenWidthOn:aDevice |
|
321 |
"returns the maximum name length of my children |
|
322 |
" |
|
323 |
|max name| |
|
324 |
||
325 |
max := 0. |
|
326 |
||
327 |
children do:[:aChild| |
|
328 |
(name := aChild name) notNil ifTrue:[ |
|
329 |
max := max max:(name widthOn:aDevice) |
|
330 |
] |
|
331 |
]. |
|
332 |
^ max |
|
333 |
! ! |
|
334 |
||
1818 | 335 |
!TreeItem methodsFor:'accessing-hierarchy'! |
457 | 336 |
|
337 |
collapse |
|
469 | 338 |
"hide all my children |
339 |
" |
|
772 | 340 |
hide := true |
457 | 341 |
! |
342 |
||
343 |
collapseAll |
|
469 | 344 |
"hide all my children and sub children |
457 | 345 |
" |
841 | 346 |
hide := true. |
457 | 347 |
|
841 | 348 |
children notEmpty ifTrue:[ |
349 |
children do:[:aChild| aChild collapseAll] |
|
834 | 350 |
] |
351 |
! |
|
352 |
||
469 | 353 |
expand |
354 |
"show all my children |
|
355 |
" |
|
772 | 356 |
hide := false |
457 | 357 |
! |
358 |
||
359 |
expandAll |
|
360 |
"show all my children and sub children |
|
361 |
" |
|
841 | 362 |
hide := false. |
834 | 363 |
|
841 | 364 |
self children notEmpty ifTrue:[ |
365 |
children do:[:aChild| aChild expandAll ] |
|
366 |
] |
|
457 | 367 |
! ! |
368 |
||
2404 | 369 |
!TreeItem methodsFor:'accessing-mvc'! |
786 | 370 |
|
371 |
model |
|
372 |
"get my model (an instance of selection in tree) or nil |
|
373 |
" |
|
374 |
^ parent notNil ifTrue:[parent model] ifFalse:[tree] |
|
375 |
! |
|
376 |
||
377 |
model:aSelectionInTree |
|
378 |
"set my model (an instance of selection in tree) or nil |
|
379 |
" |
|
380 |
tree:= aSelectionInTree |
|
381 |
! |
|
382 |
||
383 |
tree |
|
384 |
"get my model (an instance of selection in tree) or nil |
|
385 |
" |
|
386 |
^ self model |
|
387 |
! |
|
388 |
||
389 |
tree:aSelectionInTree |
|
390 |
"set my model (an instance of selection in tree) or nil |
|
391 |
" |
|
392 |
self model:aSelectionInTree |
|
393 |
! ! |
|
394 |
||
457 | 395 |
!TreeItem methodsFor:'adding & removing'! |
396 |
||
397 |
add:something |
|
398 |
"add a child or collection of children add end |
|
399 |
" |
|
469 | 400 |
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
|
401 |
|
457 | 402 |
! |
403 |
||
404 |
add:something after:aChild |
|
405 |
"add a child or collection of children add end |
|
406 |
" |
|
407 |
self add:something afterIndex:(self indexOfChild:aChild) |
|
408 |
! |
|
409 |
||
410 |
add:something afterIndex:anIndex |
|
411 |
"add a child or collection after an index |
|
412 |
" |
|
413 |
self add:something beforeIndex:(anIndex + 1) |
|
414 |
! |
|
415 |
||
416 |
add:something before:aChild |
|
417 |
"add a child or collection of children add end |
|
418 |
" |
|
419 |
self add:something beforeIndex:(self indexOfChild:aChild) |
|
420 |
! |
|
421 |
||
422 |
add:something beforeIndex:anIndex |
|
423 |
"add a child or collection before an index |
|
424 |
" |
|
469 | 425 |
|idx children| |
426 |
||
427 |
children := self children. |
|
457 | 428 |
|
429 |
(idx := anIndex) > children size ifTrue:[ |
|
430 |
idx := children size + 1 |
|
431 |
] ifFalse:[ |
|
432 |
idx == 0 ifTrue:[idx := 1] |
|
433 |
]. |
|
434 |
||
435 |
self each:something do:[:el| |
|
436 |
children add:el beforeIndex:idx. |
|
437 |
el parent:self. |
|
438 |
el allWithParentAndChildrenDo:[:aParent :aChild| aChild parent:aParent ]. |
|
439 |
idx := idx + 1. |
|
440 |
] |
|
441 |
! |
|
442 |
||
909 | 443 |
addFirst: something |
444 |
"add a child at the beginning |
|
445 |
" |
|
446 |
self add:something beforeIndex:1 |
|
447 |
! |
|
448 |
||
457 | 449 |
remove:something |
450 |
"remove a child or collection of children |
|
451 |
" |
|
858 | 452 |
self each:something do:[:aChild| self removeChild:aChild ]. |
457 | 453 |
^ something |
454 |
! |
|
455 |
||
456 |
removeAll |
|
457 |
"remove all children |
|
458 |
" |
|
459 |
self childrenDo:[:aChild| aChild parent:nil ]. |
|
469 | 460 |
self children removeAll. |
858 | 461 |
! |
462 |
||
463 |
removeChild:aChild |
|
464 |
"remove a aChild |
|
465 |
" |
|
466 |
|item| |
|
467 |
||
468 |
(item := self children remove:aChild ifAbsent:nil) notNil ifTrue:[ |
|
469 |
item parent:nil |
|
470 |
]. |
|
471 |
^ item |
|
472 |
! |
|
473 |
||
474 |
removeIndex:anIndex |
|
475 |
"remove child at index |
|
476 |
" |
|
477 |
^ self removeChild:(self childAt:anIndex) |
|
457 | 478 |
! ! |
479 |
||
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
480 |
!TreeItem methodsFor:'change & update'! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
481 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
482 |
changed |
786 | 483 |
"node changed; raise notification to model |
484 |
" |
|
485 |
self changed:#value |
|
784 | 486 |
! |
487 |
||
786 | 488 |
changed:what |
489 |
"node changed; raise notification to model |
|
490 |
" |
|
491 |
|model| |
|
784 | 492 |
|
795 | 493 |
what == #value |
982
d94684e7fe9f
sending #changed to a tree item should not invoke retrieving children
tz
parents:
909
diff
changeset
|
494 |
ifTrue: [self retrieveLabel] |
795 | 495 |
ifFalse: [what == #children ifTrue: [self retrieveChildren]]. |
786 | 496 |
|
497 |
(model := self model) notNil ifTrue:[ |
|
795 | 498 |
model update:what with:nil from:self |
786 | 499 |
] |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
500 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
501 |
|
2038 | 502 |
changedSelected |
503 |
"called if the node is selected |
|
504 |
" |
|
505 |
! |
|
506 |
||
786 | 507 |
update:something with:aParameter from:anItem |
508 |
"raise change notification to my model |
|
509 |
" |
|
510 |
|m| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
511 |
|
786 | 512 |
(m := self model) notNil ifTrue:[ |
513 |
m update:something with:aParameter from:anItem |
|
514 |
] |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
515 |
! ! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
516 |
|
506 | 517 |
!TreeItem methodsFor:'converting'! |
518 |
||
519 |
fromLiteralArrayEncoding:aLiteralEncodedArray |
|
786 | 520 |
"read my contents from a aLiteralEncodedArray. |
521 |
" |
|
506 | 522 |
|narg| |
523 |
||
524 |
( (aLiteralEncodedArray size > 0) |
|
525 |
and:[(name := aLiteralEncodedArray at:1) isString]) ifFalse:[ |
|
526 |
^ nil |
|
527 |
]. |
|
528 |
narg := aLiteralEncodedArray at:2 ifAbsent:nil. |
|
529 |
||
530 |
name isSymbol ifTrue:[ |
|
531 |
(narg isArray and:[aLiteralEncodedArray size == 2]) ifTrue:[ |
|
532 |
^ self fromLiteralArrayEncoding:narg |
|
533 |
]. |
|
534 |
^ nil |
|
535 |
]. |
|
536 |
||
537 |
narg isArray ifFalse:[ |
|
538 |
contents := narg. |
|
539 |
narg := aLiteralEncodedArray at:3 ifAbsent:nil. |
|
540 |
]. |
|
541 |
||
542 |
narg isArray ifTrue:[ |
|
543 |
children := OrderedCollection new. |
|
544 |
||
545 |
narg do:[:aSubArray||aChild| |
|
546 |
children add:(aChild := TreeItem new). |
|
547 |
aChild fromLiteralArrayEncoding:aSubArray. |
|
548 |
aChild parent:self. |
|
549 |
] |
|
550 |
] |
|
551 |
||
552 |
||
553 |
||
554 |
! |
|
555 |
||
556 |
literalArrayEncoding |
|
786 | 557 |
"return myself encoded as a literal array |
558 |
" |
|
559 |
|array childs size noChld| |
|
506 | 560 |
|
561 |
contents isString ifTrue:[size := 2] |
|
562 |
ifFalse:[size := 1]. |
|
563 |
||
786 | 564 |
noChld := self numberOfChildren. |
565 |
||
566 |
noChld == 0 ifTrue:[ |
|
506 | 567 |
array := Array new:size |
568 |
] ifFalse:[ |
|
786 | 569 |
array := Array new:size + 1. |
570 |
childs := Array new:noChld. |
|
506 | 571 |
array at:(size + 1) put:childs. |
572 |
||
573 |
self children keysAndValuesDo:[:i :aChild| |
|
574 |
childs at:i put:(aChild literalArrayEncoding) |
|
575 |
] |
|
576 |
]. |
|
577 |
array at:1 put:(name ? ''). |
|
578 |
||
579 |
contents isString ifTrue:[ |
|
580 |
array at:2 put:contents |
|
581 |
]. |
|
582 |
parent isNil ifTrue:[ |
|
583 |
array := Array with:#TreeItem with:array. |
|
584 |
]. |
|
585 |
^ array |
|
586 |
||
587 |
||
588 |
! ! |
|
589 |
||
2102 | 590 |
!TreeItem methodsFor:'copying'! |
457 | 591 |
|
592 |
copy |
|
2102 | 593 |
|node newContents| |
457 | 594 |
|
595 |
node := self species new. |
|
596 |
||
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
597 |
contents ~~ UnknownContents ifTrue:[ |
2102 | 598 |
newContents := contents copy. |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
599 |
] ifFalse:[ |
2102 | 600 |
newContents := UnknownContents |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
601 |
]. |
2102 | 602 |
node name:name copy. |
603 |
node contents:newContents. |
|
469 | 604 |
node children:(self children collect:[:c| c copy]). |
786 | 605 |
node readChildren:readChildren. |
2102 | 606 |
^ node |
457 | 607 |
! ! |
608 |
||
609 |
!TreeItem methodsFor:'enumerating'! |
|
610 |
||
611 |
allChildrenDo:aOneArgBlock |
|
612 |
"evaluate a block on each children and subchildren |
|
613 |
" |
|
469 | 614 |
self children do:[:aChild| |
457 | 615 |
aOneArgBlock value:aChild. |
616 |
aChild allChildrenDo:aOneArgBlock |
|
617 |
] |
|
618 |
! |
|
619 |
||
620 |
allWithParentAndChildrenDo:aTwoArgBlock |
|
621 |
self childrenDo:[:aChild| |
|
622 |
aTwoArgBlock value:self value:aChild. |
|
623 |
aChild allWithParentAndChildrenDo:aTwoArgBlock |
|
624 |
] |
|
625 |
! |
|
626 |
||
627 |
childrenDo:aOneArgBlock |
|
628 |
"evaluate a block on each children( excluding sub-children ) |
|
629 |
" |
|
837 | 630 |
self children do:aOneArgBlock |
457 | 631 |
! |
632 |
||
1241 | 633 |
detectParent:aBlock |
634 |
"evaluate aBlock for my parent-chain; return the parent for which it returns true" |
|
635 |
||
636 |
|p| |
|
637 |
||
638 |
p := parent. |
|
639 |
[p notNil] whileTrue:[ |
|
640 |
(aBlock value:p) ifTrue:[^ p]. |
|
641 |
p := p parent |
|
642 |
]. |
|
643 |
^ nil |
|
644 |
||
645 |
! |
|
646 |
||
837 | 647 |
each:something do:aOneArgBlock |
457 | 648 |
"evaluate a block for something or in case of a collection for each |
649 |
element in the collection |
|
650 |
" |
|
651 |
something notNil ifTrue:[ |
|
837 | 652 |
something isCollection ifTrue:[something do:aOneArgBlock] |
653 |
ifFalse:[aOneArgBlock value:something] |
|
457 | 654 |
] |
655 |
||
656 |
! ! |
|
657 |
||
2501 | 658 |
!TreeItem methodsFor:'initialization & release'! |
457 | 659 |
|
660 |
initialize |
|
661 |
"setup defaults |
|
662 |
" |
|
506 | 663 |
super initialize. |
664 |
||
457 | 665 |
children := OrderedCollection new. |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
666 |
readChildren := hide := true. |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
667 |
contents := UnknownContents. |
457 | 668 |
! ! |
669 |
||
1825 | 670 |
!TreeItem methodsFor:'printing & storing'! |
1172 | 671 |
|
672 |
asString |
|
3361
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
673 |
"sometimes used by the SelectionInListView to get the name" |
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
674 |
|
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
675 |
^ self name |
1172 | 676 |
! |
677 |
||
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
678 |
displayString |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
679 |
^ self class name , '(' , self printString , ')' |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
680 |
! |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
681 |
|
3361
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
682 |
printOn:aStream |
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
683 |
"sometimes used by the SelectionInListView to get the name" |
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
684 |
|
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
685 |
aStream nextPutAll:self name |
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
686 |
! |
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
687 |
|
1172 | 688 |
printString |
3361
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
689 |
"sometimes used by the SelectionInListView to get the name" |
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
690 |
|
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
691 |
^ self name |
1172 | 692 |
! |
693 |
||
694 |
printableEditValue |
|
3361
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
695 |
"returns the printable edit value or nil" |
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
696 |
|
1172 | 697 |
^ nil |
698 |
! ! |
|
699 |
||
457 | 700 |
!TreeItem methodsFor:'queries'! |
701 |
||
1172 | 702 |
canEdit |
703 |
"returns true if field is editable |
|
704 |
" |
|
705 |
^ false |
|
706 |
! |
|
707 |
||
457 | 708 |
hasChildren |
786 | 709 |
"returns true if any child exists |
457 | 710 |
" |
786 | 711 |
^ self children notEmpty |
457 | 712 |
! |
713 |
||
834 | 714 |
hasChildrenWithSubChildren |
2930 | 715 |
"returns true if any child exists and has children too" |
834 | 716 |
|
2930 | 717 |
self children contains:[:aChild| aChild hasChildren] |
834 | 718 |
! |
719 |
||
720 |
hasExpandedChildren |
|
721 |
"returns true if any of my children is expanded |
|
722 |
" |
|
3123
8912a9a3bc01
code cleanup: use #contains instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
2930
diff
changeset
|
723 |
^ children contains:[:aChild | aChild hidden not]. |
8912a9a3bc01
code cleanup: use #contains instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
2930
diff
changeset
|
724 |
|
8912a9a3bc01
code cleanup: use #contains instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
2930
diff
changeset
|
725 |
"Modified: / 13-10-2006 / 13:00:05 / cg" |
834 | 726 |
! |
727 |
||
457 | 728 |
hidden |
786 | 729 |
"returns true if node is not visible |
730 |
" |
|
457 | 731 |
^ hide |
732 |
! |
|
733 |
||
734 |
isCollapsable |
|
735 |
"is collabsable; children existing and shown |
|
736 |
" |
|
469 | 737 |
^ (self hasChildren and:[hide == false]) |
457 | 738 |
! |
739 |
||
569 | 740 |
isContainedByParent:aParent |
741 |
"returns true if contained in subtree of a parent |
|
742 |
" |
|
743 |
|p| |
|
744 |
||
745 |
p := parent. |
|
746 |
||
747 |
[p notNil] whileTrue:[ |
|
748 |
p == aParent ifTrue:[^ true ]. |
|
749 |
p := p parent |
|
750 |
]. |
|
751 |
^ false |
|
752 |
! |
|
753 |
||
457 | 754 |
isExpandable |
755 |
"is expandable; children existing and hidden |
|
756 |
" |
|
469 | 757 |
^ (self hasChildren and:[hide == true]) |
457 | 758 |
|
759 |
! |
|
760 |
||
1205 | 761 |
isExpanded |
762 |
"return true if I am expanded" |
|
763 |
^ hide not |
|
764 |
||
765 |
! |
|
766 |
||
472 | 767 |
numberOfChildren |
786 | 768 |
"returns number of children |
769 |
" |
|
472 | 770 |
^ self children size |
771 |
! |
|
772 |
||
841 | 773 |
showIndicator |
774 |
"returns true if children exists |
|
775 |
" |
|
776 |
^ self hasChildren |
|
777 |
! |
|
778 |
||
779 |
shown |
|
780 |
"returns true if node is visible |
|
781 |
" |
|
782 |
^ hide not |
|
783 |
! ! |
|
784 |
||
785 |
!TreeItem methodsFor:'recomputation'! |
|
786 |
||
858 | 787 |
addVisibleChildrenTo:aList |
788 |
"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
|
789 |
" |
838 | 790 |
|item |
791 |
size "{ Class: SmallInteger }" |
|
792 |
idx "{ Class: SmallInteger }" |
|
793 |
| |
|
794 |
||
457 | 795 |
hide ifFalse:[ |
841 | 796 |
readChildren ifTrue:[ |
797 |
self children |
|
798 |
]. |
|
849 | 799 |
(size := children size) ~~ 0 ifTrue:[ |
838 | 800 |
idx := 1. |
801 |
size timesRepeat:[ |
|
802 |
aList add:(item := children at:idx). |
|
858 | 803 |
item addVisibleChildrenTo:aList. |
838 | 804 |
idx := idx + 1. |
805 |
] |
|
457 | 806 |
] |
807 |
] |
|
841 | 808 |
|
457 | 809 |
|
569 | 810 |
|
858 | 811 |
! |
812 |
||
813 |
numberOfAllVisibleChildren |
|
814 |
"returns number of all visible children including all the children of children |
|
815 |
" |
|
816 |
|total "{ Class: SmallInteger }"| |
|
817 |
||
818 |
hide ifTrue:[ |
|
819 |
^ 0 |
|
820 |
]. |
|
821 |
readChildren ifTrue:[ self children ]. |
|
822 |
||
823 |
(total := children size) ~~ 0 ifTrue:[ |
|
824 |
children do:[:aChild| total := total + aChild numberOfAllVisibleChildren ]. |
|
825 |
]. |
|
826 |
^ total |
|
827 |
||
828 |
||
829 |
||
457 | 830 |
! ! |
831 |
||
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
832 |
!TreeItem methodsFor:'retrieving'! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
833 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
834 |
childrenAction |
786 | 835 |
"get children action block |
836 |
" |
|
837 |
|m| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
838 |
|
786 | 839 |
^ (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
|
840 |
! |
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 |
contentsAction |
786 | 843 |
"get contents 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 contentsAction] 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 |
iconAction |
786 | 851 |
"get icon 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 iconAction] 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 |
labelAction |
3699 | 859 |
"get label action block " |
860 |
||
786 | 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 labelAction] 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 |
retrieveAll |
786 | 867 |
"retrieve all values from model |
868 |
" |
|
784 | 869 |
self "retrieveContents;" retrieveLabel; retrieveChildren |
761
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 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
872 |
retrieveAndEvaluate: aBlockSymbol |
1279 | 873 |
"retrieve a specific value from model; if no model exists, nil is returned |
786 | 874 |
" |
2071
7c58c73eff49
use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents:
2038
diff
changeset
|
875 |
|arg model| |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
876 |
|
786 | 877 |
(model := self model) isNil ifTrue:[ |
878 |
^ nil |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
879 |
]. |
786 | 880 |
arg := model perform:aBlockSymbol. |
881 |
||
882 |
arg isBlock ifFalse:[ |
|
883 |
^ arg value |
|
884 |
]. |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
885 |
|
2071
7c58c73eff49
use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents:
2038
diff
changeset
|
886 |
^ arg valueWithOptionalArgument:self |
761
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 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
889 |
retrieveChildren |
786 | 890 |
"retrieve children from model |
891 |
" |
|
892 |
|retChildren cls| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
893 |
|
786 | 894 |
retChildren := self retrieveAndEvaluate:#childrenAction. |
895 |
||
896 |
retChildren notNil ifTrue:[ |
|
897 |
retChildren isCollection ifFalse: [retChildren := OrderedCollection with:retChildren]. |
|
898 |
cls := self class. |
|
899 |
||
900 |
self children: (retChildren collect: |
|
768
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
901 |
[:obj| |
786 | 902 |
(obj isKindOf:cls) ifTrue:[obj] |
903 |
ifFalse:[cls new contents:obj] |
|
768
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
904 |
]). |
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
905 |
readChildren := false. |
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
906 |
]. |
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
907 |
|
786 | 908 |
^ children |
761
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 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
911 |
retrieveContents |
786 | 912 |
"retrieve contents value from model; |
913 |
" |
|
914 |
|cont| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
915 |
|
786 | 916 |
(cont := self retrieveAndEvaluate: #contentsAction) isNil ifTrue:[ |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
917 |
contents == UnknownContents ifTrue:[ |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
918 |
cont := '' |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
919 |
] |
786 | 920 |
]. |
921 |
^ contents := cont |
|
761
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 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
924 |
retrieveLabel |
786 | 925 |
"retrieve label from model |
926 |
" |
|
927 |
|n| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
928 |
|
786 | 929 |
(n := self retrieveAndEvaluate:#labelAction) isNil ifTrue:[ |
930 |
n := name ? '' |
|
931 |
]. |
|
932 |
^ name := n |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
933 |
! ! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
934 |
|
479 | 935 |
!TreeItem methodsFor:'searching'! |
936 |
||
1172 | 937 |
childAt:anIndex |
1551 | 938 |
"get child at an index or nil" |
939 |
||
940 |
^ self children at:anIndex ifAbsent:nil |
|
1172 | 941 |
! |
942 |
||
479 | 943 |
detectChild:aOneArgBlock |
1551 | 944 |
"evaluate the block on each child; |
945 |
returns the child's node or nil. |
|
946 |
This searches my children only - not walking down sublevels. |
|
479 | 947 |
" |
1551 | 948 |
|
479 | 949 |
^ self children detect:aOneArgBlock ifNone:nil |
950 |
||
951 |
! |
|
952 |
||
849 | 953 |
detectChild:aTwoArgBlock arguments:args |
954 |
"detect a child the evaluation of the block returns true. The |
|
955 |
first argument to the block is the item, the second argument |
|
1551 | 956 |
the value derived from the argument list at node-level ... |
957 |
I.e. for each sublevel, a different block arg can be specified. |
|
958 |
The number of arguments also defines the search level. |
|
1552 | 959 |
i.e. if you pass (1 to:10) as args, the block will get the sub-level |
960 |
as second argument and stop the search after 10 levels. |
|
849 | 961 |
" |
1551 | 962 |
|
849 | 963 |
^ self detectChild:aTwoArgBlock arguments:args index:1 |
964 |
! |
|
965 |
||
1551 | 966 |
detectFirstChild:anOneArgBlock |
967 |
"detect the first child which evaluation of anOneArgBlock returns true. |
|
968 |
Recursively walks down the node-tree. |
|
969 |
" |
|
970 |
|node children| |
|
971 |
||
972 |
(anOneArgBlock value:self) ifTrue:[ |
|
973 |
^ self. |
|
974 |
]. |
|
975 |
(children := self children) notEmpty ifTrue:[ |
|
976 |
children do:[:aChild | |
|
977 |
(node := aChild detectFirstChild:anOneArgBlock) notNil ifTrue:[ |
|
978 |
^ node |
|
979 |
] |
|
980 |
] |
|
981 |
]. |
|
982 |
^ nil |
|
983 |
! |
|
984 |
||
985 |
indexOfChild:aChild |
|
986 |
"get index of a child or 0 |
|
987 |
" |
|
988 |
^ aChild notNil ifTrue:[self children identityIndexOf:aChild] |
|
989 |
ifFalse:[0] |
|
990 |
! ! |
|
991 |
||
2498 | 992 |
!TreeItem methodsFor:'searching-private'! |
1551 | 993 |
|
849 | 994 |
detectChild:aTwoArgBlock arguments:args index:idxArgs |
1552 | 995 |
"helper for limited search. |
996 |
detect a child the evaluation of the block returns true. The |
|
849 | 997 |
first argument to the block is the item, the second argument |
1551 | 998 |
the value derived from the argument list at an index. |
999 |
This one recursively walks down the tree searching for a node. |
|
849 | 1000 |
" |
1001 |
|num node| |
|
1002 |
||
1003 |
(num := args size) >= idxArgs ifTrue:[ |
|
1004 |
(aTwoArgBlock value:self value:(args at:idxArgs)) ifFalse:[ |
|
1005 |
^ nil |
|
1006 |
]. |
|
1007 |
||
1008 |
idxArgs == num ifTrue:[ |
|
1009 |
^ self |
|
1010 |
]. |
|
1011 |
||
1012 |
self children notEmpty ifTrue:[ |
|
1013 |
num := idxArgs + 1. |
|
1014 |
||
1015 |
children do:[:aChild| |
|
1016 |
node := aChild detectChild:aTwoArgBlock arguments:args index:num. |
|
1017 |
||
1018 |
node notNil ifTrue:[ |
|
1019 |
^ node |
|
1020 |
] |
|
1021 |
] |
|
1022 |
] |
|
1023 |
]. |
|
1024 |
^ nil |
|
479 | 1025 |
! ! |
1026 |
||
457 | 1027 |
!TreeItem class methodsFor:'documentation'! |
1028 |
||
1029 |
version |
|
3907
860a141af427
changed: #newAsTreeFromSmalltalkClass:
Claus Gittinger <cg@exept.de>
parents:
3699
diff
changeset
|
1030 |
^ '$Header: /cvs/stx/stx/libwidg2/TreeItem.st,v 1.50 2010-06-14 11:02:20 cg Exp $' |
860a141af427
changed: #newAsTreeFromSmalltalkClass:
Claus Gittinger <cg@exept.de>
parents:
3699
diff
changeset
|
1031 |
! |
860a141af427
changed: #newAsTreeFromSmalltalkClass:
Claus Gittinger <cg@exept.de>
parents:
3699
diff
changeset
|
1032 |
|
860a141af427
changed: #newAsTreeFromSmalltalkClass:
Claus Gittinger <cg@exept.de>
parents:
3699
diff
changeset
|
1033 |
version_CVS |
860a141af427
changed: #newAsTreeFromSmalltalkClass:
Claus Gittinger <cg@exept.de>
parents:
3699
diff
changeset
|
1034 |
^ '$Header: /cvs/stx/stx/libwidg2/TreeItem.st,v 1.50 2010-06-14 11:02:20 cg Exp $' |
457 | 1035 |
! ! |
2404 | 1036 |
|
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
1037 |
TreeItem initialize! |