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