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