author | Claus Gittinger <cg@exept.de> |
Sat, 29 Jun 2019 23:25:22 +0200 | |
changeset 6081 | 52da01945044 |
parent 6079 | c61b633da982 |
permissions | -rw-r--r-- |
6079 | 1 |
"{ Encoding: utf8 }" |
2 |
||
457 | 3 |
" |
4 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
1818 | 14 |
"{ Package: 'stx:libwidg2' }" |
15 |
||
5233 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
457 | 18 |
Object subclass:#TreeItem |
795 | 19 |
instanceVariableNames:'name tree parent children contents hide readChildren' |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
20 |
classVariableNames:'UnknownContents' |
795 | 21 |
poolDictionaries:'' |
22 |
category:'Interface-Support' |
|
457 | 23 |
! |
24 |
||
25 |
!TreeItem class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger |
|
30 |
All Rights Reserved |
|
31 |
||
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
||
40 |
||
41 |
||
42 |
! |
|
43 |
||
44 |
documentation |
|
45 |
" |
|
5458 | 46 |
THIS CLASS HAS BEEN OBSOLETED by HierarchicalItem with its corresponding |
47 |
view class HierarchicalListView. Please use these new ones. |
|
457 | 48 |
|
5458 | 49 |
Class to build up tree-like structures to represent file-trees, class tress etc. |
50 |
Especially suited for use with (also now obsolete) SelectionInTree and SelectionInTreeView. |
|
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 |
|
5450 | 118 |
newAsTreeFromNestedList:aListOfElementsOrSublists named:name |
119 |
"create a tree of nodes with fix elements from aListOfElementsOrSublists. |
|
120 |
The tree will contain leafs for any non-collection elements in aListOfElementsOrSublists, |
|
121 |
and sub-trees for 2-element array-elements. |
|
122 |
Useful to be shown in long selection lists, if some grouping is possible" |
|
123 |
||
124 |
|newInst| |
|
125 |
||
126 |
newInst := self new. |
|
127 |
newInst name:name. |
|
128 |
||
129 |
aListOfElementsOrSublists do:[:each | |
|
130 |
each isArray ifTrue:[ |
|
131 |
newInst add:(self newAsTreeFromNestedList:each second named:each first) |
|
132 |
] ifFalse:[ |
|
133 |
newInst add:(self new name:each) |
|
134 |
] |
|
135 |
]. |
|
136 |
^ newInst |
|
137 |
||
138 |
" |
|
139 |
|top model sel root| |
|
140 |
||
141 |
root := TreeItem |
|
142 |
newAsTreeFromNestedList: |
|
143 |
#( |
|
144 |
'one-1' |
|
145 |
'two-1' |
|
146 |
('three...' |
|
147 |
('three-1' |
|
148 |
'three-2' |
|
149 |
'three-3')) |
|
150 |
'four-1' |
|
151 |
('five...' |
|
152 |
('five-1' |
|
153 |
'five-2' |
|
154 |
'five-3' |
|
155 |
'five-4' |
|
156 |
'five-5')) |
|
157 |
('six...' |
|
158 |
('six-1' |
|
159 |
'six-2' |
|
160 |
('six-3...' |
|
161 |
('six-3-1' |
|
162 |
'six-3-2' |
|
163 |
'six-3-3')) |
|
164 |
'six-4' |
|
165 |
('six-5...' |
|
166 |
('six-5-1' |
|
167 |
'five-5-2')) |
|
168 |
) |
|
169 |
) |
|
170 |
'seven-1' |
|
171 |
). |
|
172 |
root expand. |
|
173 |
model := SelectionInTree new root:root. |
|
174 |
||
175 |
top := StandardSystemView new. |
|
176 |
top extent:300@300. |
|
177 |
||
178 |
sel := SelectionInTreeView new. |
|
179 |
sel showDirectoryIndicator:true. |
|
180 |
sel showRoot:false. |
|
181 |
sel imageOpened:nil. |
|
182 |
sel imageClosed:nil. |
|
183 |
sel imageItem:nil. |
|
184 |
sel model: model. |
|
185 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
|
186 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
187 |
top open. |
|
188 |
" |
|
189 |
||
190 |
"Created: / 04-02-2017 / 22:48:28 / cg" |
|
191 |
! |
|
192 |
||
457 | 193 |
newAsTreeFromSmalltalkClass:aClass |
194 |
"create a tree of nodes with aClass and all its |
|
195 |
subclasses as contents. Set the initial level as given." |
|
196 |
||
197 |
|newInst clsName| |
|
198 |
||
199 |
aClass isNil ifTrue:[ |
|
200 |
"/ nil subclasses requested |
|
201 |
clsName := 'nil' |
|
202 |
] ifFalse:[ |
|
203 |
"/ regular tree requested |
|
204 |
clsName := aClass name |
|
205 |
]. |
|
206 |
||
3907
860a141af427
changed: #newAsTreeFromSmalltalkClass:
Claus Gittinger <cg@exept.de>
parents:
3699
diff
changeset
|
207 |
newInst := self new. |
457 | 208 |
newInst name:clsName. |
209 |
||
210 |
aClass isNil ifTrue:[ |
|
211 |
((Smalltalk allClasses select:[:cls | cls superclass isNil]) |
|
212 |
asSortedCollection:[:a :b | a name < b name]) |
|
213 |
do:[:aSubClass | |
|
214 |
newInst add:(self newAsTreeFromSmalltalkClass:aSubClass). |
|
215 |
] |
|
216 |
] ifFalse:[ |
|
217 |
(aClass subclasses asSortedCollection:[:a :b | a name < b name]) |
|
218 |
do:[:aSubClass | |
|
219 |
newInst add:(self newAsTreeFromSmalltalkClass:aSubClass). |
|
220 |
] |
|
221 |
]. |
|
222 |
^newInst |
|
223 |
||
506 | 224 |
" |
225 |
|top model sel root| |
|
226 |
||
227 |
root := TreeItem newAsTreeFromSmalltalkClass:ByteArray. |
|
228 |
root expand. |
|
229 |
model := SelectionInTree new root:root. |
|
230 |
top := StandardSystemView new. |
|
231 |
top extent:300@300. |
|
232 |
||
233 |
sel := SelectionInTreeView new. |
|
234 |
sel model: model. |
|
235 |
sel action:[:nr | Transcript show:'selected:'; showCR:nr]. |
|
236 |
top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
237 |
top open. |
|
238 |
" |
|
457 | 239 |
! ! |
240 |
||
241 |
!TreeItem methodsFor:'accessing'! |
|
242 |
||
243 |
contents |
|
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
244 |
"get the contents; |
5450 | 245 |
usually, the contents is computed lazily |
246 |
i.e. #retrieveContents is invoked when the contents has not yet been set." |
|
247 |
||
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
248 |
contents == UnknownContents ifTrue:[ |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
249 |
self retrieveContents |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
250 |
]. |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
251 |
^contents |
5450 | 252 |
|
253 |
"Modified (comment): / 04-02-2017 / 20:23:22 / cg" |
|
457 | 254 |
! |
255 |
||
256 |
contents:something |
|
5450 | 257 |
"set the contents" |
258 |
||
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
259 |
contents := something |
5450 | 260 |
|
261 |
"Modified (comment): / 04-02-2017 / 20:23:33 / cg" |
|
457 | 262 |
! |
263 |
||
1172 | 264 |
editor |
5450 | 265 |
"returns an editor on the editable value or nil" |
266 |
||
506 | 267 |
^ nil |
5450 | 268 |
|
269 |
"Modified (comment): / 04-02-2017 / 20:23:44 / cg" |
|
506 | 270 |
! |
271 |
||
457 | 272 |
hide |
5450 | 273 |
"retrieve the hide flag " |
274 |
||
457 | 275 |
^ hide |
5450 | 276 |
|
277 |
"Modified (comment): / 04-02-2017 / 20:24:08 / cg" |
|
457 | 278 |
! |
279 |
||
280 |
hide:aBoolean |
|
5450 | 281 |
"set hide flag " |
282 |
||
283 |
hide := aBoolean |
|
284 |
||
285 |
"Modified (comment): / 04-02-2017 / 20:23:55 / cg" |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
286 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
287 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
288 |
icon |
5450 | 289 |
"get the icon" |
290 |
||
772 | 291 |
^self retrieveAndEvaluate: #iconAction |
5450 | 292 |
|
293 |
"Modified (comment): / 04-02-2017 / 20:24:16 / cg" |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
294 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
295 |
|
5629 | 296 |
label |
297 |
"for protocol compatibility with herarchical item" |
|
298 |
||
299 |
^ self name |
|
300 |
||
301 |
"Created: / 20-10-2017 / 11:30:15 / cg" |
|
302 |
! |
|
303 |
||
304 |
labelPath |
|
305 |
"for protocol compatibility with herarchical item" |
|
306 |
||
307 |
^ ({self} , self allParents) reverse collect:#label |
|
308 |
||
309 |
"Created: / 20-10-2017 / 11:30:07 / cg" |
|
310 |
! |
|
311 |
||
457 | 312 |
level |
5450 | 313 |
"get the nesting level" |
314 |
||
315 |
|p lvl| |
|
316 |
||
317 |
lvl := 1. |
|
786 | 318 |
p := self. |
319 |
||
5450 | 320 |
[ (p := p parent) notNil ] whileTrue:[ lvl := lvl + 1 ]. |
321 |
^ lvl |
|
322 |
||
323 |
"Modified (comment): / 04-02-2017 / 20:25:22 / cg" |
|
457 | 324 |
! |
325 |
||
1172 | 326 |
middleButtonMenu |
5450 | 327 |
"returns the middleButtonMenu of the item or nil" |
328 |
||
1172 | 329 |
^ nil |
5450 | 330 |
|
331 |
"Modified (comment): / 04-02-2017 / 20:25:04 / cg" |
|
1172 | 332 |
! |
333 |
||
457 | 334 |
name |
335 |
"get name |
|
772 | 336 |
" |
786 | 337 |
name isNil ifTrue:[ |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
338 |
self retrieveLabel |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
339 |
]. |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
340 |
^name |
457 | 341 |
! |
342 |
||
343 |
name:aString |
|
344 |
name := aString. |
|
345 |
! |
|
346 |
||
347 |
parent |
|
348 |
"get parent |
|
349 |
" |
|
350 |
^ parent |
|
351 |
! |
|
352 |
||
353 |
parent:something |
|
354 |
"set parent |
|
355 |
" |
|
356 |
parent := something. |
|
506 | 357 |
! |
358 |
||
5571 | 359 |
string |
360 |
^ self contents asString |
|
361 |
||
362 |
"Created: / 03-08-2017 / 16:49:05 / cg" |
|
363 |
! |
|
364 |
||
506 | 365 |
value |
366 |
"get contents |
|
367 |
" |
|
368 |
^ self contents |
|
369 |
! |
|
370 |
||
371 |
value:something |
|
5366 | 372 |
"allow TreeItem to be used as a model" |
373 |
||
506 | 374 |
self contents:something |
457 | 375 |
! ! |
376 |
||
1818 | 377 |
!TreeItem methodsFor:'accessing-children'! |
1172 | 378 |
|
379 |
basicLastChild |
|
380 |
"returns the last child without checking for valid sequence |
|
381 |
" |
|
382 |
^ children last |
|
383 |
! |
|
384 |
||
385 |
children |
|
386 |
"get list of children |
|
387 |
" |
|
5572 | 388 |
|
389 |
"/ readChildren is actually: "MUSTreadChildren" - bad naming |
|
1172 | 390 |
(readChildren and:[children isEmpty]) ifTrue:[ |
391 |
self retrieveChildren |
|
392 |
]. |
|
393 |
^children |
|
5572 | 394 |
|
395 |
"Modified (comment): / 04-08-2017 / 14:15:08 / cg" |
|
1172 | 396 |
! |
397 |
||
398 |
children:aCollection |
|
399 |
"set children |
|
1208 | 400 |
" |
401 |
aCollection isNil ifTrue:[ |
|
402 |
children removeAll |
|
403 |
] ifFalse:[ |
|
404 |
aCollection notNil ifTrue:[ |
|
405 |
aCollection do:[:child| child parent:self ]. |
|
5572 | 406 |
"/ readChildren is actually: "MUSTreadChildren" - bad naming |
1208 | 407 |
readChildren := false |
408 |
]. |
|
409 |
children := aCollection |
|
410 |
] |
|
5572 | 411 |
|
412 |
"Modified (comment): / 04-08-2017 / 14:15:13 / cg" |
|
1172 | 413 |
! |
414 |
||
415 |
firstChild |
|
416 |
"returns first child in sequence |
|
417 |
" |
|
418 |
self children notEmpty ifTrue:[ |
|
419 |
^ children at:1 |
|
420 |
]. |
|
421 |
^ nil |
|
422 |
||
423 |
! |
|
424 |
||
425 |
lastChild |
|
3699 | 426 |
"returns the last child in sequence" |
427 |
||
1172 | 428 |
self children notEmpty ifTrue:[ |
429 |
^ children last |
|
430 |
]. |
|
431 |
^ nil |
|
432 |
! |
|
433 |
||
434 |
readChildren:aBoolean |
|
5572 | 435 |
"set MUSTread children flag |
1172 | 436 |
" |
5572 | 437 |
"/ readChildren is actually: "MUSTreadChildren" - bad naming |
1172 | 438 |
readChildren:= aBoolean |
5572 | 439 |
|
440 |
"Modified (comment): / 04-08-2017 / 14:15:25 / cg" |
|
1172 | 441 |
! ! |
442 |
||
1818 | 443 |
!TreeItem methodsFor:'accessing-dimensions'! |
1172 | 444 |
|
445 |
childrenWidthOn:aDevice |
|
446 |
"returns the maximum name length of my children |
|
447 |
" |
|
448 |
|max name| |
|
449 |
||
450 |
max := 0. |
|
451 |
||
452 |
children do:[:aChild| |
|
453 |
(name := aChild name) notNil ifTrue:[ |
|
454 |
max := max max:(name widthOn:aDevice) |
|
455 |
] |
|
456 |
]. |
|
457 |
^ max |
|
458 |
! ! |
|
459 |
||
1818 | 460 |
!TreeItem methodsFor:'accessing-hierarchy'! |
457 | 461 |
|
5629 | 462 |
allParents |
463 |
"return a collection of all parents (in parent, grandparent, ... order)" |
|
464 |
||
465 |
|parents| |
|
466 |
||
467 |
parents := OrderedCollection new. |
|
468 |
self parentsDo:[:p | parents add:p]. |
|
469 |
^ parents. |
|
470 |
||
471 |
"Created: / 20-10-2017 / 11:31:06 / cg" |
|
472 |
! |
|
473 |
||
457 | 474 |
collapse |
469 | 475 |
"hide all my children |
476 |
" |
|
772 | 477 |
hide := true |
457 | 478 |
! |
479 |
||
480 |
collapseAll |
|
469 | 481 |
"hide all my children and sub children |
457 | 482 |
" |
841 | 483 |
hide := true. |
457 | 484 |
|
841 | 485 |
children notEmpty ifTrue:[ |
486 |
children do:[:aChild| aChild collapseAll] |
|
834 | 487 |
] |
488 |
! |
|
489 |
||
469 | 490 |
expand |
491 |
"show all my children |
|
492 |
" |
|
772 | 493 |
hide := false |
457 | 494 |
! |
495 |
||
496 |
expandAll |
|
497 |
"show all my children and sub children |
|
498 |
" |
|
841 | 499 |
hide := false. |
834 | 500 |
|
841 | 501 |
self children notEmpty ifTrue:[ |
502 |
children do:[:aChild| aChild expandAll ] |
|
503 |
] |
|
5629 | 504 |
! |
505 |
||
506 |
parentsDo:aBlock |
|
507 |
"evaluate a block for each parent" |
|
508 |
||
509 |
|prnt| |
|
510 |
||
511 |
prnt := self. |
|
512 |
||
513 |
[(prnt := prnt parent) notNil] whileTrue:[ |
|
514 |
aBlock value:prnt |
|
515 |
]. |
|
516 |
||
517 |
"Created: / 20-10-2017 / 11:31:41 / cg" |
|
457 | 518 |
! ! |
519 |
||
2404 | 520 |
!TreeItem methodsFor:'accessing-mvc'! |
786 | 521 |
|
522 |
model |
|
523 |
"get my model (an instance of selection in tree) or nil |
|
524 |
" |
|
5577 | 525 |
^ parent notNil |
526 |
ifTrue:[parent model] |
|
527 |
ifFalse:[tree] |
|
528 |
||
529 |
"Modified (format): / 16-08-2017 / 19:13:49 / cg" |
|
786 | 530 |
! |
531 |
||
532 |
model:aSelectionInTree |
|
533 |
"set my model (an instance of selection in tree) or nil |
|
534 |
" |
|
535 |
tree:= aSelectionInTree |
|
536 |
! |
|
537 |
||
538 |
tree |
|
539 |
"get my model (an instance of selection in tree) or nil |
|
540 |
" |
|
541 |
^ self model |
|
542 |
! |
|
543 |
||
544 |
tree:aSelectionInTree |
|
545 |
"set my model (an instance of selection in tree) or nil |
|
546 |
" |
|
547 |
self model:aSelectionInTree |
|
548 |
! ! |
|
549 |
||
457 | 550 |
!TreeItem methodsFor:'adding & removing'! |
551 |
||
552 |
add:something |
|
553 |
"add a child or collection of children add end |
|
554 |
" |
|
469 | 555 |
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
|
556 |
|
457 | 557 |
! |
558 |
||
559 |
add:something after:aChild |
|
560 |
"add a child or collection of children add end |
|
561 |
" |
|
562 |
self add:something afterIndex:(self indexOfChild:aChild) |
|
563 |
! |
|
564 |
||
565 |
add:something afterIndex:anIndex |
|
566 |
"add a child or collection after an index |
|
567 |
" |
|
568 |
self add:something beforeIndex:(anIndex + 1) |
|
569 |
! |
|
570 |
||
571 |
add:something before:aChild |
|
572 |
"add a child or collection of children add end |
|
573 |
" |
|
574 |
self add:something beforeIndex:(self indexOfChild:aChild) |
|
575 |
! |
|
576 |
||
577 |
add:something beforeIndex:anIndex |
|
578 |
"add a child or collection before an index |
|
579 |
" |
|
469 | 580 |
|idx children| |
581 |
||
582 |
children := self children. |
|
457 | 583 |
|
584 |
(idx := anIndex) > children size ifTrue:[ |
|
585 |
idx := children size + 1 |
|
586 |
] ifFalse:[ |
|
587 |
idx == 0 ifTrue:[idx := 1] |
|
588 |
]. |
|
589 |
||
590 |
self each:something do:[:el| |
|
591 |
children add:el beforeIndex:idx. |
|
592 |
el parent:self. |
|
593 |
el allWithParentAndChildrenDo:[:aParent :aChild| aChild parent:aParent ]. |
|
594 |
idx := idx + 1. |
|
595 |
] |
|
596 |
! |
|
597 |
||
909 | 598 |
addFirst: something |
599 |
"add a child at the beginning |
|
600 |
" |
|
601 |
self add:something beforeIndex:1 |
|
602 |
! |
|
603 |
||
457 | 604 |
remove:something |
605 |
"remove a child or collection of children |
|
606 |
" |
|
858 | 607 |
self each:something do:[:aChild| self removeChild:aChild ]. |
457 | 608 |
^ something |
609 |
! |
|
610 |
||
611 |
removeAll |
|
612 |
"remove all children |
|
613 |
" |
|
614 |
self childrenDo:[:aChild| aChild parent:nil ]. |
|
469 | 615 |
self children removeAll. |
858 | 616 |
! |
617 |
||
618 |
removeChild:aChild |
|
619 |
"remove a aChild |
|
620 |
" |
|
621 |
|item| |
|
622 |
||
623 |
(item := self children remove:aChild ifAbsent:nil) notNil ifTrue:[ |
|
624 |
item parent:nil |
|
625 |
]. |
|
626 |
^ item |
|
627 |
! |
|
628 |
||
629 |
removeIndex:anIndex |
|
630 |
"remove child at index |
|
631 |
" |
|
632 |
^ self removeChild:(self childAt:anIndex) |
|
457 | 633 |
! ! |
634 |
||
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
635 |
!TreeItem methodsFor:'change & update'! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
636 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
637 |
changed |
786 | 638 |
"node changed; raise notification to model |
639 |
" |
|
640 |
self changed:#value |
|
784 | 641 |
! |
642 |
||
786 | 643 |
changed:what |
644 |
"node changed; raise notification to model |
|
645 |
" |
|
646 |
|model| |
|
784 | 647 |
|
795 | 648 |
what == #value |
982
d94684e7fe9f
sending #changed to a tree item should not invoke retrieving children
tz
parents:
909
diff
changeset
|
649 |
ifTrue: [self retrieveLabel] |
5557 | 650 |
ifFalse: [ |
651 |
what == #children ifTrue: [ |
|
652 |
self retrieveChildren |
|
653 |
] |
|
654 |
]. |
|
786 | 655 |
|
656 |
(model := self model) notNil ifTrue:[ |
|
795 | 657 |
model update:what with:nil from:self |
786 | 658 |
] |
5557 | 659 |
|
660 |
"Modified (format): / 21-07-2017 / 09:14:30 / cg" |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
661 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
662 |
|
2038 | 663 |
changedSelected |
664 |
"called if the node is selected |
|
665 |
" |
|
666 |
! |
|
667 |
||
786 | 668 |
update:something with:aParameter from:anItem |
669 |
"raise change notification to my model |
|
670 |
" |
|
671 |
|m| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
672 |
|
786 | 673 |
(m := self model) notNil ifTrue:[ |
674 |
m update:something with:aParameter from:anItem |
|
675 |
] |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
676 |
! ! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
677 |
|
506 | 678 |
!TreeItem methodsFor:'converting'! |
679 |
||
680 |
fromLiteralArrayEncoding:aLiteralEncodedArray |
|
786 | 681 |
"read my contents from a aLiteralEncodedArray. |
682 |
" |
|
506 | 683 |
|narg| |
684 |
||
685 |
( (aLiteralEncodedArray size > 0) |
|
686 |
and:[(name := aLiteralEncodedArray at:1) isString]) ifFalse:[ |
|
687 |
^ nil |
|
688 |
]. |
|
689 |
narg := aLiteralEncodedArray at:2 ifAbsent:nil. |
|
690 |
||
691 |
name isSymbol ifTrue:[ |
|
692 |
(narg isArray and:[aLiteralEncodedArray size == 2]) ifTrue:[ |
|
693 |
^ self fromLiteralArrayEncoding:narg |
|
694 |
]. |
|
695 |
^ nil |
|
696 |
]. |
|
697 |
||
698 |
narg isArray ifFalse:[ |
|
699 |
contents := narg. |
|
700 |
narg := aLiteralEncodedArray at:3 ifAbsent:nil. |
|
701 |
]. |
|
702 |
||
703 |
narg isArray ifTrue:[ |
|
704 |
children := OrderedCollection new. |
|
705 |
||
706 |
narg do:[:aSubArray||aChild| |
|
707 |
children add:(aChild := TreeItem new). |
|
708 |
aChild fromLiteralArrayEncoding:aSubArray. |
|
709 |
aChild parent:self. |
|
710 |
] |
|
711 |
] |
|
712 |
||
713 |
||
714 |
||
715 |
! |
|
716 |
||
717 |
literalArrayEncoding |
|
786 | 718 |
"return myself encoded as a literal array |
719 |
" |
|
5635 | 720 |
|array children size noChld| |
506 | 721 |
|
722 |
contents isString ifTrue:[size := 2] |
|
723 |
ifFalse:[size := 1]. |
|
724 |
||
786 | 725 |
noChld := self numberOfChildren. |
726 |
||
727 |
noChld == 0 ifTrue:[ |
|
506 | 728 |
array := Array new:size |
729 |
] ifFalse:[ |
|
786 | 730 |
array := Array new:size + 1. |
5635 | 731 |
children := Array new:noChld. |
732 |
array at:(size + 1) put:children. |
|
506 | 733 |
|
734 |
self children keysAndValuesDo:[:i :aChild| |
|
5635 | 735 |
children at:i put:(aChild literalArrayEncoding) |
506 | 736 |
] |
737 |
]. |
|
738 |
array at:1 put:(name ? ''). |
|
739 |
||
740 |
contents isString ifTrue:[ |
|
741 |
array at:2 put:contents |
|
742 |
]. |
|
743 |
parent isNil ifTrue:[ |
|
744 |
array := Array with:#TreeItem with:array. |
|
745 |
]. |
|
746 |
^ array |
|
747 |
! ! |
|
748 |
||
2102 | 749 |
!TreeItem methodsFor:'copying'! |
457 | 750 |
|
751 |
copy |
|
2102 | 752 |
|node newContents| |
457 | 753 |
|
754 |
node := self species new. |
|
755 |
||
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
756 |
contents ~~ UnknownContents ifTrue:[ |
2102 | 757 |
newContents := contents copy. |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
758 |
] ifFalse:[ |
2102 | 759 |
newContents := UnknownContents |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
760 |
]. |
2102 | 761 |
node name:name copy. |
762 |
node contents:newContents. |
|
469 | 763 |
node children:(self children collect:[:c| c copy]). |
786 | 764 |
node readChildren:readChildren. |
2102 | 765 |
^ node |
457 | 766 |
! ! |
767 |
||
768 |
!TreeItem methodsFor:'enumerating'! |
|
769 |
||
770 |
allChildrenDo:aOneArgBlock |
|
5628 | 771 |
"recursively enumerate children |
772 |
and evaluate a block on each child and subchildren" |
|
773 |
||
469 | 774 |
self children do:[:aChild| |
457 | 775 |
aOneArgBlock value:aChild. |
776 |
aChild allChildrenDo:aOneArgBlock |
|
777 |
] |
|
5628 | 778 |
|
779 |
"Modified (comment): / 20-10-2017 / 11:26:36 / cg" |
|
457 | 780 |
! |
781 |
||
782 |
allWithParentAndChildrenDo:aTwoArgBlock |
|
783 |
self childrenDo:[:aChild| |
|
784 |
aTwoArgBlock value:self value:aChild. |
|
785 |
aChild allWithParentAndChildrenDo:aTwoArgBlock |
|
786 |
] |
|
787 |
! |
|
788 |
||
789 |
childrenDo:aOneArgBlock |
|
5628 | 790 |
"evaluate a block on each child (excluding sub-children)" |
791 |
||
837 | 792 |
self children do:aOneArgBlock |
5628 | 793 |
|
794 |
"Modified (comment): / 20-10-2017 / 11:27:02 / cg" |
|
457 | 795 |
! |
796 |
||
1241 | 797 |
detectParent:aBlock |
5628 | 798 |
"evaluate aBlock for my parent-chain; |
799 |
return the parent for which it returns true" |
|
1241 | 800 |
|
801 |
|p| |
|
802 |
||
803 |
p := parent. |
|
804 |
[p notNil] whileTrue:[ |
|
805 |
(aBlock value:p) ifTrue:[^ p]. |
|
806 |
p := p parent |
|
807 |
]. |
|
808 |
^ nil |
|
809 |
||
5628 | 810 |
"Modified (comment): / 20-10-2017 / 11:27:09 / cg" |
1241 | 811 |
! |
812 |
||
5627 | 813 |
each:itemOrCollectionOfItems do:aOneArgBlock |
457 | 814 |
"evaluate a block for something or in case of a collection for each |
5628 | 815 |
element in the collection" |
816 |
||
5627 | 817 |
itemOrCollectionOfItems notNil ifTrue:[ |
818 |
itemOrCollectionOfItems isCollection ifTrue:[ |
|
819 |
itemOrCollectionOfItems do:aOneArgBlock |
|
820 |
] ifFalse:[ |
|
821 |
aOneArgBlock value:itemOrCollectionOfItems |
|
822 |
] |
|
457 | 823 |
] |
824 |
||
5628 | 825 |
"Modified (comment): / 20-10-2017 / 11:27:16 / cg" |
457 | 826 |
! ! |
827 |
||
2501 | 828 |
!TreeItem methodsFor:'initialization & release'! |
457 | 829 |
|
830 |
initialize |
|
831 |
"setup defaults |
|
832 |
" |
|
506 | 833 |
super initialize. |
834 |
||
457 | 835 |
children := OrderedCollection new. |
5572 | 836 |
"/ readChildren is actually: "MUSTreadChildren" - bad naming |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
837 |
readChildren := hide := true. |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
838 |
contents := UnknownContents. |
5572 | 839 |
|
840 |
"Modified (comment): / 04-08-2017 / 14:15:31 / cg" |
|
457 | 841 |
! ! |
842 |
||
1825 | 843 |
!TreeItem methodsFor:'printing & storing'! |
1172 | 844 |
|
845 |
asString |
|
3361
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
846 |
"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
|
847 |
|
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
848 |
^ self name |
1172 | 849 |
! |
850 |
||
4140
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
851 |
displayOn:aGCOrStream |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
852 |
"Compatibility |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
853 |
append a printed desription on some stream (Dolphin, Squeak) |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
854 |
OR: |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
855 |
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
|
856 |
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
|
857 |
(although the fallBack is to display its printString ...)" |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
858 |
|
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
859 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
5495 | 860 |
"/ old ST80 means: draw-yourself on a GC. |
4140
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
861 |
aGCOrStream isStream ifFalse:[ |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
862 |
^ super displayOn:aGCOrStream. |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
863 |
]. |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
864 |
|
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
865 |
aGCOrStream |
6079 | 866 |
nextPutAll:self className; |
4140
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
867 |
nextPut:$(. |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
868 |
self printOn:aGCOrStream. |
267c46c27c2a
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
3907
diff
changeset
|
869 |
aGCOrStream nextPut:$) |
5495 | 870 |
|
871 |
"Modified (comment): / 22-02-2017 / 16:48:13 / cg" |
|
6079 | 872 |
"Modified: / 28-06-2019 / 09:22:22 / Claus Gittinger" |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
873 |
! |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
874 |
|
3361
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
875 |
printOn:aStream |
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
876 |
"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
|
877 |
|
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
878 |
aStream nextPutAll:self name |
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
879 |
! |
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
880 |
|
1172 | 881 |
printString |
3361
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
882 |
"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
|
883 |
|
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
884 |
^ self name |
1172 | 885 |
! |
886 |
||
887 |
printableEditValue |
|
3361
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
888 |
"returns the printable edit value or nil" |
5b0ba50df077
Define #printOn: for each method defining #printString
Stefan Vogel <sv@exept.de>
parents:
3123
diff
changeset
|
889 |
|
1172 | 890 |
^ nil |
891 |
! ! |
|
892 |
||
457 | 893 |
!TreeItem methodsFor:'queries'! |
894 |
||
1172 | 895 |
canEdit |
896 |
"returns true if field is editable |
|
897 |
" |
|
898 |
^ false |
|
899 |
! |
|
900 |
||
457 | 901 |
hasChildren |
786 | 902 |
"returns true if any child exists |
457 | 903 |
" |
786 | 904 |
^ self children notEmpty |
457 | 905 |
! |
906 |
||
834 | 907 |
hasChildrenWithSubChildren |
2930 | 908 |
"returns true if any child exists and has children too" |
834 | 909 |
|
2930 | 910 |
self children contains:[:aChild| aChild hasChildren] |
834 | 911 |
! |
912 |
||
913 |
hasExpandedChildren |
|
914 |
"returns true if any of my children is expanded |
|
915 |
" |
|
3123
8912a9a3bc01
code cleanup: use #contains instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
2930
diff
changeset
|
916 |
^ children contains:[:aChild | aChild hidden not]. |
8912a9a3bc01
code cleanup: use #contains instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
2930
diff
changeset
|
917 |
|
8912a9a3bc01
code cleanup: use #contains instead of explicit loop
Claus Gittinger <cg@exept.de>
parents:
2930
diff
changeset
|
918 |
"Modified: / 13-10-2006 / 13:00:05 / cg" |
834 | 919 |
! |
920 |
||
457 | 921 |
hidden |
786 | 922 |
"returns true if node is not visible |
923 |
" |
|
457 | 924 |
^ hide |
925 |
! |
|
926 |
||
927 |
isCollapsable |
|
928 |
"is collabsable; children existing and shown |
|
929 |
" |
|
469 | 930 |
^ (self hasChildren and:[hide == false]) |
457 | 931 |
! |
932 |
||
569 | 933 |
isContainedByParent:aParent |
934 |
"returns true if contained in subtree of a parent |
|
935 |
" |
|
936 |
|p| |
|
937 |
||
938 |
p := parent. |
|
939 |
||
940 |
[p notNil] whileTrue:[ |
|
941 |
p == aParent ifTrue:[^ true ]. |
|
942 |
p := p parent |
|
943 |
]. |
|
944 |
^ false |
|
945 |
! |
|
946 |
||
457 | 947 |
isExpandable |
948 |
"is expandable; children existing and hidden |
|
949 |
" |
|
469 | 950 |
^ (self hasChildren and:[hide == true]) |
457 | 951 |
|
952 |
! |
|
953 |
||
1205 | 954 |
isExpanded |
955 |
"return true if I am expanded" |
|
956 |
^ hide not |
|
957 |
||
958 |
! |
|
959 |
||
472 | 960 |
numberOfChildren |
786 | 961 |
"returns number of children |
962 |
" |
|
472 | 963 |
^ self children size |
964 |
! |
|
965 |
||
841 | 966 |
showIndicator |
967 |
"returns true if children exists |
|
968 |
" |
|
969 |
^ self hasChildren |
|
970 |
! |
|
971 |
||
972 |
shown |
|
973 |
"returns true if node is visible |
|
974 |
" |
|
975 |
^ hide not |
|
976 |
! ! |
|
977 |
||
978 |
!TreeItem methodsFor:'recomputation'! |
|
979 |
||
858 | 980 |
addVisibleChildrenTo:aList |
981 |
"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
|
982 |
" |
838 | 983 |
|item |
984 |
size "{ Class: SmallInteger }" |
|
985 |
idx "{ Class: SmallInteger }" |
|
986 |
| |
|
987 |
||
457 | 988 |
hide ifFalse:[ |
5572 | 989 |
"/ readChildren is actually: "MUSTreadChildren" - bad naming |
841 | 990 |
readChildren ifTrue:[ |
991 |
self children |
|
992 |
]. |
|
849 | 993 |
(size := children size) ~~ 0 ifTrue:[ |
838 | 994 |
idx := 1. |
995 |
size timesRepeat:[ |
|
996 |
aList add:(item := children at:idx). |
|
858 | 997 |
item addVisibleChildrenTo:aList. |
838 | 998 |
idx := idx + 1. |
999 |
] |
|
457 | 1000 |
] |
1001 |
] |
|
841 | 1002 |
|
5572 | 1003 |
"Modified (format): / 04-08-2017 / 14:15:42 / cg" |
858 | 1004 |
! |
1005 |
||
1006 |
numberOfAllVisibleChildren |
|
1007 |
"returns number of all visible children including all the children of children |
|
1008 |
" |
|
1009 |
|total "{ Class: SmallInteger }"| |
|
1010 |
||
1011 |
hide ifTrue:[ |
|
1012 |
^ 0 |
|
1013 |
]. |
|
5572 | 1014 |
"/ readChildren is actually: "MUSTreadChildren" - bad naming |
858 | 1015 |
readChildren ifTrue:[ self children ]. |
1016 |
||
1017 |
(total := children size) ~~ 0 ifTrue:[ |
|
1018 |
children do:[:aChild| total := total + aChild numberOfAllVisibleChildren ]. |
|
1019 |
]. |
|
1020 |
^ total |
|
1021 |
||
5572 | 1022 |
"Modified (comment): / 04-08-2017 / 14:15:49 / cg" |
457 | 1023 |
! ! |
1024 |
||
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1025 |
!TreeItem methodsFor:'retrieving'! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1026 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1027 |
childrenAction |
786 | 1028 |
"get children action block |
1029 |
" |
|
1030 |
|m| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1031 |
|
786 | 1032 |
^ (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
|
1033 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1034 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1035 |
contentsAction |
786 | 1036 |
"get contents action block |
1037 |
" |
|
1038 |
|m| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1039 |
|
786 | 1040 |
^ (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
|
1041 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1042 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1043 |
iconAction |
786 | 1044 |
"get icon action block |
1045 |
" |
|
1046 |
|m| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1047 |
|
786 | 1048 |
^ (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
|
1049 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1050 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1051 |
labelAction |
3699 | 1052 |
"get label action block " |
1053 |
||
786 | 1054 |
|m| |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1055 |
|
786 | 1056 |
^ (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
|
1057 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1058 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1059 |
retrieveAll |
786 | 1060 |
"retrieve all values from model |
1061 |
" |
|
784 | 1062 |
self "retrieveContents;" retrieveLabel; retrieveChildren |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1063 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1064 |
|
5450 | 1065 |
retrieveAndEvaluate: selectorToReturnABlockOrValueHolder |
1066 |
"retrieve a specific value from the model; |
|
1067 |
if no model exists, nil is returned. |
|
1068 |
||
1069 |
The model mist return a block or valueHolder, |
|
1070 |
which is evaluate with self as optopal argument. |
|
1071 |
So the model can compute icons, labels, etc. dynamically. |
|
1072 |
||
1073 |
Typical selectors are: |
|
1074 |
#iconAction |
|
1075 |
#childrenAction |
|
1076 |
#contentsAction |
|
1077 |
#labelAction |
|
786 | 1078 |
" |
5450 | 1079 |
|
2071
7c58c73eff49
use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents:
2038
diff
changeset
|
1080 |
|arg model| |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1081 |
|
786 | 1082 |
(model := self model) isNil ifTrue:[ |
1083 |
^ nil |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1084 |
]. |
5450 | 1085 |
arg := model perform:selectorToReturnABlockOrValueHolder. |
786 | 1086 |
|
1087 |
arg isBlock ifFalse:[ |
|
1088 |
^ arg value |
|
1089 |
]. |
|
5450 | 1090 |
^ arg valueWithOptionalArgument:self |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1091 |
|
5450 | 1092 |
"Modified (comment): / 04-02-2017 / 19:30:44 / cg" |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1093 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1094 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1095 |
retrieveChildren |
786 | 1096 |
"retrieve children from model |
1097 |
" |
|
1098 |
|retChildren cls| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1099 |
|
786 | 1100 |
retChildren := self retrieveAndEvaluate:#childrenAction. |
1101 |
||
1102 |
retChildren notNil ifTrue:[ |
|
1103 |
retChildren isCollection ifFalse: [retChildren := OrderedCollection with:retChildren]. |
|
1104 |
cls := self class. |
|
1105 |
||
5576 | 1106 |
self children: |
1107 |
(retChildren collect: |
|
1108 |
[:obj | |
|
1109 |
(obj isKindOf:cls) |
|
1110 |
ifTrue:[obj] |
|
1111 |
ifFalse:[cls new contents:obj] |
|
1112 |
]). |
|
5572 | 1113 |
"/ readChildren is actually: "MUSTreadChildren" - bad naming |
768
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
1114 |
readChildren := false. |
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
1115 |
]. |
5fa51db3bdb5
set read children flag to false only if retrieving succeeded
tz
parents:
766
diff
changeset
|
1116 |
|
786 | 1117 |
^ children |
5572 | 1118 |
|
5576 | 1119 |
"Modified (format): / 16-08-2017 / 17:18:58 / cg" |
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1120 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1121 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1122 |
retrieveContents |
786 | 1123 |
"retrieve contents value from model; |
1124 |
" |
|
1125 |
|cont| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1126 |
|
786 | 1127 |
(cont := self retrieveAndEvaluate: #contentsAction) isNil ifTrue:[ |
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
1128 |
contents == UnknownContents ifTrue:[ |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
1129 |
cont := '' |
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
1130 |
] |
786 | 1131 |
]. |
1132 |
^ contents := cont |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1133 |
! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1134 |
|
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1135 |
retrieveLabel |
786 | 1136 |
"retrieve label from model |
1137 |
" |
|
1138 |
|n| |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1139 |
|
786 | 1140 |
(n := self retrieveAndEvaluate:#labelAction) isNil ifTrue:[ |
1141 |
n := name ? '' |
|
1142 |
]. |
|
1143 |
^ name := n |
|
761
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1144 |
! ! |
d0cf8f76f1b6
supports dynamic read behavior for contents, label, children, and icon
tz
parents:
569
diff
changeset
|
1145 |
|
479 | 1146 |
!TreeItem methodsFor:'searching'! |
1147 |
||
1172 | 1148 |
childAt:anIndex |
1551 | 1149 |
"get child at an index or nil" |
1150 |
||
1151 |
^ self children at:anIndex ifAbsent:nil |
|
1172 | 1152 |
! |
1153 |
||
479 | 1154 |
detectChild:aOneArgBlock |
1551 | 1155 |
"evaluate the block on each child; |
1156 |
returns the child's node or nil. |
|
5233 | 1157 |
This searches my direct children only - not walking down sublevels. |
479 | 1158 |
" |
1551 | 1159 |
|
479 | 1160 |
^ self children detect:aOneArgBlock ifNone:nil |
1161 |
! |
|
1162 |
||
849 | 1163 |
detectChild:aTwoArgBlock arguments:args |
1164 |
"detect a child the evaluation of the block returns true. The |
|
1165 |
first argument to the block is the item, the second argument |
|
1551 | 1166 |
the value derived from the argument list at node-level ... |
1167 |
I.e. for each sublevel, a different block arg can be specified. |
|
1168 |
The number of arguments also defines the search level. |
|
1552 | 1169 |
i.e. if you pass (1 to:10) as args, the block will get the sub-level |
1170 |
as second argument and stop the search after 10 levels. |
|
849 | 1171 |
" |
1551 | 1172 |
|
849 | 1173 |
^ self detectChild:aTwoArgBlock arguments:args index:1 |
1174 |
! |
|
1175 |
||
1551 | 1176 |
detectFirstChild:anOneArgBlock |
1177 |
"detect the first child which evaluation of anOneArgBlock returns true. |
|
1178 |
Recursively walks down the node-tree. |
|
1179 |
" |
|
1180 |
|node children| |
|
1181 |
||
1182 |
(anOneArgBlock value:self) ifTrue:[ |
|
1183 |
^ self. |
|
1184 |
]. |
|
1185 |
(children := self children) notEmpty ifTrue:[ |
|
1186 |
children do:[:aChild | |
|
1187 |
(node := aChild detectFirstChild:anOneArgBlock) notNil ifTrue:[ |
|
1188 |
^ node |
|
1189 |
] |
|
1190 |
] |
|
1191 |
]. |
|
1192 |
^ nil |
|
1193 |
! |
|
1194 |
||
1195 |
indexOfChild:aChild |
|
1196 |
"get index of a child or 0 |
|
1197 |
" |
|
1198 |
^ aChild notNil ifTrue:[self children identityIndexOf:aChild] |
|
1199 |
ifFalse:[0] |
|
1200 |
! ! |
|
1201 |
||
2498 | 1202 |
!TreeItem methodsFor:'searching-private'! |
1551 | 1203 |
|
849 | 1204 |
detectChild:aTwoArgBlock arguments:args index:idxArgs |
1552 | 1205 |
"helper for limited search. |
1206 |
detect a child the evaluation of the block returns true. The |
|
849 | 1207 |
first argument to the block is the item, the second argument |
1551 | 1208 |
the value derived from the argument list at an index. |
1209 |
This one recursively walks down the tree searching for a node. |
|
849 | 1210 |
" |
1211 |
|num node| |
|
1212 |
||
1213 |
(num := args size) >= idxArgs ifTrue:[ |
|
1214 |
(aTwoArgBlock value:self value:(args at:idxArgs)) ifFalse:[ |
|
1215 |
^ nil |
|
1216 |
]. |
|
1217 |
||
1218 |
idxArgs == num ifTrue:[ |
|
1219 |
^ self |
|
1220 |
]. |
|
1221 |
||
1222 |
self children notEmpty ifTrue:[ |
|
1223 |
num := idxArgs + 1. |
|
1224 |
||
1225 |
children do:[:aChild| |
|
1226 |
node := aChild detectChild:aTwoArgBlock arguments:args index:num. |
|
1227 |
||
1228 |
node notNil ifTrue:[ |
|
1229 |
^ node |
|
1230 |
] |
|
1231 |
] |
|
1232 |
] |
|
1233 |
]. |
|
1234 |
^ nil |
|
479 | 1235 |
! ! |
1236 |
||
457 | 1237 |
!TreeItem class methodsFor:'documentation'! |
1238 |
||
1239 |
version |
|
5233 | 1240 |
^ '$Header$' |
3907
860a141af427
changed: #newAsTreeFromSmalltalkClass:
Claus Gittinger <cg@exept.de>
parents:
3699
diff
changeset
|
1241 |
! |
860a141af427
changed: #newAsTreeFromSmalltalkClass:
Claus Gittinger <cg@exept.de>
parents:
3699
diff
changeset
|
1242 |
|
860a141af427
changed: #newAsTreeFromSmalltalkClass:
Claus Gittinger <cg@exept.de>
parents:
3699
diff
changeset
|
1243 |
version_CVS |
5233 | 1244 |
^ '$Header$' |
457 | 1245 |
! ! |
2404 | 1246 |
|
5233 | 1247 |
|
1196
8f9a3c273eff
use UnknownContents special object instead of nil.
Claus Gittinger <cg@exept.de>
parents:
1172
diff
changeset
|
1248 |
TreeItem initialize! |