author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Thu, 07 Feb 2019 12:16:15 +0000 | |
branch | jv |
changeset 6065 | e880a0b1320b |
parent 5373 | 772578cec4f7 |
child 5498 | 797c3e694be7 |
permissions | -rw-r--r-- |
1431 | 1 |
" |
2 |
COPYRIGHT (c) 1999 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 |
" |
|
1751 | 12 |
"{ Package: 'stx:libwidg2' }" |
13 |
||
5216 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1390 | 16 |
List subclass:#HierarchicalList |
1733 | 17 |
instanceVariableNames:'recursionLock root showRoot application monitoringTask |
2223
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
18 |
monitoringTaskDelay additionalItemsToMonitorSemaphore' |
1390 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
1430 | 21 |
category:'Views-Support' |
1390 | 22 |
! |
23 |
||
24 |
!HierarchicalList class methodsFor:'documentation'! |
|
25 |
||
1431 | 26 |
copyright |
27 |
" |
|
28 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
||
39 |
! |
|
40 |
||
1390 | 41 |
documentation |
42 |
" |
|
43 |
Hierarchical Lists are mostly like List, but adding and removing |
|
44 |
elements are handled by the items itself. |
|
5289 | 45 |
Special change notifications are emitted, |
46 |
whenever the list is changed. |
|
47 |
I am used mostly by the HierarchicalListView widget; |
|
48 |
see comments there. |
|
1390 | 49 |
|
50 |
[Instance variables:] |
|
51 |
root <HierarchicalItem> first item into list |
|
52 |
showRoot <Boolean> show or hide root item |
|
53 |
application <Application> the user is able to set an application |
|
54 |
which can be accessed by an item. |
|
55 |
[author:] |
|
56 |
Claus Atzkern |
|
57 |
||
58 |
[see also:] |
|
59 |
HierarchicalItem |
|
60 |
HierarchicalListView |
|
61 |
" |
|
62 |
! ! |
|
63 |
||
1818 | 64 |
!HierarchicalList methodsFor:'accessing-look'! |
1390 | 65 |
|
66 |
showRoot |
|
67 |
"show or hide root item |
|
68 |
" |
|
2430 | 69 |
showRoot isNil ifTrue:[ |
70 |
showRoot := true |
|
71 |
]. |
|
72 |
^ showRoot |
|
1390 | 73 |
! |
74 |
||
75 |
showRoot:aBoolean |
|
76 |
"show or hide root item |
|
77 |
" |
|
78 |
aBoolean ~~ self showRoot ifTrue:[ |
|
79 |
showRoot := aBoolean. |
|
80 |
||
81 |
root notNil ifTrue:[ |
|
1869 | 82 |
showRoot ifTrue:[ |
83 |
super addFirst:root |
|
84 |
] ifFalse:[ |
|
85 |
super removeFirst. |
|
86 |
root expand |
|
87 |
] |
|
1390 | 88 |
] |
89 |
] |
|
90 |
||
91 |
! ! |
|
92 |
||
1818 | 93 |
!HierarchicalList methodsFor:'accessing-monitoring task'! |
1390 | 94 |
|
95 |
monitoringTaskDelay |
|
96 |
"get the delay time of the monitoring task measured in seconds |
|
97 |
or nil( monitoring disabled ). The task runs through all items |
|
98 |
of the list performing #monitoringCycle and than at end of the |
|
99 |
list the task is suspended for monitoringTaskDelay seconds. |
|
100 |
" |
|
101 |
^ monitoringTaskDelay |
|
102 |
! |
|
103 |
||
104 |
monitoringTaskDelay:inSecondsOrNil |
|
105 |
"set the delay time of the monitoring task measured in seconds |
|
106 |
or nil( monitoring disabled ). The task runs through all items |
|
107 |
of the list performing #monitoringCycle and than at end of the |
|
108 |
list the task is suspended for monitoringTaskDelay seconds. |
|
109 |
" |
|
110 |
inSecondsOrNil isNil ifTrue:[ |
|
1439
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
111 |
self stopMonitoringTask. |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
112 |
monitoringTaskDelay := nil. |
1390 | 113 |
] ifFalse:[ |
1439
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
114 |
monitoringTaskDelay := inSecondsOrNil. |
1390 | 115 |
self startMonitoringTask |
116 |
]. |
|
117 |
! ! |
|
118 |
||
1818 | 119 |
!HierarchicalList methodsFor:'accessing-mvc'! |
1390 | 120 |
|
1439
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
121 |
addDependent:anObject |
5373 | 122 |
"restart the monitoringTask if necessary |
1439
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
123 |
" |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
124 |
super addDependent:anObject. |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
125 |
self startMonitoringTask. |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
126 |
! |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
127 |
|
1390 | 128 |
application |
129 |
"returns the responsible application; if no application is defined, |
|
130 |
nil is returned |
|
131 |
" |
|
132 |
^ application |
|
133 |
! |
|
134 |
||
135 |
application:anApplication |
|
136 |
"set the responsible application |
|
137 |
" |
|
1733 | 138 |
application := anApplication. |
1390 | 139 |
! |
140 |
||
141 |
applicationsDo:aOneArgBlock |
|
142 |
"evaluate the block on each dependent application |
|
143 |
" |
|
144 |
|appl| |
|
145 |
||
146 |
dependents notNil ifTrue:[ |
|
147 |
dependents do:[:aDep| |
|
148 |
appl := aDep perform:#application ifNotUnderstood:nil. |
|
149 |
||
150 |
appl notNil ifTrue:[ |
|
151 |
aOneArgBlock value:appl |
|
152 |
] |
|
153 |
] |
|
154 |
] |
|
1439
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
155 |
! |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
156 |
|
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
157 |
removeDependent:anObject |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
158 |
"stop the monitoringTask if no more dependencies exists |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
159 |
" |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
160 |
super removeDependent:anObject. |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
161 |
|
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
162 |
dependents size == 0 ifTrue:[ |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
163 |
self stopMonitoringTask |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
164 |
]. |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
165 |
|
1390 | 166 |
! ! |
167 |
||
1818 | 168 |
!HierarchicalList methodsFor:'accessing-root'! |
1390 | 169 |
|
170 |
root |
|
171 |
"get the root item |
|
172 |
" |
|
173 |
^ root |
|
174 |
||
175 |
! |
|
176 |
||
5216 | 177 |
root:aRootItem |
1390 | 178 |
"set the root item |
179 |
" |
|
4676 | 180 |
|children| |
1390 | 181 |
|
182 |
self stopMonitoringTask. |
|
183 |
||
5216 | 184 |
"/ inlink the previous root |
1390 | 185 |
root notNil ifTrue:[ |
186 |
root parent:nil. |
|
187 |
root := nil. |
|
188 |
]. |
|
189 |
||
5216 | 190 |
(root := aRootItem) isEmptyOrNil ifTrue:[ |
4676 | 191 |
self removeAll. |
192 |
] ifFalse:[ |
|
1869 | 193 |
self showRoot ifFalse:[root expand]. |
194 |
||
1390 | 195 |
root parent:self. |
196 |
children := OrderedCollection new. |
|
197 |
self showRoot ifTrue:[children add:root]. |
|
198 |
root addVisibleChildrenTo:children. |
|
4676 | 199 |
"/ self removeAll. |
200 |
"/ self addAll:children beforeIndex:1. |
|
201 |
self contents:children. |
|
1390 | 202 |
]. |
203 |
self startMonitoringTask. |
|
3070 | 204 |
|
205 |
"Modified: / 12-09-2006 / 18:22:42 / cg" |
|
1390 | 206 |
! ! |
207 |
||
208 |
!HierarchicalList methodsFor:'private'! |
|
209 |
||
2258 | 210 |
criticalDo:aBlock |
211 |
"evaluate the block in a critical region |
|
212 |
" |
|
213 |
^ recursionLock critical:aBlock |
|
214 |
! |
|
215 |
||
1733 | 216 |
initContents:aSize |
2430 | 217 |
"setup defaults |
218 |
" |
|
219 |
showRoot isNil ifTrue:[ showRoot := true ]. |
|
220 |
recursionLock isNil ifTrue:[ recursionLock := RecursionLock new ]. |
|
221 |
||
1733 | 222 |
^ super initContents:aSize. |
223 |
! |
|
224 |
||
1390 | 225 |
itemAddAll:aListOfItems beforeIndex:anIndex |
226 |
"insert all items before an index |
|
227 |
" |
|
228 |
super addAll:aListOfItems beforeIndex:anIndex |
|
229 |
! |
|
230 |
||
231 |
itemChanged:what with:aPara from:anItem |
|
232 |
"catch notification from item; throw changeNotifications |
|
233 |
to dependencies; |
|
234 |
**** don't know what to do with a parameter and argument what |
|
235 |
**** list protocol **** |
|
236 |
" |
|
237 |
|index arrIdx "{ Class: SmallInteger }"| |
|
238 |
||
239 |
(index := super identityIndexOf:anItem) ~~ 0 ifTrue:[ |
|
240 |
arrIdx := index + firstIndex - 1. |
|
241 |
contentsArray basicAt:arrIdx put:anItem. |
|
242 |
||
243 |
dependents size ~~ 0 ifTrue:[ |
|
244 |
what isNil ifTrue:[self changed:#at: with:index] |
|
245 |
ifFalse:[self changed:#at: with:(Array with:index with:what)] |
|
246 |
] |
|
247 |
] |
|
248 |
! |
|
249 |
||
250 |
itemRemoveFromIndex:start toIndex:stop |
|
251 |
"remove the items stored under startIndex up to and including |
|
252 |
the items under stopIndex. |
|
253 |
" |
|
254 |
^ super removeFromIndex:start toIndex:stop |
|
255 |
! |
|
256 |
||
257 |
parentOrModel |
|
258 |
"always returns nil |
|
259 |
" |
|
260 |
^ nil |
|
1733 | 261 |
! |
262 |
||
263 |
recursionLock |
|
264 |
^ recursionLock |
|
265 |
||
1390 | 266 |
! ! |
267 |
||
2493 | 268 |
!HierarchicalList methodsFor:'private-monitoring task'! |
1390 | 269 |
|
1437
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
270 |
monitoringCycle |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
271 |
"the block evaluated |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
272 |
" |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
273 |
|index item| |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
274 |
|
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
275 |
item := root. |
2430 | 276 |
index := 1. "/ on default discard first entry the root |
277 |
||
278 |
root isNil ifTrue:[ |
|
279 |
item := self at:index ifAbsent:nil. |
|
280 |
] ifFalse:[ |
|
281 |
self showRoot ifFalse:[ |
|
282 |
index := 0 "/ read list from begin |
|
283 |
] |
|
284 |
]. |
|
1437
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
285 |
|
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
286 |
[item notNil] whileTrue:[ |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
287 |
item monitoringCycle. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
288 |
Processor yield. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
289 |
index := index + 1. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
290 |
item := self at:index ifAbsent:nil. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
291 |
] |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
292 |
! |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
293 |
|
1390 | 294 |
startMonitoringTask |
2223
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
295 |
"start the monitoring task; backgrund process finishes, when no (more) dependencies exist, |
2743 | 296 |
and the additionalItemsToMonitorSemaphore is not signalled |
297 |
(aka: no more background children to read)" |
|
298 |
||
1439
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
299 |
|name| |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
300 |
|
2744
21b90562122b
Fix monitoring task starting (bug introduced in last version)
Stefan Vogel <sv@exept.de>
parents:
2743
diff
changeset
|
301 |
(monitoringTask isNil |
21b90562122b
Fix monitoring task starting (bug introduced in last version)
Stefan Vogel <sv@exept.de>
parents:
2743
diff
changeset
|
302 |
and:[self monitoringTaskDelay notNil |
2743 | 303 |
and:[(dependents size ~~ 0) or:[additionalItemsToMonitorSemaphore notNil]]] |
1390 | 304 |
) ifTrue:[ |
3832 | 305 |
monitoringTask := |
306 |
[ |
|
307 |
[(dependents size ~~ 0) or:[additionalItemsToMonitorSemaphore notNil]] whileTrue:[ |
|
308 |
self monitoringCycle. |
|
309 |
additionalItemsToMonitorSemaphore isNil ifTrue:[ |
|
310 |
Delay waitForSeconds:self monitoringTaskDelay |
|
311 |
] ifFalse:[ |
|
312 |
additionalItemsToMonitorSemaphore waitWithTimeout:self monitoringTaskDelay. |
|
313 |
] |
|
314 |
]. |
|
315 |
] newProcess. |
|
2273 | 316 |
|
317 |
monitoringTask priorityRange:(Processor userBackgroundPriority to:Processor activePriority). |
|
2412 | 318 |
monitoringTask restartable:true. |
2273 | 319 |
monitoringTask resume. |
1437
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
320 |
|
1439
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
321 |
name := application notNil ifTrue:[application class name] ifFalse:['???']. |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
322 |
monitoringTask name:'HierarchicalList: ', name. |
1390 | 323 |
]. |
324 |
^ true. |
|
325 |
! |
|
326 |
||
327 |
stopMonitoringTask |
|
2743 | 328 |
"stop the monitoring task" |
329 |
||
1616 | 330 |
|task| |
331 |
||
332 |
(task := monitoringTask) notNil ifTrue:[ |
|
1390 | 333 |
monitoringTask := nil. |
1616 | 334 |
|
3832 | 335 |
Error |
336 |
handle:[:ex| ] |
|
337 |
do:[ |
|
338 |
task terminateWithAllSubprocessesInGroup. |
|
339 |
task waitUntilTerminated. |
|
340 |
] |
|
1390 | 341 |
] |
2223
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
342 |
! |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
343 |
|
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
344 |
triggerUpdateCycle |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
345 |
additionalItemsToMonitorSemaphore isNil ifTrue:[ |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
346 |
[ |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
347 |
additionalItemsToMonitorSemaphore isNil ifTrue:[ |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
348 |
additionalItemsToMonitorSemaphore := Semaphore new. |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
349 |
]. |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
350 |
] valueUninterruptably |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
351 |
]. |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
352 |
|
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
353 |
monitoringTaskDelay isNil ifTrue:[ |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
354 |
monitoringTaskDelay := 10 |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
355 |
]. |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
356 |
|
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
357 |
additionalItemsToMonitorSemaphore signalOnce. |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
358 |
self startMonitoringTask. |
1390 | 359 |
! ! |
360 |
||
361 |
!HierarchicalList methodsFor:'protocol'! |
|
362 |
||
363 |
childrenFor:anItem |
|
364 |
"returns the children for an item or an empty list |
|
365 |
" |
|
366 |
^ #() |
|
367 |
! |
|
368 |
||
369 |
iconFor:anItem |
|
370 |
"returns the icon for an item or nil |
|
371 |
" |
|
372 |
^ nil |
|
373 |
! |
|
374 |
||
375 |
labelFor:anItem |
|
3848 | 376 |
"returns the label for an item or nil" |
377 |
||
1390 | 378 |
^ nil |
379 |
! |
|
380 |
||
381 |
middleButtonMenuFor:anItem |
|
382 |
"returns the middleButton menu for an item or nil |
|
383 |
" |
|
384 |
^ nil |
|
385 |
||
386 |
||
387 |
! ! |
|
388 |
||
389 |
!HierarchicalList class methodsFor:'documentation'! |
|
390 |
||
391 |
version |
|
5216 | 392 |
^ '$Header$' |
3832 | 393 |
! |
394 |
||
395 |
version_CVS |
|
5216 | 396 |
^ '$Header$' |
1390 | 397 |
! ! |
4676 | 398 |