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