author | Merge Script |
Sat, 30 Apr 2016 06:46:08 +0200 | |
branch | jv |
changeset 5037 | a991ac280740 |
parent 4140 | 267c46c27c2a |
child 5233 | 011a234e6095 |
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 |
||
4140
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
678 |
displayOn:aGCOrStream |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
679 |
"Compatibility |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
680 |
append a printed desription on some stream (Dolphin, Squeak) |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
681 |
OR: |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
682 |
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
|
683 |
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
|
684 |
(although the fallBack is to display its printString ...)" |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
685 |
|
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
686 |
"/ 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
|
687 |
"/ 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
|
688 |
aGCOrStream isStream ifFalse:[ |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
689 |
^ super displayOn:aGCOrStream. |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
690 |
]. |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
691 |
|
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
692 |
aGCOrStream |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
693 |
nextPutAll:self class name; |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
694 |
nextPut:$(. |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
695 |
self printOn:aGCOrStream. |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
696 |
aGCOrStream nextPut:$) |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
697 |
! |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
698 |
|
3361
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
699 |
printOn:aStream |
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
700 |
"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
|
701 |
|
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
702 |
aStream nextPutAll:self 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 |
|
1172 | 705 |
printString |
3361
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
706 |
"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
|
707 |
|
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
708 |
^ self name |
1172 | 709 |
! |
710 |
||
711 |
printableEditValue |
|
3361
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
712 |
"returns the printable edit value or nil" |
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
713 |
|
1172 | 714 |
^ nil |
715 |
! ! |
|
716 |
||
457 | 717 |
!TreeItem methodsFor:'queries'! |
718 |
||
1172 | 719 |
canEdit |
720 |
"returns true if field is editable |
|
721 |
" |
|
722 |
^ false |
|
723 |
! |
|
724 |
||
457 | 725 |
hasChildren |
786 | 726 |
"returns true if any child exists |
457 | 727 |
" |
786 | 728 |
^ self children notEmpty |
457 | 729 |
! |
730 |
||
834 | 731 |
hasChildrenWithSubChildren |
2930 | 732 |
"returns true if any child exists and has children too" |
834 | 733 |
|
2930 | 734 |
self children contains:[:aChild| aChild hasChildren] |
834 | 735 |
! |
736 |
||
737 |
hasExpandedChildren |
|
738 |
"returns true if any of my children is expanded |
|
739 |
" |
|
3123
8912a9a3bc01
code cleanup: use #contains instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
2930
diff
changeset
|
740 |
^ children contains:[:aChild | aChild hidden not]. |
8912a9a3bc01
code cleanup: use #contains instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
2930
diff
changeset
|
741 |
|
8912a9a3bc01
code cleanup: use #contains instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
2930
diff
changeset
|
742 |
"Modified: / 13-10-2006 / 13:00:05 / cg" |
834 | 743 |
! |
744 |
||
457 | 745 |
hidden |
786 | 746 |
"returns true if node is not visible |
747 |
" |
|
457 | 748 |
^ hide |
749 |
! |
|
750 |
||
751 |
isCollapsable |
|
752 |
"is collabsable; children existing and shown |
|
753 |
" |
|
469 | 754 |
^ (self hasChildren and:[hide == false]) |
457 | 755 |
! |
756 |
||
569 | 757 |
isContainedByParent:aParent |
758 |
"returns true if contained in subtree of a parent |
|
759 |
" |
|
760 |
|p| |
|
761 |
||
762 |
p := parent. |
|
763 |
||
764 |
[p notNil] whileTrue:[ |
|
765 |
p == aParent ifTrue:[^ true ]. |
|
766 |
p := p parent |
|
767 |
]. |
|
768 |
^ false |
|
769 |
! |
|
770 |
||
457 | 771 |
isExpandable |
772 |
"is expandable; children existing and hidden |
|
773 |
" |
|
469 | 774 |
^ (self hasChildren and:[hide == true]) |
457 | 775 |
|
776 |
! |
|
777 |
||
1205 | 778 |
isExpanded |
779 |
"return true if I am expanded" |
|
780 |
^ hide not |
|
781 |
||
782 |
! |
|
783 |
||
472 | 784 |
numberOfChildren |
786 | 785 |
"returns number of children |
786 |
" |
|
472 | 787 |
^ self children size |
788 |
! |
|
789 |
||
841 | 790 |
showIndicator |
791 |
"returns true if children exists |
|
792 |
" |
|
793 |
^ self hasChildren |
|
794 |
! |
|
795 |
||
796 |
shown |
|
797 |
"returns true if node is visible |
|
798 |
" |
|
799 |
^ hide not |
|
800 |
! ! |
|
801 |
||
802 |
!TreeItem methodsFor:'recomputation'! |
|
803 |
||
858 | 804 |
addVisibleChildrenTo:aList |
805 |
"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
|
806 |
" |
838 | 807 |
|item |
808 |
size "{ Class: SmallInteger }" |
|
809 |
idx "{ Class: SmallInteger }" |
|
810 |
| |
|
811 |
||
457 | 812 |
hide ifFalse:[ |
841 | 813 |
readChildren ifTrue:[ |
814 |
self children |
|
815 |
]. |
|
849 | 816 |
(size := children size) ~~ 0 ifTrue:[ |
838 | 817 |
idx := 1. |
818 |
size timesRepeat:[ |
|
819 |
aList add:(item := children at:idx). |
|
858 | 820 |
item addVisibleChildrenTo:aList. |
838 | 821 |
idx := idx + 1. |
822 |
] |
|
457 | 823 |
] |
824 |
] |
|
841 | 825 |
|
457 | 826 |
|
569 | 827 |
|
858 | 828 |
! |
829 |
||
830 |
numberOfAllVisibleChildren |
|
831 |
"returns number of all visible children including all the children of children |
|
832 |
" |
|
833 |
|total "{ Class: SmallInteger }"| |
|
834 |
||
835 |
hide ifTrue:[ |
|
836 |
^ 0 |
|
837 |
]. |
|
838 |
readChildren ifTrue:[ self children ]. |
|
839 |
||
840 |
(total := children size) ~~ 0 ifTrue:[ |
|
841 |
children do:[:aChild| total := total + aChild numberOfAllVisibleChildren ]. |
|
842 |
]. |
|
843 |
^ total |
|
844 |
||
845 |
||
846 |
||
457 | 847 |
! ! |
848 |
||
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
849 |
!TreeItem methodsFor:'retrieving'! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
850 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
851 |
childrenAction |
786 | 852 |
"get children action block |
853 |
" |
|
854 |
|m| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
855 |
|
786 | 856 |
^ (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
|
857 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
858 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
859 |
contentsAction |
786 | 860 |
"get contents action block |
861 |
" |
|
862 |
|m| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
863 |
|
786 | 864 |
^ (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
|
865 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
866 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
867 |
iconAction |
786 | 868 |
"get icon action block |
869 |
" |
|
870 |
|m| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
871 |
|
786 | 872 |
^ (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
|
873 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
874 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
875 |
labelAction |
3699 | 876 |
"get label action block " |
877 |
||
786 | 878 |
|m| |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
879 |
|
786 | 880 |
^ (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
|
881 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
882 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
883 |
retrieveAll |
786 | 884 |
"retrieve all values from model |
885 |
" |
|
784 | 886 |
self "retrieveContents;" retrieveLabel; retrieveChildren |
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 |
retrieveAndEvaluate: aBlockSymbol |
1279 | 890 |
"retrieve a specific value from model; if no model exists, nil is returned |
786 | 891 |
" |
2071
7c58c73eff49
use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents:
2038
diff
changeset
|
892 |
|arg model| |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
893 |
|
786 | 894 |
(model := self model) isNil ifTrue:[ |
895 |
^ nil |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
896 |
]. |
786 | 897 |
arg := model perform:aBlockSymbol. |
898 |
||
899 |
arg isBlock ifFalse:[ |
|
900 |
^ arg value |
|
901 |
]. |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
902 |
|
2071
7c58c73eff49
use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents:
2038
diff
changeset
|
903 |
^ arg valueWithOptionalArgument:self |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
904 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
905 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
906 |
retrieveChildren |
786 | 907 |
"retrieve children from model |
908 |
" |
|
909 |
|retChildren cls| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
910 |
|
786 | 911 |
retChildren := self retrieveAndEvaluate:#childrenAction. |
912 |
||
913 |
retChildren notNil ifTrue:[ |
|
914 |
retChildren isCollection ifFalse: [retChildren := OrderedCollection with:retChildren]. |
|
915 |
cls := self class. |
|
916 |
||
917 |
self children: (retChildren collect: |
|
768
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
918 |
[:obj| |
786 | 919 |
(obj isKindOf:cls) ifTrue:[obj] |
920 |
ifFalse:[cls new contents:obj] |
|
768
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
921 |
]). |
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
922 |
readChildren := false. |
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 |
|
786 | 925 |
^ children |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
926 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
927 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
928 |
retrieveContents |
786 | 929 |
"retrieve contents value from model; |
930 |
" |
|
931 |
|cont| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
932 |
|
786 | 933 |
(cont := self retrieveAndEvaluate: #contentsAction) isNil ifTrue:[ |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
934 |
contents == UnknownContents ifTrue:[ |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
935 |
cont := '' |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
936 |
] |
786 | 937 |
]. |
938 |
^ contents := cont |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
939 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
940 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
941 |
retrieveLabel |
786 | 942 |
"retrieve label from model |
943 |
" |
|
944 |
|n| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
945 |
|
786 | 946 |
(n := self retrieveAndEvaluate:#labelAction) isNil ifTrue:[ |
947 |
n := name ? '' |
|
948 |
]. |
|
949 |
^ name := n |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
950 |
! ! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
951 |
|
479 | 952 |
!TreeItem methodsFor:'searching'! |
953 |
||
1172 | 954 |
childAt:anIndex |
1551 | 955 |
"get child at an index or nil" |
956 |
||
957 |
^ self children at:anIndex ifAbsent:nil |
|
1172 | 958 |
! |
959 |
||
479 | 960 |
detectChild:aOneArgBlock |
1551 | 961 |
"evaluate the block on each child; |
962 |
returns the child's node or nil. |
|
963 |
This searches my children only - not walking down sublevels. |
|
479 | 964 |
" |
1551 | 965 |
|
479 | 966 |
^ self children detect:aOneArgBlock ifNone:nil |
967 |
||
968 |
! |
|
969 |
||
849 | 970 |
detectChild:aTwoArgBlock arguments:args |
971 |
"detect a child the evaluation of the block returns true. The |
|
972 |
first argument to the block is the item, the second argument |
|
1551 | 973 |
the value derived from the argument list at node-level ... |
974 |
I.e. for each sublevel, a different block arg can be specified. |
|
975 |
The number of arguments also defines the search level. |
|
1552 | 976 |
i.e. if you pass (1 to:10) as args, the block will get the sub-level |
977 |
as second argument and stop the search after 10 levels. |
|
849 | 978 |
" |
1551 | 979 |
|
849 | 980 |
^ self detectChild:aTwoArgBlock arguments:args index:1 |
981 |
! |
|
982 |
||
1551 | 983 |
detectFirstChild:anOneArgBlock |
984 |
"detect the first child which evaluation of anOneArgBlock returns true. |
|
985 |
Recursively walks down the node-tree. |
|
986 |
" |
|
987 |
|node children| |
|
988 |
||
989 |
(anOneArgBlock value:self) ifTrue:[ |
|
990 |
^ self. |
|
991 |
]. |
|
992 |
(children := self children) notEmpty ifTrue:[ |
|
993 |
children do:[:aChild | |
|
994 |
(node := aChild detectFirstChild:anOneArgBlock) notNil ifTrue:[ |
|
995 |
^ node |
|
996 |
] |
|
997 |
] |
|
998 |
]. |
|
999 |
^ nil |
|
1000 |
! |
|
1001 |
||
1002 |
indexOfChild:aChild |
|
1003 |
"get index of a child or 0 |
|
1004 |
" |
|
1005 |
^ aChild notNil ifTrue:[self children identityIndexOf:aChild] |
|
1006 |
ifFalse:[0] |
|
1007 |
! ! |
|
1008 |
||
2498 | 1009 |
!TreeItem methodsFor:'searching-private'! |
1551 | 1010 |
|
849 | 1011 |
detectChild:aTwoArgBlock arguments:args index:idxArgs |
1552 | 1012 |
"helper for limited search. |
1013 |
detect a child the evaluation of the block returns true. The |
|
849 | 1014 |
first argument to the block is the item, the second argument |
1551 | 1015 |
the value derived from the argument list at an index. |
1016 |
This one recursively walks down the tree searching for a node. |
|
849 | 1017 |
" |
1018 |
|num node| |
|
1019 |
||
1020 |
(num := args size) >= idxArgs ifTrue:[ |
|
1021 |
(aTwoArgBlock value:self value:(args at:idxArgs)) ifFalse:[ |
|
1022 |
^ nil |
|
1023 |
]. |
|
1024 |
||
1025 |
idxArgs == num ifTrue:[ |
|
1026 |
^ self |
|
1027 |
]. |
|
1028 |
||
1029 |
self children notEmpty ifTrue:[ |
|
1030 |
num := idxArgs + 1. |
|
1031 |
||
1032 |
children do:[:aChild| |
|
1033 |
node := aChild detectChild:aTwoArgBlock arguments:args index:num. |
|
1034 |
||
1035 |
node notNil ifTrue:[ |
|
1036 |
^ node |
|
1037 |
] |
|
1038 |
] |
|
1039 |
] |
|
1040 |
]. |
|
1041 |
^ nil |
|
479 | 1042 |
! ! |
1043 |
||
457 | 1044 |
!TreeItem class methodsFor:'documentation'! |
1045 |
||
1046 |
version |
|
4140
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
1047 |
^ '$Header: /cvs/stx/stx/libwidg2/TreeItem.st,v 1.51 2012-08-03 15:53:14 stefan Exp $' |
3907
860a141af427
changed: #newAsTreeFromSmalltalkClass:
Claus Gittinger <cg@exept.de>
parents:
3699
diff
changeset
|
1048 |
! |
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 |
version_CVS |
4140
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
1051 |
^ '$Header: /cvs/stx/stx/libwidg2/TreeItem.st,v 1.51 2012-08-03 15:53:14 stefan Exp $' |
457 | 1052 |
! ! |
2404 | 1053 |
|
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
1054 |
TreeItem initialize! |