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