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