author | Claus Gittinger <cg@exept.de> |
Tue, 12 Feb 2019 19:01:33 +0100 | |
changeset 5996 | e89a322b31da |
parent 5994 | d209971809a4 |
child 5998 | bb38ed2e191a |
permissions | -rw-r--r-- |
5991 | 1 |
"{ Encoding: utf8 }" |
2 |
||
4733 | 3 |
" |
4 |
COPYRIGHT (c) 1999/2015 by eXept Software AG |
|
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 |
" |
|
14 |
"{ Package: 'stx:libwidg2' }" |
|
15 |
||
16 |
"{ NameSpace: Smalltalk }" |
|
17 |
||
18 |
Object subclass:#AbstractHierarchicalItem |
|
19 |
instanceVariableNames:'parent children' |
|
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'Views-Support' |
|
23 |
! |
|
24 |
||
25 |
!AbstractHierarchicalItem class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1999/2015 by eXept Software AG |
|
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 |
documentation |
|
42 |
" |
|
43 |
Hierarchical Items are mostly like Models, but the list of |
|
44 |
dependencies are kept by its HierarchicalList. |
|
45 |
The class is used to build up hierarchical trees. |
|
46 |
||
47 |
2015 update: |
|
48 |
the original HierarchicalItem has been refactored into this abstract class, |
|
49 |
which provides all the mechanisms, but leaves the concrete representation |
|
50 |
of some slots open. |
|
51 |
These are: |
|
52 |
- if and how the geometry information (width + height) are cached, |
|
53 |
- if and how the expanded-state is remembered. |
|
54 |
- if and how the underlying model is fetched |
|
55 |
||
56 |
The old class used private slots for the first three (width-height-isExpanded), |
|
57 |
but did not keep a reference to the model. This leads to a very poor performance, |
|
58 |
as many algorithms degenerated to O(n log(n)) or even O(n^2) time behavior, |
|
59 |
as the model was fetched by walking along the parent chain - sometimes for every item |
|
60 |
in a long list. |
|
61 |
||
62 |
The old class is still around and may be used for small trees, |
|
63 |
but we recommend rewriting applications to use the new CompactHierarchicalItem |
|
64 |
class, which behaves the same on the outside, but uses clever tricks to be both more |
|
65 |
space efficient (saving 2 slots) and time efficient (caching the model). |
|
4749
13a7e6db823b
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4746
diff
changeset
|
66 |
For this, make sure that the subclass does not access the instvars isExpanded, width and height |
13a7e6db823b
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4746
diff
changeset
|
67 |
directly, but uses the getters isExpanded, width and height and the setters setExpanded:, width: and height: |
4733 | 68 |
|
69 |
[Instance variables:] |
|
70 |
parent <Item, List or nil> parent or my HierarchicalList. |
|
71 |
children <Collection or nil> list of children |
|
72 |
||
73 |
[author:] |
|
5740 | 74 |
Claus Atzkern |
4733 | 75 |
Claus Gittinger (redesign and refactoring) |
76 |
||
77 |
[see also:] |
|
78 |
HierarchicalItem (the old item class) |
|
79 |
HierarchicalList (typical model) |
|
80 |
HierarchicalListView (typical user of me) |
|
81 |
" |
|
82 |
! ! |
|
83 |
||
84 |
!AbstractHierarchicalItem class methodsFor:'instance creation'! |
|
85 |
||
86 |
new |
|
87 |
^ (self basicNew) initialize |
|
88 |
! |
|
89 |
||
90 |
parent:aParent |
|
91 |
|item| |
|
92 |
||
93 |
item := self new. |
|
94 |
item parent:aParent. |
|
95 |
^ item |
|
96 |
! ! |
|
97 |
||
98 |
!AbstractHierarchicalItem class methodsFor:'protocol'! |
|
99 |
||
100 |
doResetExtentOnChange |
|
101 |
"true: the extent of the item is reset if a change |
|
102 |
notification is raised from the item. the default is true |
|
103 |
" |
|
104 |
^ true |
|
105 |
! ! |
|
106 |
||
5461 | 107 |
!AbstractHierarchicalItem class methodsFor:'queries'! |
108 |
||
109 |
isAbstract |
|
110 |
"Return if this class is an abstract class. |
|
111 |
True is returned here for myself only; false for subclasses. |
|
112 |
Abstract subclasses must redefine this again." |
|
113 |
||
114 |
^ self == AbstractHierarchicalItem. |
|
115 |
! ! |
|
116 |
||
4733 | 117 |
!AbstractHierarchicalItem methodsFor:'accessing'! |
118 |
||
119 |
getChildren |
|
5996 | 120 |
"returns the children as they are present (or not); |
121 |
not going to the model, and especially not creating autocreated children..." |
|
4733 | 122 |
|
123 |
^ children |
|
5996 | 124 |
|
125 |
"Modified (comment): / 12-02-2019 / 17:41:06 / Claus Gittinger" |
|
4733 | 126 |
! |
127 |
||
128 |
level |
|
129 |
"returns the level starting with 0 for the root" |
|
130 |
||
131 |
|item level| |
|
132 |
||
133 |
item := self. |
|
134 |
level := 0. |
|
135 |
||
136 |
[ (item := item parentOrModel) notNil] whileTrue:[ |
|
137 |
level := level + 1. |
|
5739 | 138 |
level > 10000 ifTrue:[ |
139 |
self halt:'possibly recursive item hierarchy'. |
|
140 |
^ self. |
|
4733 | 141 |
]. |
142 |
]. |
|
143 |
^ level |
|
144 |
||
145 |
"Modified: / 09-07-2010 / 08:56:27 / cg" |
|
146 |
! |
|
147 |
||
148 |
parent |
|
149 |
"returns the parent or nil" |
|
150 |
||
5865 | 151 |
|p| |
5870 | 152 |
|
153 |
p := parent. |
|
154 |
^ (p notNil and:[p isHierarchicalItem]) |
|
5865 | 155 |
ifTrue:[p] |
4733 | 156 |
ifFalse:[nil] |
5865 | 157 |
|
5870 | 158 |
"Modified: / 01-08-2018 / 10:18:37 / Claus Gittinger" |
159 |
"Modified: / 01-08-2018 / 16:15:07 / Stefan Vogel" |
|
4733 | 160 |
! |
161 |
||
162 |
parent:aParent |
|
163 |
"set the parent (or the model if the item is the root item)" |
|
164 |
||
165 |
parent := aParent |
|
166 |
! |
|
167 |
||
168 |
rootItem |
|
169 |
"returns the root item" |
|
170 |
||
171 |
parent isHierarchicalItem ifTrue:[ |
|
172 |
^ parent rootItem |
|
173 |
]. |
|
174 |
^ self |
|
175 |
! ! |
|
176 |
||
177 |
!AbstractHierarchicalItem methodsFor:'accessing-children'! |
|
178 |
||
179 |
at:anIndex |
|
180 |
"return the child at anIndex if valid; |
|
181 |
if the index is invalid, nil is returned" |
|
182 |
||
183 |
^ self at:anIndex ifAbsent:nil |
|
184 |
! |
|
185 |
||
186 |
at:anIndex ifAbsent:exceptionBlock |
|
187 |
"return the child at anIndex if valid; if the index is |
|
188 |
invalid, the result of evaluating the exceptionBlock is returned." |
|
189 |
||
190 |
|list| |
|
191 |
||
192 |
(list := self children) notNil ifTrue:[ |
|
193 |
^ list at:anIndex ifAbsent:exceptionBlock |
|
194 |
]. |
|
195 |
^ exceptionBlock value |
|
196 |
! |
|
197 |
||
198 |
at:anIndex put:anItem |
|
199 |
"replace a child by a new item. return anItem (sigh)" |
|
200 |
||
201 |
|children oldItem visIndex model expFlag| |
|
202 |
||
203 |
anItem isNil ifTrue:[ |
|
204 |
self removeFromIndex:anIndex toIndex:anIndex. |
|
205 |
^ nil |
|
206 |
]. |
|
207 |
anItem parent:self. |
|
208 |
||
209 |
(model := self model) isNil ifTrue:[ |
|
210 |
self children at:anIndex put:anItem. |
|
211 |
^ anItem |
|
212 |
]. |
|
213 |
||
5840 | 214 |
model synchronized:[ |
4733 | 215 |
children := self children. |
216 |
oldItem := children at:anIndex. |
|
217 |
||
218 |
oldItem isExpanded ifTrue:[ |
|
219 |
oldItem collapse |
|
220 |
]. |
|
221 |
visIndex := model identityIndexOf:oldItem. |
|
222 |
expFlag := anItem isExpanded. |
|
223 |
anItem setExpanded:false. |
|
224 |
||
225 |
children at:anIndex put:anItem. |
|
226 |
||
227 |
visIndex ~~ 0 ifTrue:[ |
|
228 |
model at:visIndex put:anItem. |
|
229 |
]. |
|
230 |
self changed:#redraw. |
|
231 |
expFlag ifTrue:[ anItem expand ]. |
|
232 |
]. |
|
233 |
^ anItem |
|
5840 | 234 |
|
235 |
"Modified: / 28-07-2018 / 15:51:06 / Claus Gittinger" |
|
4733 | 236 |
! |
237 |
||
238 |
children:aListOfChildren |
|
239 |
"set a new list of children" |
|
240 |
||
5840 | 241 |
self synchronized:[ |
4733 | 242 |
self removeAll. |
5994 | 243 |
self addAll:aListOfChildren beforeIndex:1. |
4733 | 244 |
]. |
245 |
^ aListOfChildren |
|
5840 | 246 |
|
5994 | 247 |
"Modified: / 06-02-2019 / 15:59:15 / Claus Gittinger" |
4733 | 248 |
! |
249 |
||
250 |
first |
|
251 |
"returns the first child |
|
252 |
" |
|
253 |
^ self at:1 |
|
254 |
! |
|
255 |
||
256 |
last |
|
257 |
"returns the last child" |
|
258 |
||
259 |
^ self at:(self size) |
|
260 |
! |
|
261 |
||
262 |
second |
|
263 |
"returns the second child" |
|
264 |
||
265 |
^ self at:2 |
|
266 |
! ! |
|
267 |
||
268 |
!AbstractHierarchicalItem methodsFor:'accessing-hierarchy'! |
|
269 |
||
270 |
collapse |
|
271 |
"hide all my subitems" |
|
272 |
||
273 |
self canCollapse ifTrue:[ |
|
5840 | 274 |
self synchronized:[ |
5996 | 275 |
|overAllNrOfVisibleChildren nrOfVisibleChildren index| |
276 |
||
277 |
overAllNrOfVisibleChildren := self numberOfVisibleChildren. |
|
278 |
||
279 |
self setExpanded:false. |
|
280 |
||
4733 | 281 |
(index := self listIndex) notNil ifTrue:[ |
5996 | 282 |
"/ do not call self size or self children, |
283 |
"/ as this might autocreate children !!!! |
|
284 |
(nrOfVisibleChildren := children size) ~~ 0 ifTrue:[ |
|
285 |
children do:[:el| |
|
286 |
nrOfVisibleChildren := nrOfVisibleChildren + el numberOfVisibleChildren |
|
4733 | 287 |
]. |
5996 | 288 |
self assert:(nrOfVisibleChildren = overAllNrOfVisibleChildren). |
289 |
self model itemRemoveFromIndex:(index + 1) toIndex:(index + nrOfVisibleChildren). |
|
4733 | 290 |
]. |
291 |
index ~~ 0 ifTrue:[self hierarchyChanged]. |
|
292 |
] |
|
293 |
] |
|
294 |
] |
|
5840 | 295 |
|
5996 | 296 |
"Modified: / 12-02-2019 / 18:53:55 / Claus Gittinger" |
4733 | 297 |
! |
298 |
||
299 |
enforcedExpand |
|
300 |
"expand children - even if there are no children, |
|
301 |
the item is initially expanded (but this might be undone later, |
|
302 |
when we know that no children are there" |
|
303 |
||
304 |
self expand:true |
|
305 |
! |
|
306 |
||
307 |
expand |
|
308 |
"expand children - but only if there are children |
|
309 |
(i.e. this cannot be used before the childInfo is valid; |
|
310 |
aka not before the updateTask came along this item)" |
|
311 |
||
312 |
self expand:false |
|
313 |
! |
|
314 |
||
315 |
expand:enforced |
|
316 |
"expand children" |
|
317 |
||
318 |
"/ test whether the item already is expanded; #canExpand could be redefined |
|
319 |
"/ without checking whether the node is expanded (happens already) !! |
|
320 |
||
321 |
self isExpanded ifTrue:[ ^ self ]. |
|
322 |
(enforced not and:[self canExpand not]) ifTrue:[ ^ self ]. |
|
323 |
||
5840 | 324 |
self synchronized:[ |
5720 | 325 |
|index list| |
326 |
||
4733 | 327 |
(index := self listIndex) notNil ifTrue:[ |
328 |
"/ must set expand-flag to false, otherwise change notifications |
|
329 |
"/ are raised during lazy auto creation (to the list). |
|
330 |
self setExpanded:false. |
|
331 |
list := self children. |
|
332 |
list notEmptyOrNil ifTrue:[ |
|
5720 | 333 |
self setExpanded:true. |
4733 | 334 |
list := OrderedCollection new. |
335 |
self addVisibleChildrenTo:list. |
|
336 |
self model itemAddAll:list beforeIndex:(index + 1). |
|
337 |
]. |
|
338 |
index ~~ 0 ifTrue:[self hierarchyChanged]. |
|
339 |
] ifFalse:[ |
|
340 |
self setExpanded:true |
|
341 |
] |
|
342 |
]. |
|
5720 | 343 |
|
344 |
"Modified: / 08-03-2018 / 21:06:13 / stefan" |
|
5840 | 345 |
"Modified: / 28-07-2018 / 15:47:47 / Claus Gittinger" |
4733 | 346 |
! |
347 |
||
5728 | 348 |
expandLevels:numLevels |
349 |
"expand children numLevels down" |
|
350 |
||
351 |
numLevels == 0 ifTrue:[^ self]. |
|
352 |
self children do:[:each | |
|
353 |
each expand. |
|
354 |
each expandLevels:(numLevels - 1). |
|
355 |
]. |
|
356 |
! |
|
357 |
||
358 |
expandLevels:numLevels max:maxNumExpandedHolder |
|
359 |
"expand children numLevels down" |
|
360 |
||
361 |
numLevels == 0 ifTrue:[^ self]. |
|
362 |
maxNumExpandedHolder value <= 0 ifTrue:[^ self]. |
|
363 |
||
364 |
self children do:[:each | |
|
365 |
each expand. |
|
366 |
]. |
|
367 |
||
368 |
maxNumExpandedHolder value:(maxNumExpandedHolder value - self children size). |
|
369 |
self children do:[:each | |
|
370 |
each expandLevels:(numLevels - 1) max:maxNumExpandedHolder. |
|
371 |
]. |
|
372 |
! |
|
373 |
||
5992 | 374 |
expandWithoutUpdate |
375 |
"in case expand is redefined to do any update |
|
376 |
(as in guiBrowser's applicationTreeItem), |
|
377 |
this can be used to expand without updating" |
|
378 |
||
379 |
self expand |
|
380 |
||
381 |
"Created: / 02-02-2019 / 19:59:55 / Claus Gittinger" |
|
382 |
"Modified (comment): / 03-02-2019 / 01:28:33 / Claus Gittinger" |
|
383 |
! |
|
384 |
||
5623 | 385 |
labelPath |
386 |
"return my label-path as an ordered collection of individual labels" |
|
387 |
||
388 |
^ ({self} , self allParents) reverse collect:#label |
|
389 |
||
390 |
"Created: / 16-10-2017 / 13:09:10 / cg" |
|
391 |
"Modified: / 16-10-2017 / 14:16:46 / cg" |
|
392 |
! |
|
393 |
||
4733 | 394 |
makeVisible |
395 |
"expand all my parents" |
|
396 |
||
397 |
(parent notNil and:[parent isHierarchicalItem]) ifTrue:[ |
|
5840 | 398 |
self synchronized:[ |
4733 | 399 |
parent makeVisible. |
400 |
parent expand. |
|
401 |
] |
|
402 |
]. |
|
5840 | 403 |
|
404 |
"Modified: / 28-07-2018 / 15:47:52 / Claus Gittinger" |
|
4733 | 405 |
! |
406 |
||
407 |
recursiveCollapse |
|
408 |
"collapse all item and sub items |
|
409 |
**** must be expanded |
|
410 |
" |
|
5840 | 411 |
self synchronized:[ |
5996 | 412 |
|nrOfVisibleChildren index| |
5840 | 413 |
|
414 |
self canCollapse ifTrue:[ |
|
4733 | 415 |
(index := self listIndex) notNil ifTrue:[ |
5996 | 416 |
"/ do not call self size or self children here; |
417 |
"/ otherwise, lazy children would be autocreated !!!! |
|
418 |
(nrOfVisibleChildren := children size) ~~ 0 ifTrue:[ |
|
419 |
children do:[:el| |
|
420 |
nrOfVisibleChildren := nrOfVisibleChildren + el numberOfVisibleChildren |
|
4733 | 421 |
]. |
422 |
]. |
|
5996 | 423 |
self recursiveSetCollapsedHelper. |
424 |
||
425 |
nrOfVisibleChildren ~~ 0 ifTrue:[ |
|
426 |
self model itemRemoveFromIndex:(index + 1) toIndex:(index + nrOfVisibleChildren) |
|
4733 | 427 |
]. |
428 |
index ~~ 0 ifTrue:[ |
|
429 |
self hierarchyChanged |
|
430 |
] |
|
431 |
] ifFalse:[ |
|
5996 | 432 |
self recursiveSetCollapsedHelper |
4733 | 433 |
] |
434 |
] |
|
435 |
] |
|
5840 | 436 |
|
5996 | 437 |
"Modified: / 12-02-2019 / 18:54:26 / Claus Gittinger" |
4733 | 438 |
! |
439 |
||
440 |
recursiveExpand |
|
441 |
"expand children and sub-children |
|
5870 | 442 |
Precondition: must be collapsed" |
443 |
||
5996 | 444 |
|index todo toExpand myList childrenOfToExpand| |
4733 | 445 |
|
5840 | 446 |
self synchronized:[ |
5996 | 447 |
myList := self model. |
448 |
todo := OrderedCollection with:self. |
|
449 |
[todo notEmpty] whileTrue:[ |
|
450 |
toExpand := todo removeFirst. |
|
451 |
||
452 |
"/ test whether the item already is expanded; #canExpand could be redefined |
|
453 |
"/ without checking whether the node is expanded (happens actually) !! |
|
454 |
(toExpand isExpanded or:[toExpand canExpand]) ifTrue:[ |
|
455 |
toExpand setExpanded:true. |
|
456 |
childrenOfToExpand := toExpand children. |
|
457 |
||
458 |
index := toExpand listIndex. "/ get the visible list index |
|
459 |
index isNil ifTrue:[ |
|
460 |
"/ not visible |
|
461 |
childrenOfToExpand do:[:eachChild | |
|
462 |
(eachChild isExpanded not and:[eachChild canExpand]) ifTrue:[ |
|
463 |
eachChild setExpanded:true |
|
464 |
]. |
|
465 |
]. |
|
466 |
] ifFalse:[ |
|
467 |
"/ visible |
|
468 |
myList itemAddAll:childrenOfToExpand afterIndex:index. |
|
469 |
childrenOfToExpand do:[:eachChild | |
|
470 |
(eachChild isExpanded or:[eachChild canExpand]) ifTrue:[ |
|
471 |
todo add:eachChild. |
|
472 |
]. |
|
473 |
]. |
|
4733 | 474 |
]. |
475 |
] |
|
476 |
] |
|
477 |
]. |
|
5840 | 478 |
|
5870 | 479 |
"Modified (comment): / 02-08-2018 / 16:16:17 / Stefan Vogel" |
5996 | 480 |
"Modified: / 12-02-2019 / 18:39:49 / Claus Gittinger" |
4733 | 481 |
! |
482 |
||
483 |
recursiveToggleExpand |
|
484 |
"if the item is collapsed, the item and all its sub-items |
|
485 |
are expanded otherwise collapsed" |
|
486 |
||
487 |
self isExpanded ifTrue:[ |
|
488 |
self recursiveCollapse |
|
489 |
] ifFalse:[ |
|
490 |
self recursiveExpand |
|
491 |
] |
|
492 |
! |
|
493 |
||
494 |
toggleExpand |
|
495 |
"if the item is collapsed, the item is expanded otherwise collapsed" |
|
496 |
||
497 |
self isExpanded ifTrue:[ |
|
498 |
self collapse |
|
499 |
] ifFalse:[ |
|
500 |
self expand |
|
501 |
]. |
|
502 |
! ! |
|
503 |
||
504 |
!AbstractHierarchicalItem methodsFor:'accessing-mvc'! |
|
505 |
||
506 |
application |
|
507 |
"returns the responsible application or nil" |
|
508 |
||
509 |
|model| |
|
510 |
||
511 |
(model := self model) notNil ifTrue:[ |
|
512 |
^ model application |
|
513 |
]. |
|
514 |
^ nil |
|
515 |
! |
|
516 |
||
517 |
applicationsDo:aOneArgBlock |
|
518 |
"evaluate the block for each dependent application" |
|
519 |
||
520 |
|model| |
|
521 |
||
522 |
(model := self model) notNil ifTrue:[ |
|
523 |
model applicationsDo:aOneArgBlock |
|
524 |
] |
|
525 |
! |
|
526 |
||
5840 | 527 |
fetchModel |
4733 | 528 |
"returns the hierachicalList model or nil. |
529 |
This is a stupid implementation here, in that the top-item's parent is assumed to |
|
530 |
be the model of the tree, and that is returned. |
|
531 |
This saves a slot in every node, but makes some algorithms O(n*log n) or even O(n^2). |
|
532 |
So be aware of the performance penalty" |
|
533 |
||
534 |
|item next| |
|
535 |
||
536 |
item := self. |
|
537 |
[ (next := item parentOrModel) notNil ] whileTrue:[ |
|
538 |
item := next. |
|
539 |
]. |
|
540 |
||
541 |
item isHierarchicalItem ifFalse:[^ item]. |
|
542 |
^ nil |
|
5840 | 543 |
! |
544 |
||
545 |
model |
|
546 |
"returns the hierachicalList model or nil. |
|
547 |
This uses fetchModel, which has a stupid implementation here, |
|
548 |
in that the top-item's parent is assumed to be the model of the tree, and that is returned. |
|
549 |
This saves a slot in every node, but makes some algorithms O(n*log n) or even O(n^2). |
|
550 |
So be aware of the performance penalty or redefined fetchModel" |
|
551 |
||
552 |
^ self fetchModel |
|
553 |
||
554 |
"Modified (comment): / 28-07-2018 / 13:30:24 / Claus Gittinger" |
|
4733 | 555 |
! ! |
556 |
||
557 |
!AbstractHierarchicalItem methodsFor:'adding & removing'! |
|
558 |
||
559 |
add:aChildItem |
|
560 |
"add a child at end" |
|
561 |
||
5857 | 562 |
^ self synchronized:[ |
5840 | 563 |
self add:aChildItem beforeIndex:(self children size + 1). |
564 |
]. |
|
565 |
||
566 |
"Modified: / 28-07-2018 / 13:35:08 / Claus Gittinger" |
|
5857 | 567 |
"Modified: / 29-07-2018 / 20:23:01 / Stefan Vogel" |
4733 | 568 |
! |
569 |
||
570 |
add:aChildItem after:aChild |
|
571 |
"add an item after an existing item" |
|
572 |
||
5857 | 573 |
^ self synchronized:[ |
574 |
|index| |
|
575 |
||
5840 | 576 |
index := self identityIndexOf:aChild. |
577 |
index == 0 ifTrue:[ self subscriptBoundsError:index ]. |
|
578 |
||
579 |
self add:aChildItem beforeIndex:(index + 1). |
|
580 |
]. |
|
581 |
||
582 |
"Modified: / 28-07-2018 / 13:35:18 / Claus Gittinger" |
|
5857 | 583 |
"Modified: / 29-07-2018 / 20:23:26 / Stefan Vogel" |
4733 | 584 |
! |
585 |
||
586 |
add:aChildItem afterIndex:anIndex |
|
587 |
"add an item after an index" |
|
588 |
||
5857 | 589 |
^ self add:aChildItem beforeIndex:(anIndex + 1). |
5840 | 590 |
|
591 |
"Modified: / 28-07-2018 / 13:37:32 / Claus Gittinger" |
|
5857 | 592 |
"Modified: / 29-07-2018 / 20:23:39 / Stefan Vogel" |
4733 | 593 |
! |
594 |
||
595 |
add:aChildItem before:aChild |
|
596 |
"add an item before an existing item" |
|
597 |
||
5857 | 598 |
^ self synchronized:[ |
5840 | 599 |
|index| |
600 |
||
601 |
index := self identityIndexOf:aChild. |
|
602 |
index == 0 ifTrue:[ self subscriptBoundsError:index ]. |
|
603 |
||
604 |
self add:aChildItem beforeIndex:index. |
|
605 |
]. |
|
606 |
||
607 |
"Modified: / 28-07-2018 / 13:35:47 / Claus Gittinger" |
|
5857 | 608 |
"Modified: / 29-07-2018 / 20:22:28 / Stefan Vogel" |
4733 | 609 |
! |
610 |
||
611 |
add:aChildItem beforeIndex:anIndex |
|
612 |
"add an item before an index" |
|
613 |
||
614 |
aChildItem notNil ifTrue:[ |
|
615 |
self addAll:(Array with:aChildItem) beforeIndex:anIndex |
|
616 |
]. |
|
5857 | 617 |
^ aChildItem. |
5840 | 618 |
|
619 |
"Modified: / 28-07-2018 / 13:35:01 / Claus Gittinger" |
|
5857 | 620 |
"Modified: / 29-07-2018 / 20:24:07 / Stefan Vogel" |
4733 | 621 |
! |
622 |
||
623 |
add:aChild sortBlock:aBlock |
|
624 |
"add a child sorted" |
|
625 |
||
5857 | 626 |
^ self synchronized:[ |
4733 | 627 |
self basicAdd:aChild sortBlock:aBlock |
628 |
]. |
|
5840 | 629 |
|
630 |
"Modified: / 28-07-2018 / 13:37:12 / Claus Gittinger" |
|
5857 | 631 |
"Modified: / 29-07-2018 / 20:24:31 / Stefan Vogel" |
4733 | 632 |
! |
633 |
||
634 |
addAll:aList |
|
635 |
"add children at the end" |
|
636 |
||
5857 | 637 |
^ self synchronized:[ |
5840 | 638 |
self addAll:aList beforeIndex:(self children size + 1) |
639 |
] |
|
640 |
||
641 |
"Modified: / 28-07-2018 / 13:37:25 / Claus Gittinger" |
|
5857 | 642 |
"Modified: / 29-07-2018 / 20:25:09 / Stefan Vogel" |
4733 | 643 |
! |
644 |
||
645 |
addAll:aList before:aChild |
|
646 |
"add an item before an existing item" |
|
647 |
||
5857 | 648 |
^ self synchronized:[ |
5840 | 649 |
|index| |
650 |
||
651 |
index := self identityIndexOf:aChild. |
|
652 |
index == 0 ifTrue:[ self subscriptBoundsError:index ]. |
|
653 |
||
654 |
self addAll:aList beforeIndex:index |
|
655 |
]. |
|
656 |
||
657 |
"Modified: / 28-07-2018 / 13:37:53 / Claus Gittinger" |
|
5857 | 658 |
"Modified: / 29-07-2018 / 20:25:18 / Stefan Vogel" |
4733 | 659 |
! |
660 |
||
661 |
addAll:aList beforeIndex:anIndex |
|
662 |
"add children before an index" |
|
663 |
||
5857 | 664 |
aList notEmptyOrNil ifTrue:[ |
5840 | 665 |
self synchronized:[ |
4733 | 666 |
self basicAddAll:aList beforeIndex:anIndex |
667 |
] |
|
668 |
]. |
|
669 |
^ aList |
|
5840 | 670 |
|
671 |
"Modified: / 28-07-2018 / 13:38:02 / Claus Gittinger" |
|
5857 | 672 |
"Modified: / 29-07-2018 / 20:25:38 / Stefan Vogel" |
4733 | 673 |
! |
674 |
||
675 |
addAll:aList sortBlock:aBlock |
|
676 |
"add children sorted" |
|
677 |
||
5857 | 678 |
aList notEmptyOrNil ifTrue:[ ^ aList ]. |
4733 | 679 |
|
680 |
aBlock isNil ifTrue:[ |
|
681 |
self addAll:aList. |
|
682 |
] ifFalse:[ |
|
5840 | 683 |
self synchronized:[ |
4733 | 684 |
aList do:[:el| self basicAdd:el sortBlock:aBlock ] |
685 |
] |
|
686 |
]. |
|
5857 | 687 |
^ aList |
5840 | 688 |
|
689 |
"Modified: / 28-07-2018 / 13:38:14 / Claus Gittinger" |
|
5857 | 690 |
"Modified: / 29-07-2018 / 20:26:24 / Stefan Vogel" |
4733 | 691 |
! |
692 |
||
693 |
addAllFirst:aCollectionOfItems |
|
694 |
"add children at the beginning" |
|
695 |
||
5857 | 696 |
^ self addAll:aCollectionOfItems beforeIndex:1 |
5840 | 697 |
|
698 |
"Modified: / 28-07-2018 / 13:38:24 / Claus Gittinger" |
|
5857 | 699 |
"Modified: / 29-07-2018 / 20:26:47 / Stefan Vogel" |
4733 | 700 |
! |
701 |
||
702 |
addAllLast:aCollectionOfItems |
|
703 |
"add children at the end" |
|
704 |
||
5857 | 705 |
^ self addAll:aCollectionOfItems |
5840 | 706 |
|
707 |
"Modified: / 28-07-2018 / 13:38:32 / Claus Gittinger" |
|
5857 | 708 |
"Modified: / 29-07-2018 / 20:26:55 / Stefan Vogel" |
4733 | 709 |
! |
710 |
||
711 |
addFirst:aChildItem |
|
712 |
"add a child at the beginning" |
|
713 |
||
5857 | 714 |
^ self add:aChildItem beforeIndex:1. |
5840 | 715 |
|
716 |
"Modified: / 28-07-2018 / 13:38:47 / Claus Gittinger" |
|
5857 | 717 |
"Modified: / 29-07-2018 / 20:27:01 / Stefan Vogel" |
4733 | 718 |
! |
719 |
||
720 |
addLast:anItem |
|
721 |
"add a child at the end" |
|
722 |
||
5857 | 723 |
^ self add:anItem |
5840 | 724 |
|
725 |
"Modified: / 28-07-2018 / 13:38:52 / Claus Gittinger" |
|
5857 | 726 |
"Modified: / 29-07-2018 / 20:27:09 / Stefan Vogel" |
4733 | 727 |
! |
728 |
||
729 |
remove |
|
730 |
"remove the item" |
|
731 |
||
732 |
parent notNil ifTrue:[ "check whether parent exists" |
|
733 |
parent isHierarchicalItem ifTrue:[parent remove:self] "parent is HierarchicalItem" |
|
734 |
ifFalse:[parent root:nil] "parent is HierarchicalList" |
|
735 |
]. |
|
5857 | 736 |
|
737 |
"Modified: / 29-07-2018 / 20:31:18 / Stefan Vogel" |
|
4733 | 738 |
! |
739 |
||
740 |
remove:aChild |
|
741 |
"remove a child" |
|
742 |
||
5840 | 743 |
self synchronized:[ |
744 |
self removeIndex:(self identityIndexOf:aChild) |
|
745 |
]. |
|
746 |
||
747 |
"Modified: / 28-07-2018 / 13:39:47 / Claus Gittinger" |
|
5857 | 748 |
"Modified: / 29-07-2018 / 20:40:47 / Stefan Vogel" |
4733 | 749 |
! |
750 |
||
751 |
removeAll |
|
5840 | 752 |
"remove all children. |
753 |
Returns the receiver." |
|
754 |
||
755 |
self synchronized:[ |
|
756 |
|size| |
|
757 |
||
758 |
(size := children size) ~~ 0 ifTrue:[ |
|
759 |
self removeFromIndex:1 toIndex:size |
|
760 |
] |
|
4733 | 761 |
] |
5840 | 762 |
|
763 |
"Modified (comment): / 28-07-2018 / 13:44:24 / Claus Gittinger" |
|
4733 | 764 |
! |
765 |
||
766 |
removeAll:aList |
|
5840 | 767 |
"remove all children in the collection. |
768 |
Returns the receiver." |
|
4733 | 769 |
|
770 |
aList size ~~ 0 ifTrue:[ |
|
5840 | 771 |
self synchronized:[ |
4733 | 772 |
aList do:[:el| |
5840 | 773 |
|index| |
774 |
||
4733 | 775 |
(index := self identityIndexOf:el) ~~ 0 ifTrue:[ |
776 |
self removeIndex:index |
|
777 |
] |
|
778 |
] |
|
779 |
] |
|
780 |
]. |
|
5840 | 781 |
|
782 |
"Modified (format): / 28-07-2018 / 13:44:51 / Claus Gittinger" |
|
5857 | 783 |
"Modified: / 29-07-2018 / 20:39:01 / Stefan Vogel" |
4733 | 784 |
! |
785 |
||
786 |
removeAllIdentical:aList |
|
787 |
"remove all children in the collection" |
|
788 |
||
5840 | 789 |
^ self removeAll:aList. |
4733 | 790 |
|
791 |
"Created: / 20-09-2010 / 09:43:06 / sr" |
|
5840 | 792 |
"Modified: / 28-07-2018 / 13:41:48 / Claus Gittinger" |
4733 | 793 |
! |
794 |
||
795 |
removeFromIndex:startIndex |
|
5840 | 796 |
"remove the children from startIndex up to end of children. |
797 |
Returns the receiver." |
|
798 |
||
799 |
self synchronized:[ |
|
800 |
self removeFromIndex:startIndex toIndex:(children size) |
|
801 |
]. |
|
802 |
||
803 |
"Modified: / 28-07-2018 / 13:44:07 / Claus Gittinger" |
|
4733 | 804 |
! |
805 |
||
806 |
removeFromIndex:startIndex toIndex:stopIndex |
|
807 |
"remove the children from startIndex up to and including |
|
808 |
the child under stopIndex. |
|
809 |
Returns the receiver." |
|
810 |
||
5840 | 811 |
self synchronized:[ |
5870 | 812 |
|nrOfChildren| |
5840 | 813 |
|
814 |
nrOfChildren := children size. |
|
815 |
||
816 |
(startIndex <= stopIndex and:[startIndex <= nrOfChildren]) ifTrue:[ |
|
5870 | 817 |
self basicRemoveFromIndex:startIndex toIndex:(stopIndex min:nrOfChildren) |
5840 | 818 |
]. |
5870 | 819 |
(children isEmptyOrNil and:[self clearExpandedWhenLastChildWasRemoved]) ifTrue:[ |
820 |
self setExpanded:false. |
|
5840 | 821 |
]. |
4733 | 822 |
]. |
823 |
||
5840 | 824 |
"Modified: / 28-07-2018 / 13:45:07 / Claus Gittinger" |
5870 | 825 |
"Modified: / 02-08-2018 / 15:51:19 / Stefan Vogel" |
4733 | 826 |
! |
827 |
||
828 |
removeIndex:anIndex |
|
829 |
"remove the child at an index" |
|
830 |
||
831 |
anIndex > 0 ifTrue:[ |
|
832 |
self removeFromIndex:anIndex toIndex:anIndex |
|
833 |
] |
|
834 |
! ! |
|
835 |
||
836 |
!AbstractHierarchicalItem methodsFor:'basic adding & removing'! |
|
837 |
||
5870 | 838 |
basicAdd:aChild sortBlock:aBlockOrNil |
5840 | 839 |
"add a child sorted. |
840 |
Not synchronized - should only be called internally |
|
841 |
within a synchronized region." |
|
4733 | 842 |
|
843 |
|size list| |
|
844 |
||
845 |
size := children size. |
|
846 |
list := Array with:aChild. |
|
847 |
||
5870 | 848 |
(aBlockOrNil notNil and:[size ~~ 0]) ifTrue:[ |
4733 | 849 |
children keysAndValuesDo:[:i :el| |
5870 | 850 |
(aBlockOrNil value:aChild value:el) ifTrue:[ |
4733 | 851 |
self basicAddAll:list beforeIndex:i. |
852 |
^ aChild |
|
853 |
] |
|
854 |
] |
|
855 |
]. |
|
5870 | 856 |
|
857 |
"insert at the end" |
|
4733 | 858 |
self basicAddAll:list beforeIndex:(size + 1). |
859 |
^ aChild. |
|
5840 | 860 |
|
861 |
"Modified (comment): / 28-07-2018 / 13:46:12 / Claus Gittinger" |
|
5870 | 862 |
"Modified (comment): / 01-08-2018 / 16:07:16 / Stefan Vogel" |
4733 | 863 |
! |
864 |
||
865 |
basicAddAll:aList beforeIndex:anIndex |
|
5840 | 866 |
"add children before an index. |
867 |
Not synchronized - should only be called internally |
|
868 |
within a synchronized region." |
|
4733 | 869 |
|
5994 | 870 |
|coll model notify index oldSize| |
871 |
||
872 |
oldSize := children size. |
|
4733 | 873 |
|
874 |
anIndex == 1 ifTrue:[ |
|
875 |
notify := self |
|
876 |
] ifFalse:[ |
|
5994 | 877 |
anIndex > oldSize ifTrue:[ |
878 |
anIndex > (1 + oldSize) ifTrue:[ |
|
4733 | 879 |
^ self subscriptBoundsError:index |
880 |
]. |
|
5994 | 881 |
notify := self at:oldSize |
4733 | 882 |
] ifFalse:[ |
883 |
notify := nil |
|
884 |
] |
|
885 |
]. |
|
5870 | 886 |
|
887 |
aList do:[:eachItem| eachItem parent:self ]. |
|
888 |
||
5994 | 889 |
oldSize == 0 ifTrue:[ |
5993 | 890 |
self setChildren:(OrderedCollection withAll:aList). |
4795
eead012852f9
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4758
diff
changeset
|
891 |
] ifFalse:[ |
5870 | 892 |
children isArray ifTrue:[ |
5993 | 893 |
self setChildren:(children asOrderedCollection) |
4795
eead012852f9
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4758
diff
changeset
|
894 |
]. |
5870 | 895 |
children addAll:aList beforeIndex:anIndex. |
4733 | 896 |
]. |
5993 | 897 |
|
4733 | 898 |
(model := self model) isNil ifTrue:[ |
899 |
^ aList |
|
900 |
]. |
|
901 |
||
902 |
self isExpanded ifFalse:[ |
|
903 |
notify notNil ifTrue:[ |
|
904 |
notify changed |
|
905 |
]. |
|
906 |
^ aList |
|
907 |
]. |
|
908 |
(index := self listIndex) isNil ifTrue:[ |
|
909 |
^ aList |
|
910 |
]. |
|
911 |
||
912 |
children from:1 to:(anIndex - 1) do:[:anItem| |
|
913 |
index := 1 + index + anItem numberOfVisibleChildren |
|
914 |
]. |
|
5857 | 915 |
|
4733 | 916 |
coll := OrderedCollection new. |
917 |
aList do:[:anItem| |
|
918 |
coll add:anItem. |
|
919 |
anItem addVisibleChildrenTo:coll. |
|
920 |
]. |
|
921 |
model itemAddAll:coll beforeIndex:(index + 1). |
|
922 |
||
923 |
notify notNil ifTrue:[ |
|
924 |
notify changed |
|
925 |
]. |
|
926 |
^ aList |
|
5840 | 927 |
|
5870 | 928 |
"Modified: / 01-08-2018 / 15:31:54 / Stefan Vogel" |
929 |
"Modified (format): / 02-08-2018 / 15:52:16 / Stefan Vogel" |
|
5993 | 930 |
"Modified: / 03-02-2019 / 19:32:25 / Claus Gittinger" |
5994 | 931 |
"Modified (format): / 06-02-2019 / 15:58:41 / Claus Gittinger" |
4733 | 932 |
! |
933 |
||
934 |
basicRemoveFromIndex:startIndex toIndex:stopIndex |
|
935 |
"remove the children from startIndex up to and including |
|
5840 | 936 |
the child under stopIndex. |
937 |
Not synchronized - should only be called internally |
|
938 |
within a synchronized region." |
|
4733 | 939 |
|
940 |
|model notify |
|
941 |
index "{ Class:SmallInteger }" |
|
942 |
start "{ Class:SmallInteger }" |
|
943 |
stop "{ Class:SmallInteger }" |
|
944 |
size "{ Class:SmallInteger }" |
|
945 |
| |
|
946 |
size := self children size. |
|
947 |
stop := stopIndex. |
|
948 |
start := startIndex. |
|
949 |
||
950 |
(stop <= size and:[start between:1 and:stop]) ifFalse:[ |
|
951 |
^ self subscriptBoundsError:index |
|
952 |
]. |
|
953 |
start == 1 ifTrue:[ |
|
954 |
notify := self |
|
955 |
] ifFalse:[ |
|
956 |
stop == size ifTrue:[ |
|
957 |
notify := self at:(start - 1) |
|
958 |
] ifFalse:[ |
|
959 |
notify := nil |
|
960 |
] |
|
961 |
]. |
|
962 |
||
963 |
(model := self model) notNil ifTrue:[ |
|
964 |
index := model identityIndexOf:(children at:start). |
|
965 |
size := stop - start + 1. |
|
966 |
] ifFalse:[ |
|
967 |
index := 0 |
|
968 |
]. |
|
969 |
||
970 |
children from:start to:stop do:[:aChild| |
|
971 |
index ~~ 0 ifTrue:[ |
|
972 |
size := size + aChild numberOfVisibleChildren |
|
973 |
]. |
|
974 |
aChild parent:nil |
|
975 |
]. |
|
976 |
children removeFromIndex:start toIndex:stop. |
|
977 |
||
978 |
index ~~ 0 ifTrue:[ |
|
979 |
model itemRemoveFromIndex:index toIndex:(index + size - 1) |
|
980 |
]. |
|
981 |
notify notNil ifTrue:[ |
|
982 |
notify changed |
|
983 |
]. |
|
5840 | 984 |
|
985 |
"Modified (format): / 28-07-2018 / 13:46:41 / Claus Gittinger" |
|
4733 | 986 |
! ! |
987 |
||
988 |
!AbstractHierarchicalItem methodsFor:'change & update'! |
|
989 |
||
990 |
changed:what with:anArgument |
|
991 |
"the item changed; raise change notification |
|
992 |
#icon icon is modified; height and width are unchanged |
|
993 |
#hierarchy collapsed/expanded; height and width are unchanged |
|
994 |
#redraw redraw but height and width are unchanged |
|
995 |
....... all others: the height and width are reset |
|
996 |
" |
|
5886 | 997 |
|
4733 | 998 |
|model| |
999 |
||
5860 | 1000 |
(what ~~ #redraw |
1001 |
and:[what ~~ #hierarchy |
|
1002 |
and:[what ~~ #icon |
|
1003 |
and:[self class doResetExtentOnChange]]]) ifTrue:[ |
|
1004 |
self makeWidthAndHeightUnknown |
|
1005 |
]. |
|
1006 |
||
5886 | 1007 |
(model := self model) notNil ifTrue:[ |
1008 |
self synchronized:[ |
|
5860 | 1009 |
model itemChanged:what with:anArgument from:self. |
4733 | 1010 |
]. |
1011 |
]. |
|
1012 |
super changed:what with:anArgument |
|
1013 |
||
1014 |
"Modified: / 24-11-2010 / 17:21:20 / cg" |
|
5861 | 1015 |
"Modified: / 30-07-2018 / 15:58:18 / Stefan Vogel" |
5886 | 1016 |
"Modified (format): / 15-08-2018 / 12:37:03 / Claus Gittinger" |
4733 | 1017 |
! |
1018 |
||
1019 |
childrenOrderChanged |
|
1020 |
"called if the order of the children changed by a user |
|
1021 |
operation. Update the model and raise a change notification for |
|
1022 |
each item which has changed its position |
|
1023 |
triggered by the user operation !!" |
|
1024 |
||
1025 |
|model visStart list| |
|
1026 |
||
1027 |
self isExpanded ifFalse:[ ^ self ]. "/ not expanded |
|
1028 |
children size > 1 ifFalse:[ ^ self ]. |
|
1029 |
||
1030 |
model := self model. |
|
1031 |
model isNil ifTrue:[^ self]. "/ no model |
|
1032 |
||
1033 |
visStart := model identityIndexOf:self. |
|
1034 |
visStart == 0 ifTrue:[ |
|
1035 |
model root ~~ self ifTrue:[ ^ self ]. |
|
5840 | 1036 |
"/ I'am the root but switched of by setting #showRoot to false |
4733 | 1037 |
]. |
1038 |
||
5840 | 1039 |
self synchronized:[ |
4733 | 1040 |
list := OrderedCollection new. |
1041 |
self addVisibleChildrenTo:list. |
|
1042 |
||
1043 |
list do:[:el| |
|
1044 |
visStart := visStart + 1. |
|
1045 |
||
1046 |
(model at:visStart ifAbsent:el) ~~ el ifTrue:[ |
|
1047 |
model at:visStart put:el |
|
1048 |
]. |
|
1049 |
] |
|
1050 |
]. |
|
5840 | 1051 |
|
1052 |
"Modified (format): / 28-07-2018 / 13:47:27 / Claus Gittinger" |
|
4733 | 1053 |
! |
1054 |
||
1055 |
fontChanged |
|
1056 |
"called if the font has changed. |
|
1057 |
Clear the precomputed width and height" |
|
1058 |
||
1059 |
self makeWidthAndHeightUnknown. |
|
1060 |
||
5870 | 1061 |
children notNil ifTrue:[ |
4733 | 1062 |
children do:[:el| el fontChanged]. |
1063 |
]. |
|
5870 | 1064 |
|
1065 |
"Modified: / 02-08-2018 / 15:53:52 / Stefan Vogel" |
|
4733 | 1066 |
! |
1067 |
||
1068 |
hierarchyChanged |
|
1069 |
"hierarchy changed; optimize redrawing" |
|
1070 |
||
1071 |
self changed:#hierarchy with:nil |
|
1072 |
! |
|
1073 |
||
1074 |
iconChanged |
|
1075 |
"icon changed; optimize redrawing" |
|
1076 |
||
1077 |
self changed:#icon with:nil |
|
1078 |
! |
|
1079 |
||
5886 | 1080 |
invalidate |
1081 |
"force redrawing of me" |
|
1082 |
||
1083 |
self changed:#redraw with:nil |
|
1084 |
||
1085 |
"Created: / 15-08-2018 / 12:38:48 / Claus Gittinger" |
|
1086 |
! |
|
1087 |
||
4733 | 1088 |
labelChanged |
1089 |
"called if the label has changed. |
|
5887 | 1090 |
Clear the precomputed width and height, and invalidate" |
4733 | 1091 |
|
1092 |
self makeWidthAndHeightUnknown. |
|
5887 | 1093 |
self invalidate |
4733 | 1094 |
|
1095 |
"Created: / 17-01-2011 / 17:43:42 / cg" |
|
5887 | 1096 |
"Modified: / 15-08-2018 / 12:43:20 / Claus Gittinger" |
4733 | 1097 |
! ! |
1098 |
||
1099 |
!AbstractHierarchicalItem methodsFor:'enumerating'! |
|
1100 |
||
5623 | 1101 |
allExpandedItemsDo:aBlock |
1102 |
"recursively enumerate all expanded nodes |
|
1103 |
(depth first; parent before children)" |
|
1104 |
||
1105 |
self recursiveDo:[:each | |
|
1106 |
each isExpanded ifTrue:[ |
|
1107 |
aBlock value:each. |
|
1108 |
]. |
|
1109 |
]. |
|
1110 |
||
1111 |
"Created: / 16-10-2017 / 14:19:00 / cg" |
|
1112 |
! |
|
1113 |
||
4733 | 1114 |
collect:aBlock |
5363 | 1115 |
"for each child in the receiver (non recursive), evaluate the argument, aBlock |
4733 | 1116 |
and return a new collection with the results" |
1117 |
||
1118 |
|coll| |
|
1119 |
||
1120 |
coll := OrderedCollection new. |
|
1121 |
self do:[:el| coll add:(aBlock value:el) ]. |
|
1122 |
^ coll |
|
5363 | 1123 |
|
1124 |
"Modified (comment): / 25-11-2016 / 08:42:19 / cg" |
|
4733 | 1125 |
! |
1126 |
||
1127 |
contains:aBlock |
|
5363 | 1128 |
"evaluate aOneArgBlock for each of the receiver's children (non recursive). |
4733 | 1129 |
Return true and skip remaining elements, if aBlock ever returns true, |
1130 |
otherwise return false" |
|
1131 |
||
1132 |
self do:[:el | (aBlock value:el) ifTrue:[^ true] ]. |
|
1133 |
^ false |
|
5362 | 1134 |
|
5363 | 1135 |
"Modified (comment): / 25-11-2016 / 08:43:31 / cg" |
4733 | 1136 |
! |
1137 |
||
1138 |
do:aOneArgBlock |
|
5363 | 1139 |
"evaluate a block for each child (non recursive)" |
4733 | 1140 |
|
1141 |
self from:1 to:nil do:aOneArgBlock |
|
5363 | 1142 |
|
1143 |
"Modified (comment): / 25-11-2016 / 08:43:36 / cg" |
|
4733 | 1144 |
! |
1145 |
||
1146 |
from:startIndex do:aOneArgBlock |
|
1147 |
"evaluate a block on each child starting with the |
|
5362 | 1148 |
child at startIndex to the end." |
1149 |
||
4733 | 1150 |
self from:startIndex to:nil do:aOneArgBlock |
5362 | 1151 |
|
1152 |
"Modified (comment): / 25-11-2016 / 07:45:55 / cg" |
|
4733 | 1153 |
! |
1154 |
||
1155 |
from:startIndex reverseDo:aOneArgBlock |
|
5363 | 1156 |
"evaluate a block on each child (non recursive) starting at end to the startIndex" |
5362 | 1157 |
|
4733 | 1158 |
self from:startIndex to:nil reverseDo:aOneArgBlock |
5362 | 1159 |
|
5363 | 1160 |
"Modified (comment): / 25-11-2016 / 08:43:42 / cg" |
4733 | 1161 |
! |
1162 |
||
1163 |
from:startIndex to:endIndex do:aOneArgBlock |
|
5996 | 1164 |
"WARNING: may fetch lazy children |
1165 |
evaluate a block on each child (non recursive), |
|
5870 | 1166 |
starting with the child at startIndex to the endIndex (last index if nil). |
1167 |
Answer the value of the block executed on the last element." |
|
1168 |
||
1169 |
^ self synchronized:[ |
|
1170 |
self nonCriticalFrom:startIndex to:endIndex do:aOneArgBlock |
|
4733 | 1171 |
]. |
5363 | 1172 |
|
1173 |
"Modified (comment): / 25-11-2016 / 08:43:51 / cg" |
|
5840 | 1174 |
"Modified: / 28-07-2018 / 13:48:49 / Claus Gittinger" |
5870 | 1175 |
"Modified: / 02-08-2018 / 16:04:04 / Stefan Vogel" |
5996 | 1176 |
"Modified (comment): / 12-02-2019 / 18:49:58 / Claus Gittinger" |
4733 | 1177 |
! |
1178 |
||
1179 |
from:startIndex to:endIndex reverseDo:aOneArgBlock |
|
5996 | 1180 |
"WARNING: may fetch lazy children |
1181 |
evaluate a block on each child (non recursive), |
|
5363 | 1182 |
starting with the child at endIndex to the startIndex." |
4733 | 1183 |
|
5840 | 1184 |
self synchronized:[ |
1185 |
self size >= startIndex ifTrue:[ |
|
1186 |
self nonCriticalFrom:startIndex to:endIndex reverseDo:aOneArgBlock |
|
1187 |
]. |
|
4733 | 1188 |
]. |
5363 | 1189 |
|
1190 |
"Modified (comment): / 25-11-2016 / 08:43:58 / cg" |
|
5840 | 1191 |
"Modified: / 28-07-2018 / 13:49:17 / Claus Gittinger" |
5996 | 1192 |
"Modified (comment): / 12-02-2019 / 18:50:04 / Claus Gittinger" |
4733 | 1193 |
! |
1194 |
||
1195 |
keysAndValuesDo:aTwoArgBlock |
|
5363 | 1196 |
"evaluate the argument, aBlock for every child (non recursive), |
4733 | 1197 |
passing both index and element as arguments." |
1198 |
||
5840 | 1199 |
|key| |
4733 | 1200 |
|
1201 |
key := 1. |
|
1202 |
||
1203 |
self do:[:el| |
|
5840 | 1204 |
el value:key value:el. |
4733 | 1205 |
key := key + 1. |
1206 |
]. |
|
5363 | 1207 |
|
1208 |
"Modified (comment): / 25-11-2016 / 08:44:03 / cg" |
|
5840 | 1209 |
"Modified: / 28-07-2018 / 13:49:35 / Claus Gittinger" |
4733 | 1210 |
! |
1211 |
||
1212 |
keysAndValuesReverseDo:aTwoArgBlock |
|
5996 | 1213 |
"WARNING: may fetch lazy children |
1214 |
evaluate the argument, aBlock in reverse order for every child (non recursive), |
|
5362 | 1215 |
passing both index and element as arguments." |
4733 | 1216 |
|
5840 | 1217 |
self synchronized:[ |
1218 |
self size == 0 ifFalse:[ |
|
1219 |
self nonCriticalKeysAndValuesReverseDo:aTwoArgBlock |
|
1220 |
]. |
|
4733 | 1221 |
]. |
5362 | 1222 |
|
5363 | 1223 |
"Modified (comment): / 25-11-2016 / 08:44:06 / cg" |
5840 | 1224 |
"Modified: / 28-07-2018 / 13:50:14 / Claus Gittinger" |
5996 | 1225 |
"Modified (comment): / 12-02-2019 / 18:50:08 / Claus Gittinger" |
4733 | 1226 |
! |
1227 |
||
1228 |
recursiveCollect:aBlock |
|
1229 |
"for each child in the receiver, evaluate the argument, aBlock |
|
5363 | 1230 |
and return a new collection with the results. |
1231 |
Warning: this only enumerates already visible child elements |
|
1232 |
i.e. any collapsed items are not visited." |
|
4733 | 1233 |
|
1234 |
|coll| |
|
1235 |
||
1236 |
coll := OrderedCollection new. |
|
1237 |
self recursiveDo:[:el| coll add:(aBlock value:el) ]. |
|
1238 |
^ coll |
|
5363 | 1239 |
|
1240 |
"Modified (comment): / 25-11-2016 / 08:43:20 / cg" |
|
4733 | 1241 |
! |
1242 |
||
1243 |
recursiveDo:aOneArgBlock |
|
5996 | 1244 |
"WARNING: may fetch lazy children |
1245 |
evaluate a block on each item and all the sub-items. |
|
5363 | 1246 |
Warning: this only enumerates already visible child elements |
1247 |
i.e. any collapsed items are not visited." |
|
4733 | 1248 |
|
5840 | 1249 |
self do:[:aChild| "/ notice: do does it synchronized |
4733 | 1250 |
aOneArgBlock value:aChild. |
1251 |
aChild nonCriticalRecursiveDo:aOneArgBlock |
|
1252 |
]. |
|
5363 | 1253 |
|
1254 |
"Modified (comment): / 25-11-2016 / 08:43:04 / cg" |
|
5996 | 1255 |
"Modified (comment): / 12-02-2019 / 18:51:21 / Claus Gittinger" |
4733 | 1256 |
! |
1257 |
||
1258 |
recursiveReverseDo:aOneArgBlock |
|
5996 | 1259 |
"WARNING: may fetch lazy children |
1260 |
evaluate a block on each item and all the sub-items; |
|
5363 | 1261 |
proccesing children in reverse direction. |
1262 |
Warning: this only enumerates already visible child elements |
|
1263 |
i.e. any collapsed items are not visited." |
|
4733 | 1264 |
|
5840 | 1265 |
self reverseDo:[:aChild| "/ notice: reverseDo does it synchronized |
4733 | 1266 |
aChild nonCriticalRecursiveReverseDo:aOneArgBlock. |
1267 |
aOneArgBlock value:aChild. |
|
1268 |
]. |
|
5363 | 1269 |
|
1270 |
"Modified (comment): / 25-11-2016 / 08:43:09 / cg" |
|
5996 | 1271 |
"Modified (comment): / 12-02-2019 / 18:51:09 / Claus Gittinger" |
4733 | 1272 |
! |
1273 |
||
1274 |
recursiveSelect:aBlock |
|
5362 | 1275 |
"return a new collection with all children and subChildren from the receiver, |
5363 | 1276 |
for which the argument aBlock evaluates to true. |
1277 |
Warning: this only enumerates already visible child elements |
|
1278 |
i.e. any collapsed items are not visited." |
|
4733 | 1279 |
|
1280 |
|coll| |
|
1281 |
||
1282 |
coll := OrderedCollection new. |
|
1283 |
self recursiveDo:[:el| (aBlock value:el) ifTrue:[coll add:el] ]. |
|
1284 |
^ coll |
|
5362 | 1285 |
|
5363 | 1286 |
"Modified (comment): / 25-11-2016 / 08:43:12 / cg" |
4733 | 1287 |
! |
1288 |
||
1289 |
reverseDo:aOneArgBlock |
|
5363 | 1290 |
"evaluate a block on each child (non recursive) in reverse direction" |
4733 | 1291 |
|
1292 |
self from:1 reverseDo:aOneArgBlock |
|
5363 | 1293 |
|
1294 |
"Modified (comment): / 25-11-2016 / 08:44:12 / cg" |
|
4733 | 1295 |
! |
1296 |
||
1297 |
select:aBlock |
|
5363 | 1298 |
"return a new collection with all items from the receiver (non recursive), |
1299 |
for which the argument aBlock evaluates to true." |
|
4733 | 1300 |
|
1301 |
|coll| |
|
1302 |
||
1303 |
coll := OrderedCollection new. |
|
1304 |
self do:[:el| (aBlock value:el) ifTrue:[coll add:el] ]. |
|
1305 |
^ coll |
|
5363 | 1306 |
|
1307 |
"Modified (comment): / 25-11-2016 / 08:44:20 / cg" |
|
4733 | 1308 |
! |
1309 |
||
1310 |
withAllDo:aOneArgBlock |
|
5996 | 1311 |
"WARNING: may fetch lazy children |
1312 |
recursively evaluate aOneArgBlock on each item and subitem including self" |
|
4733 | 1313 |
|
1314 |
aOneArgBlock value:self. |
|
1315 |
||
5840 | 1316 |
self do:[:el| "/ do does it synchronized |
4733 | 1317 |
aOneArgBlock value:el. |
1318 |
el nonCriticalRecursiveDo:aOneArgBlock. |
|
1319 |
]. |
|
5363 | 1320 |
|
1321 |
"Modified (comment): / 25-11-2016 / 08:44:49 / cg" |
|
5996 | 1322 |
"Modified (comment): / 12-02-2019 / 18:50:40 / Claus Gittinger" |
4733 | 1323 |
! ! |
1324 |
||
1325 |
!AbstractHierarchicalItem methodsFor:'enumerating parents'! |
|
1326 |
||
5623 | 1327 |
allParents |
5925 | 1328 |
"return a collection of all parents (bottom to top, ie. in parent, grandparent, ... order)" |
5623 | 1329 |
|
1330 |
|parents| |
|
1331 |
||
1332 |
parents := OrderedCollection new. |
|
1333 |
self parentsDo:[:p | parents add:p]. |
|
1334 |
^ parents. |
|
1335 |
||
1336 |
"Created: / 16-10-2017 / 13:08:45 / cg" |
|
1337 |
! |
|
1338 |
||
4733 | 1339 |
parentsDetect:aBlock |
5925 | 1340 |
"find the first parent (bottom to top), for which evaluation of the block returns |
4733 | 1341 |
true; if none does so, report an error" |
1342 |
||
1343 |
^ self parentsDetect:aBlock ifNone:[self errorNotFound] |
|
1344 |
! |
|
1345 |
||
1346 |
parentsDetect:aBlock ifNone:anExceptionBlock |
|
5925 | 1347 |
"find the first parent (bottom to top), for which evaluation of the block returns |
4733 | 1348 |
true; if none does so, return the evaluation of anExceptionBlock" |
1349 |
||
5925 | 1350 |
self parentsDo:[:prnt | |
1351 |
(aBlock value:prnt) ifTrue:[^ prnt] |
|
4733 | 1352 |
]. |
1353 |
^ anExceptionBlock value |
|
5840 | 1354 |
|
1355 |
"Modified: / 28-07-2018 / 13:51:06 / Claus Gittinger" |
|
4733 | 1356 |
! |
1357 |
||
1358 |
parentsDo:aBlock |
|
5925 | 1359 |
"evaluate a block for each parent (bottom to top)" |
4733 | 1360 |
|
1361 |
|prnt| |
|
1362 |
||
1363 |
prnt := self. |
|
1364 |
||
5840 | 1365 |
self synchronized:[ |
4733 | 1366 |
[(prnt := prnt parent) notNil and:[prnt isHierarchicalItem]] whileTrue:[ |
1367 |
aBlock value:prnt |
|
1368 |
] |
|
1369 |
]. |
|
5840 | 1370 |
|
1371 |
"Modified: / 28-07-2018 / 13:51:22 / Claus Gittinger" |
|
4733 | 1372 |
! ! |
1373 |
||
1374 |
!AbstractHierarchicalItem methodsFor:'initialization'! |
|
1375 |
||
1376 |
initialize |
|
1377 |
self setExpanded:false |
|
1378 |
! ! |
|
1379 |
||
1380 |
!AbstractHierarchicalItem methodsFor:'private'! |
|
1381 |
||
1382 |
addVisibleChildrenTo:aList |
|
1383 |
"add all visible children and sub-children to the list" |
|
1384 |
||
1385 |
self isExpanded ifFalse:[^ self]. |
|
1386 |
||
5840 | 1387 |
self from:1 to:nil do:[:el| |
4733 | 1388 |
aList add:el. |
5996 | 1389 |
el isExpanded ifTrue:[ |
1390 |
el addVisibleChildrenTo:aList. |
|
1391 |
]. |
|
4733 | 1392 |
]. |
5840 | 1393 |
|
5996 | 1394 |
"Modified: / 12-02-2019 / 19:00:25 / Claus Gittinger" |
4733 | 1395 |
! |
1396 |
||
1397 |
clearExpandedWhenLastChildWasRemoved |
|
5712 | 1398 |
"https://expeccoalm.exept.de/D227397 |
1399 |
Do not set #isExpanded to false just because #children is empty (may children appear 'again' later). |
|
1400 |
Do modify #isExpanded ONLY when a user presses the expand/collapse toggle, otherwise #isExpanded should be persistent. |
|
1401 |
||
1402 |
The user's preference if the item is expanded or collapsed should be kept, |
|
1403 |
regardless if there are chilren or not (even regardless anything else). |
|
1404 |
All other related things, like the drawing in case for #isExpanded is true and children is empty, |
|
1405 |
has to be solved within the drawing (or within any feature requesting this information)" |
|
1406 |
||
1407 |
^ false |
|
4733 | 1408 |
! |
1409 |
||
1410 |
criticalDo:aBlock |
|
5996 | 1411 |
<resource: #obsolete> |
5840 | 1412 |
self synchronized:aBlock |
5834 | 1413 |
|
1414 |
"Modified: / 23-07-2018 / 13:25:11 / Stefan Vogel" |
|
5840 | 1415 |
"Modified: / 28-07-2018 / 15:51:23 / Claus Gittinger" |
4733 | 1416 |
! |
1417 |
||
1418 |
listIndex |
|
1419 |
"returns the visible index or nil; for a non-visible root, 0 is returned" |
|
1420 |
||
1421 |
|index model| |
|
1422 |
||
1423 |
(model := self model) notNil ifTrue:[ |
|
1424 |
index := model identityIndexOf:self. |
|
1425 |
||
1426 |
(index ~~ 0 or:[parent == model]) ifTrue:[ |
|
1427 |
^ index |
|
1428 |
] |
|
1429 |
]. |
|
1430 |
^ nil |
|
1431 |
! |
|
1432 |
||
1433 |
numberOfVisibleChildren |
|
5996 | 1434 |
"returns the number of all visible children including subchildren, |
1435 |
but excluding myself" |
|
1436 |
||
1437 |
|count todo toCount| |
|
4733 | 1438 |
|
1439 |
self isExpanded ifFalse:[^ 0]. |
|
5840 | 1440 |
|
1441 |
count := 0. |
|
5996 | 1442 |
todo := OrderedCollection with:self. |
1443 |
[todo notEmpty] whileTrue:[ |
|
1444 |
toCount := todo removeFirst. |
|
1445 |
count := count + toCount getChildren size. |
|
1446 |
toCount getChildren do:[:each | |
|
1447 |
each isExpanded ifTrue:[ |
|
1448 |
todo add:each |
|
1449 |
]. |
|
1450 |
]. |
|
4733 | 1451 |
]. |
5840 | 1452 |
^ count |
1453 |
||
5996 | 1454 |
"Modified: / 12-02-2019 / 18:42:05 / Claus Gittinger" |
4733 | 1455 |
! |
1456 |
||
1457 |
parentOrModel |
|
1458 |
"returns the parent without checking for item or model" |
|
1459 |
||
1460 |
^ parent |
|
5840 | 1461 |
! |
1462 |
||
5993 | 1463 |
setChildren:aCollectionOfChildrenOrNil |
5994 | 1464 |
children := aCollectionOfChildrenOrNil. |
1465 |
||
1466 |
Smalltalk isSmalltalkDevelopmentSystem ifTrue:[ |
|
1467 |
children notNil ifTrue:[ |
|
1468 |
self assert:(children conform:[:each | each parent == self]). |
|
1469 |
]. |
|
1470 |
]. |
|
5993 | 1471 |
|
1472 |
"Created: / 03-02-2019 / 19:22:26 / Claus Gittinger" |
|
5994 | 1473 |
"Modified: / 06-02-2019 / 16:00:51 / Claus Gittinger" |
5993 | 1474 |
! |
1475 |
||
5840 | 1476 |
synchronized:aBlock |
1477 |
|model| |
|
1478 |
||
1479 |
(model := self model) notNil ifTrue:[ |
|
5857 | 1480 |
^ model synchronized:aBlock |
5840 | 1481 |
] ifFalse:[ |
5977 | 1482 |
"/ self breakPoint:#cg. "/ should not happen |
5857 | 1483 |
^ aBlock value |
5840 | 1484 |
] |
1485 |
||
1486 |
"Created: / 28-07-2018 / 13:58:54 / Claus Gittinger" |
|
5857 | 1487 |
"Modified: / 29-07-2018 / 21:02:22 / Stefan Vogel" |
5977 | 1488 |
"Modified: / 21-12-2018 / 20:01:54 / Claus Gittinger" |
4733 | 1489 |
! ! |
1490 |
||
1491 |
!AbstractHierarchicalItem methodsFor:'private-displaying'! |
|
1492 |
||
1493 |
displayLabel:aLabel h:lH on:aGC x:x y:y h:h |
|
1494 |
<resource: #obsolete> |
|
1495 |
||
1496 |
"display the label at x@y" |
|
1497 |
||
1498 |
"/ obsolete - left in for backward compatibility |
|
1499 |
self displayLabel:aLabel h:lH on:aGC x:x y:y h:h isHighlightedAsSelected:false |
|
1500 |
! |
|
1501 |
||
1502 |
displayLabel:aLabel h:lH on:aGC x:x y:y h:h isHighlightedAsSelected:isHighlightedAsSelected |
|
1503 |
"display the label at x@y" |
|
1504 |
||
4758
1095f8fdf167
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4751
diff
changeset
|
1505 |
|y0| |
4733 | 1506 |
|
1507 |
lH ~~ 0 ifTrue:[ |
|
1508 |
y0 := y - ((lH + 1 - h) // 2). |
|
1509 |
y0 := y0 + (aLabel ascentOn:aGC). |
|
1510 |
||
1511 |
(aLabel isString not |
|
5821 | 1512 |
or:[(aLabel includes:(Character cr)) not]) ifTrue:[ |
4758
1095f8fdf167
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4751
diff
changeset
|
1513 |
|labelShown| |
1095f8fdf167
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4751
diff
changeset
|
1514 |
|
4733 | 1515 |
labelShown := aLabel. |
1516 |
isHighlightedAsSelected ifTrue:[ |
|
1517 |
(aLabel isText and:[aLabel hasChangeOfEmphasis]) ifTrue:[ |
|
1518 |
labelShown := Text string:aLabel string emphasisCollection:aLabel emphasis asArray. |
|
1519 |
labelShown emphasisAllRemove:#color. |
|
1520 |
]. |
|
1521 |
]. |
|
5821 | 1522 |
labelShown displayOn:aGC x:x y:y0. |
1523 |
^ self. |
|
4733 | 1524 |
]. |
1525 |
||
4758
1095f8fdf167
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4751
diff
changeset
|
1526 |
aLabel asCollectionOfLines do:[:el| |
1095f8fdf167
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4751
diff
changeset
|
1527 |
|labelShown| |
1095f8fdf167
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4751
diff
changeset
|
1528 |
|
4733 | 1529 |
labelShown := el. |
1530 |
isHighlightedAsSelected ifTrue:[ |
|
1531 |
(el isText and:[el hasChangeOfEmphasis]) ifTrue:[ |
|
1532 |
labelShown := Text string:el string emphasisCollection:el emphasis asArray. |
|
1533 |
labelShown emphasisAllRemove:#color. |
|
1534 |
]. |
|
1535 |
]. |
|
1536 |
labelShown displayOn:aGC x:x y:y0. |
|
1537 |
y0 := y0 + (el heightOn:aGC) |
|
1538 |
] |
|
1539 |
]. |
|
1540 |
! |
|
1541 |
||
1542 |
heightOf:aLabel on:aGC |
|
1543 |
"returns the height of the label or 0" |
|
1544 |
||
1545 |
|h| |
|
1546 |
||
1547 |
aLabel isSequenceable ifFalse:[ |
|
1548 |
^ aLabel notNil ifTrue:[aLabel heightOn:aGC] ifFalse:[0] |
|
1549 |
]. |
|
1550 |
||
1551 |
aLabel isString ifFalse:[ |
|
1552 |
h := 0. |
|
1553 |
aLabel do:[:el|h := h max:(self heightOf:el on:aGC)]. |
|
4746
25341fd92e38
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4733
diff
changeset
|
1554 |
^ h |
4733 | 1555 |
]. |
1556 |
||
1557 |
h := 1 + (aLabel occurrencesOf:(Character cr)). |
|
1558 |
^ h * (aGC font height) |
|
1559 |
! |
|
1560 |
||
1561 |
widthOf:aLabel on:aGC |
|
1562 |
"returns the height of the label or 0" |
|
1563 |
||
1564 |
|w| |
|
1565 |
||
1566 |
aLabel isSequenceable ifFalse:[ |
|
1567 |
^ aLabel notNil ifTrue:[aLabel widthOn:aGC] ifFalse:[0] |
|
1568 |
]. |
|
1569 |
||
1570 |
aLabel isString ifFalse:[ |
|
1571 |
w := -5. |
|
1572 |
aLabel do:[:el|w := w + 5 + (self widthOf:el on:aGC)]. |
|
1573 |
^ w |
|
1574 |
]. |
|
1575 |
||
1576 |
(aLabel indexOf:(Character cr)) == 0 ifTrue:[ |
|
1577 |
^ aLabel widthOn:aGC |
|
1578 |
]. |
|
1579 |
||
1580 |
w := 0. |
|
1581 |
aLabel asCollectionOfLines do:[:el|w := w max:(el widthOn:aGC)]. |
|
1582 |
^ w |
|
1583 |
! ! |
|
1584 |
||
1585 |
!AbstractHierarchicalItem methodsFor:'private-enumerating'! |
|
1586 |
||
1587 |
nonCriticalDo:aOneArgBlock |
|
5996 | 1588 |
"WARNING: may fetch lazy children |
1589 |
evaluate a block noncritical for each child. |
|
5840 | 1590 |
Not synchronized - should only be called internally |
1591 |
within a synchronized region." |
|
4733 | 1592 |
|
1593 |
^ self nonCriticalFrom:1 to:nil do:aOneArgBlock |
|
5840 | 1594 |
|
5996 | 1595 |
"Modified (comment): / 12-02-2019 / 18:49:05 / Claus Gittinger" |
4733 | 1596 |
! |
1597 |
||
1598 |
nonCriticalFrom:startIndex to:endIndex do:aOneArgBlock |
|
5996 | 1599 |
"WARNING: may fetch lazy children |
1600 |
evaluate a block noncritical for each child starting with the |
|
5840 | 1601 |
child at startIndex to the endIndex (if nil to end of list). |
1602 |
Not synchronized - should only be called internally |
|
5870 | 1603 |
within a synchronized region. |
1604 |
Answer the value of the block executed on the last element." |
|
4733 | 1605 |
|
1606 |
|list size resp| |
|
1607 |
||
1608 |
list := self children. |
|
1609 |
size := list size. |
|
1610 |
||
1611 |
startIndex > size ifTrue:[^ nil]. |
|
1612 |
resp := nil. |
|
1613 |
||
1614 |
endIndex notNil ifTrue:[ |
|
1615 |
size := size min:endIndex |
|
1616 |
]. |
|
1617 |
startIndex to:size do:[:i| |
|
1618 |
|item| |
|
1619 |
||
1620 |
item := list at:i ifAbsent:nil. |
|
5996 | 1621 |
item isNil ifTrue:[self halt:'oops - lost child item?'. ^ resp]. |
4733 | 1622 |
resp := aOneArgBlock value:item. |
1623 |
]. |
|
1624 |
^ resp |
|
5840 | 1625 |
|
5870 | 1626 |
"Modified (comment): / 02-08-2018 / 16:02:13 / Stefan Vogel" |
5996 | 1627 |
"Modified: / 12-02-2019 / 16:55:20 / Claus Gittinger" |
1628 |
"Modified (comment): / 12-02-2019 / 18:48:58 / Claus Gittinger" |
|
4733 | 1629 |
! |
1630 |
||
1631 |
nonCriticalFrom:startIndex to:endIndex reverseDo:aOneArgBlock |
|
5996 | 1632 |
"WARNING: may fetch lazy children |
1633 |
evaluate a block non critical for each child starting with the |
|
5840 | 1634 |
child at endIndex (if nil to end of list) to startIndex. |
1635 |
Not synchronized - should only be called internally |
|
1636 |
within a synchronized region." |
|
4733 | 1637 |
|
1638 |
|list size resp| |
|
1639 |
||
1640 |
list := self children. |
|
1641 |
size := list size. |
|
1642 |
resp := nil. |
|
1643 |
||
1644 |
endIndex notNil ifTrue:[ |
|
1645 |
size := size min:endIndex |
|
1646 |
]. |
|
1647 |
size to:startIndex by:-1 do:[:i| |
|
1648 |
|item| |
|
1649 |
||
1650 |
item := list at:i ifAbsent:nil. |
|
1651 |
item isNil ifTrue:[^ resp]. |
|
1652 |
resp := aOneArgBlock value:item. |
|
1653 |
]. |
|
1654 |
^ resp |
|
5840 | 1655 |
|
5996 | 1656 |
"Modified (comment): / 12-02-2019 / 18:49:11 / Claus Gittinger" |
4733 | 1657 |
! |
1658 |
||
1659 |
nonCriticalKeysAndValuesReverseDo:aOneArgBlock |
|
5996 | 1660 |
"WARNING: may fetch lazy children |
1661 |
evaluate the argument, aBlock in reverse order for every |
|
5840 | 1662 |
child, passing both index and element as arguments. |
1663 |
Not synchronized - should only be called internally |
|
1664 |
within a synchronized region." |
|
4733 | 1665 |
|
1666 |
|list size resp| |
|
1667 |
||
1668 |
list := self children. |
|
1669 |
size := list size. |
|
1670 |
resp := nil. |
|
1671 |
||
1672 |
size to:1 by:-1 do:[:i| |
|
1673 |
|item| |
|
1674 |
||
1675 |
item := list at:i ifAbsent:nil. |
|
1676 |
item isNil ifTrue:[^ resp]. |
|
1677 |
resp := aOneArgBlock value:i value:item. |
|
1678 |
]. |
|
1679 |
^ resp |
|
5840 | 1680 |
|
5996 | 1681 |
"Modified (comment): / 12-02-2019 / 18:49:16 / Claus Gittinger" |
4733 | 1682 |
! |
1683 |
||
1684 |
nonCriticalRecursiveDo:aOneArgBlock |
|
5996 | 1685 |
"WARNING: may fetch lazy children |
1686 |
evaluate the block non critical for each item and all the sub-items. |
|
5840 | 1687 |
Not synchronized - should only be called internally |
1688 |
within a synchronized region." |
|
4733 | 1689 |
|
1690 |
self nonCriticalFrom:1 to:nil do:[:eachChild| |
|
1691 |
aOneArgBlock value:eachChild. |
|
1692 |
eachChild nonCriticalRecursiveDo:aOneArgBlock |
|
1693 |
]. |
|
5840 | 1694 |
|
5996 | 1695 |
"Modified (comment): / 12-02-2019 / 18:49:23 / Claus Gittinger" |
4733 | 1696 |
! |
1697 |
||
1698 |
nonCriticalRecursiveReverseDo:aOneArgBlock |
|
5996 | 1699 |
"WARNING: may fetch lazy children |
1700 |
evaluate the block non critical for each item and all the sub-items; |
|
5840 | 1701 |
proccesing children in reverse direction. |
1702 |
Not synchronized - should only be called internally |
|
1703 |
within a synchronized region." |
|
4733 | 1704 |
|
1705 |
self nonCriticalFrom:1 to:nil reverseDo:[:eachChild| |
|
1706 |
eachChild nonCriticalRecursiveReverseDo:aOneArgBlock. |
|
1707 |
aOneArgBlock value:eachChild. |
|
1708 |
]. |
|
5840 | 1709 |
|
5996 | 1710 |
"Modified (comment): / 12-02-2019 / 18:48:45 / Claus Gittinger" |
4733 | 1711 |
! |
1712 |
||
1713 |
nonCriticalRecursiveSort:aSortBlock |
|
5840 | 1714 |
"evaluate a block noncritical for each child. |
1715 |
Not synchronized - should only be called internally |
|
1716 |
within a synchronized region." |
|
4733 | 1717 |
|
1718 |
|unsorted sorted| |
|
1719 |
||
1720 |
unsorted := children. |
|
1721 |
||
1722 |
unsorted size ~~ 0 ifTrue:[ |
|
1723 |
sorted := unsorted sort:aSortBlock. |
|
1724 |
sorted do:[:el| el nonCriticalRecursiveSort:aSortBlock ]. |
|
5993 | 1725 |
self setChildren:sorted. |
4733 | 1726 |
]. |
5840 | 1727 |
|
5993 | 1728 |
"Modified: / 03-02-2019 / 19:24:03 / Claus Gittinger" |
4733 | 1729 |
! ! |
1730 |
||
1731 |
!AbstractHierarchicalItem methodsFor:'private-hierarchy'! |
|
1732 |
||
1733 |
recursiveSetCollapsed |
|
5996 | 1734 |
<resource: #obsolete> |
4733 | 1735 |
"collapse all children and sub-children without notifications" |
1736 |
||
5840 | 1737 |
self synchronized:[ |
4733 | 1738 |
self recursiveSetCollapsedHelper |
1739 |
] |
|
5840 | 1740 |
|
1741 |
"Modified: / 28-07-2018 / 13:56:58 / Claus Gittinger" |
|
4733 | 1742 |
! |
1743 |
||
1744 |
recursiveSetCollapsedHelper |
|
1745 |
"private helper. |
|
1746 |
collapse all children and sub-children without notifications. |
|
5840 | 1747 |
Helper; not synchronized - should only be called internally |
1748 |
within a synchronized region." |
|
4733 | 1749 |
|
5996 | 1750 |
|todo toCollapse| |
1751 |
||
1752 |
todo := OrderedCollection with:self. |
|
1753 |
[todo notEmpty] whileTrue:[ |
|
1754 |
"/ do not call self size or self children; |
|
1755 |
"/ otherwise, children might will be autocreated !!!! |
|
1756 |
toCollapse := todo removeFirst. |
|
1757 |
toCollapse setExpanded:false. |
|
1758 |
toCollapse getChildren do:[:eachChild | |
|
1759 |
eachChild canRecursiveCollapse ifTrue:[ |
|
1760 |
todo add:eachChild |
|
1761 |
]. |
|
5870 | 1762 |
] |
1763 |
]. |
|
5840 | 1764 |
|
5870 | 1765 |
"Modified: / 02-08-2018 / 16:07:35 / Stefan Vogel" |
5996 | 1766 |
"Modified: / 12-02-2019 / 17:42:11 / Claus Gittinger" |
4733 | 1767 |
! |
1768 |
||
1769 |
recursiveSetExpandedAndAddToList:aList |
|
5996 | 1770 |
<resource: #obsolete> |
4733 | 1771 |
"expand all children and sub-children without notifications; |
1772 |
add children to list" |
|
1773 |
||
5840 | 1774 |
self synchronized:[ |
4733 | 1775 |
self recursiveSetExpandedAndAddToListHelper:aList |
1776 |
]. |
|
5840 | 1777 |
|
1778 |
"Modified: / 28-07-2018 / 13:59:52 / Claus Gittinger" |
|
4733 | 1779 |
! |
1780 |
||
1781 |
recursiveSetExpandedAndAddToListHelper:aList |
|
1782 |
"private helper. |
|
1783 |
expand all children and sub-children without notifications; adds children to aList |
|
5840 | 1784 |
Helper; not synchronized - should only be called internally |
1785 |
within a synchronized region." |
|
4733 | 1786 |
|
5996 | 1787 |
|toDo work toExpand indexToAddAfter| |
1788 |
||
1789 |
toDo := OrderedCollection with:(self -> aList size). |
|
5925 | 1790 |
[ toDo notEmpty ] whileTrue:[ |
5996 | 1791 |
work := toDo removeFirst. |
1792 |
toExpand := work key. |
|
1793 |
indexToAddAfter := work value. |
|
5925 | 1794 |
toExpand setExpanded:true. |
5996 | 1795 |
(children := toExpand children) size > 0 ifTrue:[ |
1796 |
aList addAll:children afterIndex:indexToAddAfter. |
|
1797 |
children doWithIndex:[:eachChild :index | |
|
1798 |
eachChild canRecursiveExpand ifTrue:[ |
|
1799 |
toDo add:(eachChild -> (indexToAddAfter+index)) |
|
1800 |
]. |
|
5925 | 1801 |
]. |
4733 | 1802 |
]. |
1803 |
]. |
|
5840 | 1804 |
|
5996 | 1805 |
"Modified: / 12-02-2019 / 17:08:48 / Claus Gittinger" |
4733 | 1806 |
! ! |
1807 |
||
1808 |
!AbstractHierarchicalItem methodsFor:'private-to be redefined'! |
|
1809 |
||
4751
a1b6112d33ca
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4749
diff
changeset
|
1810 |
fetchChildren |
a1b6112d33ca
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4749
diff
changeset
|
1811 |
^ nil |
a1b6112d33ca
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4749
diff
changeset
|
1812 |
! |
a1b6112d33ca
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4749
diff
changeset
|
1813 |
|
4733 | 1814 |
heightOn:aGC |
1815 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
1816 |
||
1817 |
self subclassResponsibility. |
|
1818 |
||
1819 |
"/ could in theory compute it for every draw operation; |
|
1820 |
"/ in practice, this is not a good idea, as it could make drawing very slow |
|
1821 |
"/ (unless that info can be easily computed) |
|
1822 |
||
1823 |
"/ so we force programmers to think about that issue and redefine this method |
|
1824 |
"/ as required. If compuation is really cheap, it can be redefined as: |
|
1825 |
"/ ^ self heightOf:(self label) on:aGC |
|
1826 |
! |
|
1827 |
||
1828 |
isExpanded |
|
1829 |
"returns true if the item is expanded" |
|
1830 |
||
1831 |
self subclassResponsibility |
|
1832 |
! |
|
1833 |
||
1834 |
makeWidthAndHeightUnknown |
|
1835 |
"invalidate any cached with/height information" |
|
1836 |
||
1837 |
"see comments in widthOn/heightOn" |
|
1838 |
self subclassResponsibility |
|
1839 |
! |
|
1840 |
||
1841 |
setExpanded:aBoolean |
|
1842 |
"set expanded flag without any computation or notification. |
|
1843 |
It is left to the subclasses responsibility, where this expanded state is stored; |
|
1844 |
could be in the model (as a list of expanded items), in the item itself (as boolean flag), |
|
1845 |
or somewhere else. |
|
1846 |
For huge trees, it may make sense to not store the expanded flag in a slot |
|
1847 |
(in order to save space). See CompactHierarchicalItem as a clever example of how it can be |
|
1848 |
stored without ANY additional space requirements." |
|
1849 |
||
1850 |
self subclassResponsibility |
|
1851 |
! |
|
1852 |
||
1853 |
widthOn:aGC |
|
1854 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
1855 |
||
1856 |
self subclassResponsibility. |
|
1857 |
||
1858 |
"/ could in theory compute it for every draw operation; |
|
1859 |
"/ in practice, this is not a good idea, as it could make drawing very slow |
|
1860 |
"/ (unless that info can be easily computed) |
|
1861 |
||
1862 |
"/ so we force programmers to think about that issue and redefine this method |
|
1863 |
"/ as required. If compuation is really cheap, it can be redefined as: |
|
1864 |
"/ ^ self widthOf:(self label) on:aGC |
|
1865 |
! ! |
|
1866 |
||
1867 |
!AbstractHierarchicalItem methodsFor:'protocol-accessing'! |
|
1868 |
||
1869 |
children |
|
1870 |
"returns a list of children. When first asked, the list is fetched, if it was |
|
5116 | 1871 |
built lazily. |
4733 | 1872 |
*** to optimize: either redefine this or fetchChildren by subClass" |
1873 |
||
1874 |
children isNil ifTrue:[ |
|
5993 | 1875 |
self setChildren:(self fetchChildren) |
4733 | 1876 |
]. |
1877 |
^ children |
|
5993 | 1878 |
|
1879 |
"Modified: / 03-02-2019 / 19:23:55 / Claus Gittinger" |
|
4733 | 1880 |
! |
1881 |
||
1882 |
icon |
|
1883 |
"returns the icon or nil; |
|
1884 |
*** to optimize:redefine by subClass" |
|
1885 |
||
1886 |
|model| |
|
1887 |
||
1888 |
(model := self model) notNil ifTrue:[ |
|
1889 |
^ model iconFor:self |
|
1890 |
]. |
|
1891 |
^ nil |
|
1892 |
! |
|
1893 |
||
1894 |
label |
|
1895 |
"returns the label displayed on aGC; |
|
1896 |
*** to optimize:redefine by subClass" |
|
1897 |
||
1898 |
|model| |
|
1899 |
||
1900 |
(model := self model) notNil ifTrue:[ |
|
1901 |
^ model labelFor:self |
|
1902 |
]. |
|
1903 |
^ nil |
|
1904 |
! |
|
1905 |
||
1906 |
middleButtonMenu |
|
1907 |
"returns the items middleButtonMenu or nil if no menu is defined. |
|
1908 |
If nil is returned, the view is asked for a menu." |
|
1909 |
||
1910 |
<resource: #programMenu> |
|
1911 |
||
1912 |
|model| |
|
1913 |
||
1914 |
(model := self model) notNil ifTrue:[ |
|
1915 |
^ model middleButtonMenuFor:self |
|
1916 |
]. |
|
1917 |
^ nil |
|
1918 |
! |
|
1919 |
||
1920 |
recursiveSortChildren:aSortBlock |
|
5840 | 1921 |
self synchronized:[ |
1922 |
|children| |
|
1923 |
||
1924 |
(children := self children) notEmptyOrNil ifTrue:[ |
|
4733 | 1925 |
children sort:aSortBlock. |
1926 |
children do:[:aChild| aChild recursiveSortChildren:aSortBlock ] |
|
1927 |
] |
|
1928 |
]. |
|
5840 | 1929 |
|
1930 |
"Modified: / 28-07-2018 / 14:01:15 / Claus Gittinger" |
|
4733 | 1931 |
! |
1932 |
||
1933 |
sortChildren:aSortBlock |
|
1934 |
"sort the children inplace using the 2-arg block sortBlock for comparison" |
|
1935 |
||
1936 |
<resource: #obsolete> |
|
1937 |
self obsoleteMethodWarning:'use #sort:'. |
|
1938 |
self sort:aSortBlock. |
|
1939 |
! ! |
|
1940 |
||
1941 |
!AbstractHierarchicalItem methodsFor:'protocol-displaying'! |
|
1942 |
||
1943 |
displayIcon:anIcon atX:x y:y on:aGC |
|
1944 |
"called to draw the icon - can be redefined to manipulate the icon" |
|
1945 |
||
1946 |
anIcon displayOn:aGC x:x y:y. |
|
1947 |
! |
|
1948 |
||
1949 |
displayOn:aGC x:x y:y h:h |
|
1950 |
<resource: #obsolete> |
|
1951 |
"draw the receiver in the graphicsContext, aGC" |
|
1952 |
||
1953 |
"/ obsolete - left here for backward compatibility |
|
1954 |
self displayOn:aGC x:x y:y h:h isHighlightedAsSelected:false |
|
1955 |
! |
|
1956 |
||
1957 |
displayOn:aGC x:x y:y h:h isHighlightedAsSelected:isHighlightedAsSelected |
|
1958 |
"draw the receiver in the graphicsContext, aGC" |
|
1959 |
||
1960 |
|label |
|
1961 |
x0 "{ Class:SmallInteger }"| |
|
1962 |
||
1963 |
label := self label. |
|
1964 |
label isNil ifTrue:[^ self]. |
|
1965 |
||
5325 | 1966 |
label isNonByteCollection ifFalse:[ |
4733 | 1967 |
^ self displayLabel:label h:(self heightOn:aGC) on:aGC x:x y:y h:h isHighlightedAsSelected:isHighlightedAsSelected |
1968 |
]. |
|
1969 |
||
1970 |
x0 := x. |
|
1971 |
label do:[:el| |
|
1972 |
el notNil ifTrue:[ |
|
1973 |
self displayLabel:el h:(self heightOf:el on:aGC) on:aGC x:x0 y:y h:h isHighlightedAsSelected:isHighlightedAsSelected. |
|
1974 |
x0 := x0 + 5 + (el widthOn:aGC). |
|
1975 |
]. |
|
1976 |
] |
|
1977 |
! ! |
|
1978 |
||
1979 |
!AbstractHierarchicalItem methodsFor:'protocol-event processing'! |
|
1980 |
||
1981 |
processButtonPress:button visibleX:visX visibleY: visY on: view |
|
1982 |
"A mouse button was pressed on myself. The visX/visY coordinates |
|
1983 |
are relative to the viewOrigin. |
|
1984 |
||
1985 |
If this method returns TRUE, the other method |
|
1986 |
#processButtonPress:x:y:on: IS NOT CALLED !!!!!! |
|
1987 |
" |
|
1988 |
||
1989 |
^false |
|
1990 |
||
1991 |
"Created: / 18-04-2013 / 09:56:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1992 |
"Modified (comment): / 18-04-2013 / 11:04:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1993 |
! |
|
1994 |
||
1995 |
processButtonPress:button x:x y:y |
|
1996 |
"a mouse button was pressed in my label. |
|
1997 |
Return true, if the event is eaten (ignored by the gc). |
|
1998 |
By default, false is returned (should be handled by the gc)." |
|
1999 |
||
2000 |
^ false |
|
2001 |
! |
|
2002 |
||
2003 |
processButtonPress:button x:x y:y on:aGC |
|
2004 |
"a mouse button was pressed in my label. |
|
2005 |
Return true, if the event is eaten (ignored by the gc). |
|
2006 |
By default, false is returned (should be handled by the gc)." |
|
2007 |
||
2008 |
^ self processButtonPress:button x:x y:y |
|
2009 |
! |
|
2010 |
||
2011 |
processButtonPressOnIcon:button on:aGC |
|
2012 |
"a mouse button was pressed in my icon. |
|
2013 |
Return true, if the event is eaten (ignored by the gc). |
|
2014 |
By default, false is returned (should be handled by the gc)." |
|
2015 |
||
2016 |
^ false |
|
2017 |
! ! |
|
2018 |
||
2019 |
!AbstractHierarchicalItem methodsFor:'protocol-monitoring'! |
|
2020 |
||
2021 |
monitoringCycle |
|
2022 |
"called every 'n' seconds by the model, if the monitoring |
|
2023 |
cycle is enabled. The item can perform some checks, .. |
|
2024 |
**** can be redefined by subclass to perform some actions |
|
2025 |
" |
|
2026 |
! ! |
|
2027 |
||
2028 |
!AbstractHierarchicalItem methodsFor:'protocol-queries'! |
|
2029 |
||
2030 |
canCollapse |
|
2031 |
"called before collapsing the item; can be redefined |
|
2032 |
by subclass to omit the collapse operation" |
|
2033 |
||
2034 |
^ self isExpanded |
|
2035 |
! |
|
2036 |
||
2037 |
canExpand |
|
2038 |
"called before expanding the item; can be redefined |
|
2039 |
by subclass to omit the expand operation" |
|
2040 |
||
2041 |
^ self hasChildren |
|
2042 |
! |
|
2043 |
||
2044 |
canRecursiveCollapse |
|
2045 |
"called before collapsing the item; can be redefined |
|
2046 |
by subclass to omit the collapse operation " |
|
2047 |
||
2048 |
^ self canCollapse |
|
2049 |
! |
|
2050 |
||
2051 |
canRecursiveExpand |
|
2052 |
"called before expanding the item; can be redefined |
|
2053 |
by subclass to omit the collapse operation" |
|
2054 |
||
2055 |
^ self canExpand |
|
2056 |
! |
|
2057 |
||
2058 |
drawHorizontalLineUpToText |
|
5802 | 2059 |
"draw the horizontal line for the selected item up to the text |
2060 |
or (by default) to the start of the vertical line; |
|
2061 |
only used by the hierarchical view |
|
4733 | 2062 |
" |
2063 |
^ false |
|
5802 | 2064 |
|
2065 |
"Modified (comment): / 12-06-2018 / 10:41:54 / Claus Gittinger" |
|
4733 | 2066 |
! |
2067 |
||
2068 |
hasChildren |
|
5991 | 2069 |
"checks whether the item has children; |
2070 |
here the children are fetched, and thus this may take some time. |
|
2071 |
*** to optimize: redefine in subClass (example: FileDirectory)" |
|
4733 | 2072 |
|
5720 | 2073 |
^ self children notEmptyOrNil |
2074 |
||
2075 |
"Modified: / 08-03-2018 / 19:37:45 / stefan" |
|
5991 | 2076 |
"Modified (comment): / 02-02-2019 / 14:51:59 / Claus Gittinger" |
4733 | 2077 |
! |
2078 |
||
2079 |
hasIndicator |
|
2080 |
"on default the indicator is drawn if the item has children" |
|
2081 |
||
2082 |
^ self hasChildren |
|
2083 |
! |
|
2084 |
||
2085 |
isSelectable |
|
2086 |
"returns true if the item is selectable. Can be redefined in subclasses" |
|
2087 |
||
2088 |
^ true |
|
2089 |
! |
|
2090 |
||
2091 |
string |
|
2092 |
"access the printable string used for stepping through a list |
|
2093 |
searching for an entry starting with a character. |
|
2094 |
*** to optimize:redefine by subClass" |
|
2095 |
||
2096 |
|label| |
|
2097 |
||
2098 |
(label := self label) notNil ifTrue:[ |
|
2099 |
label isString ifTrue:[ ^ label string ]. |
|
2100 |
label isImageOrForm ifTrue:[ ^ nil ]. |
|
2101 |
||
2102 |
label isSequenceable ifFalse:[ |
|
2103 |
^ label perform:#string ifNotUnderstood:nil |
|
2104 |
]. |
|
2105 |
||
2106 |
label do:[:el||s| |
|
2107 |
(el notNil and:[el isImageOrForm not]) ifTrue:[ |
|
2108 |
s := el perform:#string ifNotUnderstood:nil. |
|
2109 |
s notNil ifTrue:[^ s]. |
|
2110 |
] |
|
2111 |
] |
|
2112 |
]. |
|
2113 |
^ nil |
|
2114 |
! ! |
|
2115 |
||
2116 |
!AbstractHierarchicalItem methodsFor:'queries'! |
|
2117 |
||
2118 |
isChildOf:anItem |
|
5884 | 2119 |
"returns true if the item is a child (or grandchild or ...) of anItem" |
4733 | 2120 |
|
5840 | 2121 |
self synchronized:[ |
2122 |
|item| |
|
2123 |
||
2124 |
item := self. |
|
2125 |
||
2126 |
[anItem ~~ item] whileTrue:[ |
|
2127 |
((item := item parent) notNil and:[item isHierarchicalItem]) ifFalse:[ |
|
2128 |
^ false |
|
2129 |
] |
|
2130 |
]. |
|
4733 | 2131 |
]. |
2132 |
^ true |
|
5840 | 2133 |
|
2134 |
"Modified: / 28-07-2018 / 14:02:32 / Claus Gittinger" |
|
5884 | 2135 |
"Modified (comment): / 12-08-2018 / 12:49:16 / Claus Gittinger" |
4733 | 2136 |
! |
2137 |
||
2138 |
isCollapsed |
|
2139 |
"returns true if the item is collapsed" |
|
2140 |
||
2141 |
^ self isExpanded not |
|
2142 |
! |
|
2143 |
||
2144 |
isDirectoryItem |
|
2145 |
^ false |
|
2146 |
||
2147 |
"Created: / 23-06-2006 / 12:47:05 / fm" |
|
2148 |
"Modified: / 23-02-2007 / 12:04:23 / User" |
|
2149 |
! |
|
2150 |
||
2151 |
isHierarchicalItem |
|
2152 |
"used to decide if the parent is a hierarchical item or the model" |
|
2153 |
||
2154 |
^ true |
|
2155 |
! |
|
2156 |
||
2157 |
isRealChildOf:anItem |
|
2158 |
"returns true if the item is a child of anItem" |
|
2159 |
||
5840 | 2160 |
self synchronized:[ |
2161 |
|item| |
|
2162 |
item := self parent. |
|
2163 |
||
2164 |
[item notNil] whileTrue:[ |
|
2165 |
item == anItem ifTrue:[^ true]. |
|
2166 |
item := item parent. |
|
2167 |
]. |
|
4733 | 2168 |
]. |
2169 |
^ false |
|
5840 | 2170 |
|
2171 |
"Modified: / 28-07-2018 / 14:03:22 / Claus Gittinger" |
|
4733 | 2172 |
! |
2173 |
||
2174 |
isRootItem |
|
2175 |
"returns true if the item is the root item" |
|
2176 |
||
2177 |
^ parent isHierarchicalItem not |
|
2178 |
! |
|
2179 |
||
2180 |
size |
|
2181 |
"return the number of children" |
|
2182 |
||
2183 |
^ self children size |
|
2184 |
! ! |
|
2185 |
||
2186 |
!AbstractHierarchicalItem methodsFor:'searching'! |
|
2187 |
||
2188 |
detect:aOneArgBlock |
|
5363 | 2189 |
"find the first child (not recursive), for which evaluation of the block returns |
4733 | 2190 |
true; if none does so, report an error" |
2191 |
||
2192 |
^ self detect:aOneArgBlock ifNone:[self errorNotFound] |
|
5363 | 2193 |
|
2194 |
"Modified (comment): / 25-11-2016 / 08:40:16 / cg" |
|
4733 | 2195 |
! |
2196 |
||
2197 |
detect:aOneArgBlock ifNone:exceptionValue |
|
5363 | 2198 |
"find the first child (not recursive), for which evaluation of the block returns |
4733 | 2199 |
true; if none does so, return the value of anExceptionValue" |
2200 |
||
2201 |
self do:[:el| |
|
2202 |
(aOneArgBlock value:el) ifTrue:[^ el] |
|
2203 |
]. |
|
2204 |
^ exceptionValue value |
|
5363 | 2205 |
|
2206 |
"Modified (comment): / 25-11-2016 / 08:40:18 / cg" |
|
4733 | 2207 |
! |
2208 |
||
2209 |
detectLast:aOneArgBlock |
|
5363 | 2210 |
"find the last child (not recursive), for which evaluation of the block returns |
4733 | 2211 |
true; if none does so, an exception is raised" |
2212 |
||
2213 |
^ self detectLast:aOneArgBlock ifNone:[self errorNotFound] |
|
5363 | 2214 |
|
2215 |
"Modified (comment): / 25-11-2016 / 08:40:21 / cg" |
|
4733 | 2216 |
! |
2217 |
||
2218 |
detectLast:aOneArgBlock ifNone:anExceptionValue |
|
5363 | 2219 |
"find the last child (not recursive), for which evaluation of the block returns |
4733 | 2220 |
true; if none does so, return the value of anExceptionValue" |
2221 |
||
2222 |
self reverseDo:[:el| (aOneArgBlock value:el) ifTrue:[^ el] ]. |
|
2223 |
^ anExceptionValue value |
|
5363 | 2224 |
|
2225 |
"Modified (comment): / 25-11-2016 / 08:40:23 / cg" |
|
4733 | 2226 |
! |
2227 |
||
5624 | 2228 |
findChildByLabelPath:aLabelPath |
2229 |
"recursivly find the child by its label path. |
|
2230 |
A label path is an ordered collection (or array) of strings, |
|
2231 |
which are the labels of items (i.e. as retrived by labelPath)." |
|
2232 |
||
2233 |
|restPath searchedLabel childSearched| |
|
2234 |
||
2235 |
childSearched := self. |
|
2236 |
restPath := aLabelPath. |
|
2237 |
||
2238 |
[ |
|
2239 |
|subChild| |
|
2240 |
||
2241 |
restPath isEmptyOrNil ifTrue:[^ childSearched]. |
|
2242 |
||
2243 |
searchedLabel := restPath first string. |
|
2244 |
||
2245 |
subChild := childSearched detect:[:eachSubChild | eachSubChild label string = searchedLabel] ifNone:nil. |
|
2246 |
subChild isNil ifTrue:[^ nil]. |
|
2247 |
||
2248 |
childSearched := subChild. |
|
2249 |
restPath := restPath from:2. |
|
2250 |
] loop. |
|
2251 |
||
2252 |
"Created: / 16-10-2017 / 14:30:11 / cg" |
|
2253 |
! |
|
2254 |
||
4733 | 2255 |
findFirst:aOneArgBlock |
5363 | 2256 |
"find the first child (not recursive), for which evaluation of the argument, aOneArgBlock |
4733 | 2257 |
returns true; return its index or 0 if none detected." |
2258 |
||
2259 |
||
2260 |
self keysAndValuesDo:[:i :el| (aOneArgBlock value:el) ifTrue:[^ i] ]. |
|
2261 |
^ 0 |
|
5363 | 2262 |
|
2263 |
"Modified (comment): / 25-11-2016 / 08:40:25 / cg" |
|
4733 | 2264 |
! |
2265 |
||
5363 | 2266 |
findLast:aOneArgBlock |
2267 |
"find the last child (not recursive), for which evaluation of the argument, aOneArgBlock |
|
4733 | 2268 |
returns true; return its index or 0 if none detected." |
2269 |
||
5363 | 2270 |
self keysAndValuesReverseDo:[:i :el| (aOneArgBlock value:el) ifTrue:[^ i] ]. |
4733 | 2271 |
^ 0 |
5363 | 2272 |
|
2273 |
"Modified (format): / 25-11-2016 / 08:40:33 / cg" |
|
4733 | 2274 |
! |
2275 |
||
5864 | 2276 |
findNextInTreeForWhich:aBlock |
2277 |
"does a breadth-first search in the tree starting at the receiver |
|
2278 |
i.e. first goes down recursively, then up to the next child of the parent |
|
2279 |
(doing a recursive search there), |
|
2280 |
up until all of the top item's children have been visited. |
|
2281 |
Returns the found item or nil." |
|
2282 |
||
2283 |
|item nextItem itemsParent| |
|
2284 |
||
2285 |
item := self. |
|
2286 |
[item notNil] whileTrue:[ |
|
2287 |
item recursiveDo:[:eachChild | |
|
2288 |
(aBlock value:eachChild) ifTrue:[ |
|
2289 |
^ eachChild. |
|
2290 |
]. |
|
2291 |
]. |
|
2292 |
||
2293 |
itemsParent := item parent. |
|
2294 |
nextItem := nil. |
|
2295 |
||
2296 |
[ |
|
2297 |
|idx siblings| |
|
2298 |
||
2299 |
itemsParent isNil ifTrue:[ |
|
2300 |
^ nil |
|
2301 |
]. |
|
2302 |
siblings := itemsParent children. |
|
2303 |
idx := siblings identityIndexOf:item. |
|
2304 |
nextItem := siblings at:idx+1 ifAbsent:nil. |
|
2305 |
nextItem isNil ifTrue:[ |
|
2306 |
item := itemsParent. |
|
2307 |
itemsParent := itemsParent parent. |
|
2308 |
]. |
|
2309 |
] doWhile:[ nextItem isNil ]. |
|
2310 |
||
2311 |
item := nextItem. |
|
2312 |
(aBlock value:item) ifTrue:[ |
|
2313 |
^ item. |
|
2314 |
]. |
|
2315 |
]. |
|
2316 |
^ nil |
|
2317 |
||
2318 |
"Created: / 31-07-2018 / 09:01:11 / Claus Gittinger" |
|
2319 |
! |
|
2320 |
||
5885 | 2321 |
findPreviousInTreeForWhich:aBlock |
2322 |
"does a breadth-first search in the tree starting at the receiver |
|
2323 |
i.e. first goes down recursively, then up to the next child of the parent |
|
2324 |
(doing a recursive search there), |
|
2325 |
up until all of the top item's children have been visited. |
|
2326 |
Returns the found item or nil." |
|
2327 |
||
2328 |
|item itemsParent idx siblings prevItem| |
|
2329 |
||
2330 |
item := self. |
|
2331 |
[item notNil] whileTrue:[ |
|
2332 |
"/ previous sibling |
|
2333 |
itemsParent := item parent. |
|
2334 |
itemsParent isNil ifTrue:[ |
|
2335 |
^ nil |
|
2336 |
]. |
|
2337 |
siblings := itemsParent children. |
|
2338 |
idx := siblings identityIndexOf:item. |
|
2339 |
idx <= 1 ifTrue:[ |
|
2340 |
"/ continue in parent |
|
2341 |
item := itemsParent. |
|
2342 |
] ifFalse:[ |
|
2343 |
prevItem := siblings at:idx-1 ifAbsent:nil. |
|
2344 |
"/ continue in prev sibling's last child |
|
2345 |
item := prevItem. |
|
2346 |
[item children notEmptyOrNil] whileTrue:[ |
|
2347 |
item := item children last. |
|
2348 |
] |
|
2349 |
]. |
|
2350 |
item isNil ifTrue:[^ nil]. |
|
2351 |
item isRootItem ifTrue:[^ nil]. |
|
2352 |
||
2353 |
(aBlock value:item) ifTrue:[ |
|
2354 |
^ item. |
|
2355 |
]. |
|
2356 |
]. |
|
2357 |
^ nil |
|
2358 |
||
2359 |
"Created: / 13-08-2018 / 10:59:12 / Claus Gittinger" |
|
2360 |
! |
|
2361 |
||
4733 | 2362 |
identityIndexOf:aChild |
2363 |
"return the index of aChild or 0 if not found. Compare using ==" |
|
2364 |
||
2365 |
^ self identityIndexOf:aChild startingAt:1 |
|
2366 |
! |
|
2367 |
||
2368 |
identityIndexOf:aChild startingAt:startIndex |
|
2369 |
"return the index of aChild, starting search at startIndex. |
|
2370 |
Compare using ==; return 0 if not found" |
|
2371 |
||
2372 |
|index| |
|
2373 |
||
2374 |
index := startIndex. |
|
2375 |
||
2376 |
self from:startIndex do:[:el| |
|
2377 |
el == aChild ifTrue:[^ index ]. |
|
2378 |
index := index + 1. |
|
2379 |
]. |
|
2380 |
^ 0 |
|
2381 |
! |
|
2382 |
||
2383 |
recursiveDetect:aOneArgBlock |
|
2384 |
"recursive find the first child, for which evaluation |
|
2385 |
of the block returns true; if none, nil is returned. |
|
2386 |
Warning: this only searches in already visible child elements |
|
2387 |
i.e. any collapsed items are not searched." |
|
2388 |
||
2389 |
self recursiveDo:[:aChild| |
|
2390 |
(aOneArgBlock value:aChild) ifTrue:[^ aChild] |
|
2391 |
]. |
|
2392 |
^ nil |
|
2393 |
! |
|
2394 |
||
2395 |
recursiveDetectLast:aBlock |
|
5363 | 2396 |
"recursive find the last child, for which evaluation of the block returns true; |
2397 |
if none does so, nil is returned. |
|
2398 |
Warning: this only searches in already visible child elements |
|
2399 |
i.e. any collapsed items are not searched." |
|
4733 | 2400 |
|
2401 |
self recursiveReverseDo:[:aChild| |
|
2402 |
(aBlock value:aChild) ifTrue:[^ aChild]. |
|
2403 |
]. |
|
2404 |
^ nil |
|
5363 | 2405 |
|
2406 |
"Modified (comment): / 25-11-2016 / 08:41:42 / cg" |
|
4733 | 2407 |
! |
2408 |
||
2409 |
withAllDetect:aOneArgBlock |
|
5363 | 2410 |
"recursive find the first item including self, |
2411 |
for which evaluation of the block returns true; if none nil is returned. |
|
2412 |
Warning: this only searches in already visible child elements |
|
2413 |
i.e. any collapsed items are not searched." |
|
4733 | 2414 |
|
2415 |
(aOneArgBlock value:self) ifTrue:[^ self]. |
|
2416 |
||
2417 |
^ self recursiveDetect:aOneArgBlock |
|
5363 | 2418 |
|
2419 |
"Modified (comment): / 25-11-2016 / 08:41:53 / cg" |
|
4733 | 2420 |
! ! |
2421 |
||
2422 |
!AbstractHierarchicalItem methodsFor:'sorting & reordering'! |
|
2423 |
||
2424 |
recursiveSort:aSortBlock |
|
2425 |
"recursive sort the children inplace using the 2-arg block sortBlock for comparison" |
|
2426 |
||
5840 | 2427 |
children notEmptyOrNil ifTrue:[ |
2428 |
self synchronized:[ |
|
2429 |
"/ check again (asynchronous update was possible before) |
|
2430 |
children notEmptyOrNil ifTrue:[ |
|
2431 |
self nonCriticalRecursiveSort:aSortBlock. |
|
2432 |
self childrenOrderChanged. |
|
2433 |
] |
|
4733 | 2434 |
] |
2435 |
]. |
|
5840 | 2436 |
|
2437 |
"Modified (format): / 28-07-2018 / 15:46:06 / Claus Gittinger" |
|
4733 | 2438 |
! |
2439 |
||
2440 |
sort:aSortBlock |
|
2441 |
"sort the children inplace using the 2-arg block sortBlock for comparison" |
|
2442 |
||
2443 |
children notEmptyOrNil ifTrue: [ |
|
5840 | 2444 |
self synchronized:[ |
4733 | 2445 |
"/ check again (asynchronous update was possible before) |
2446 |
children notEmptyOrNil ifTrue: [ |
|
5993 | 2447 |
self setChildren:(children sort:aSortBlock). |
4733 | 2448 |
self childrenOrderChanged. |
2449 |
] |
|
2450 |
]. |
|
2451 |
] |
|
5840 | 2452 |
|
5993 | 2453 |
"Modified: / 03-02-2019 / 19:24:20 / Claus Gittinger" |
4733 | 2454 |
! ! |
2455 |
||
2456 |
!AbstractHierarchicalItem class methodsFor:'documentation'! |
|
2457 |
||
2458 |
version |
|
4795
eead012852f9
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4758
diff
changeset
|
2459 |
^ '$Header$' |
4733 | 2460 |
! |
2461 |
||
2462 |
version_CVS |
|
4795
eead012852f9
class: AbstractHierarchicalItem
Claus Gittinger <cg@exept.de>
parents:
4758
diff
changeset
|
2463 |
^ '$Header$' |
4733 | 2464 |
! ! |
2465 |