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