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