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