author | Merge Script |
Sat, 30 Apr 2016 06:46:08 +0200 | |
branch | jv |
changeset 5037 | a991ac280740 |
parent 4676 | d793a43a8860 |
child 5216 | 50b4b75edc7b |
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 |
" |
|
4676 | 179 |
|children| |
1390 | 180 |
|
181 |
self stopMonitoringTask. |
|
182 |
||
183 |
root notNil ifTrue:[ |
|
184 |
root parent:nil. |
|
185 |
root := nil. |
|
186 |
]. |
|
187 |
||
4676 | 188 |
(root := aRoot) isEmptyOrNil ifTrue:[ |
189 |
self removeAll. |
|
190 |
] ifFalse:[ |
|
1869 | 191 |
self showRoot ifFalse:[root expand]. |
192 |
||
1390 | 193 |
root parent:self. |
194 |
children := OrderedCollection new. |
|
195 |
self showRoot ifTrue:[children add:root]. |
|
196 |
root addVisibleChildrenTo:children. |
|
4676 | 197 |
"/ self removeAll. |
198 |
"/ self addAll:children beforeIndex:1. |
|
199 |
self contents:children. |
|
1390 | 200 |
]. |
201 |
self startMonitoringTask. |
|
3070 | 202 |
|
203 |
"Modified: / 12-09-2006 / 18:22:42 / cg" |
|
1390 | 204 |
! ! |
205 |
||
206 |
!HierarchicalList methodsFor:'private'! |
|
207 |
||
2258 | 208 |
criticalDo:aBlock |
209 |
"evaluate the block in a critical region |
|
210 |
" |
|
211 |
^ recursionLock critical:aBlock |
|
212 |
! |
|
213 |
||
1733 | 214 |
initContents:aSize |
2430 | 215 |
"setup defaults |
216 |
" |
|
217 |
showRoot isNil ifTrue:[ showRoot := true ]. |
|
218 |
recursionLock isNil ifTrue:[ recursionLock := RecursionLock new ]. |
|
219 |
||
1733 | 220 |
^ super initContents:aSize. |
221 |
! |
|
222 |
||
1390 | 223 |
itemAddAll:aListOfItems beforeIndex:anIndex |
224 |
"insert all items before an index |
|
225 |
" |
|
226 |
super addAll:aListOfItems beforeIndex:anIndex |
|
227 |
! |
|
228 |
||
229 |
itemChanged:what with:aPara from:anItem |
|
230 |
"catch notification from item; throw changeNotifications |
|
231 |
to dependencies; |
|
232 |
**** don't know what to do with a parameter and argument what |
|
233 |
**** list protocol **** |
|
234 |
" |
|
235 |
|index arrIdx "{ Class: SmallInteger }"| |
|
236 |
||
237 |
(index := super identityIndexOf:anItem) ~~ 0 ifTrue:[ |
|
238 |
arrIdx := index + firstIndex - 1. |
|
239 |
contentsArray basicAt:arrIdx put:anItem. |
|
240 |
||
241 |
dependents size ~~ 0 ifTrue:[ |
|
242 |
what isNil ifTrue:[self changed:#at: with:index] |
|
243 |
ifFalse:[self changed:#at: with:(Array with:index with:what)] |
|
244 |
] |
|
245 |
] |
|
246 |
! |
|
247 |
||
248 |
itemRemoveFromIndex:start toIndex:stop |
|
249 |
"remove the items stored under startIndex up to and including |
|
250 |
the items under stopIndex. |
|
251 |
" |
|
252 |
^ super removeFromIndex:start toIndex:stop |
|
253 |
! |
|
254 |
||
255 |
parentOrModel |
|
256 |
"always returns nil |
|
257 |
" |
|
258 |
^ nil |
|
1733 | 259 |
! |
260 |
||
261 |
recursionLock |
|
262 |
^ recursionLock |
|
263 |
||
1390 | 264 |
! ! |
265 |
||
2493 | 266 |
!HierarchicalList methodsFor:'private-monitoring task'! |
1390 | 267 |
|
1437
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
268 |
monitoringCycle |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
269 |
"the block evaluated |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
270 |
" |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
271 |
|index item| |
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 |
item := root. |
2430 | 274 |
index := 1. "/ on default discard first entry the root |
275 |
||
276 |
root isNil ifTrue:[ |
|
277 |
item := self at:index ifAbsent:nil. |
|
278 |
] ifFalse:[ |
|
279 |
self showRoot ifFalse:[ |
|
280 |
index := 0 "/ read list from begin |
|
281 |
] |
|
282 |
]. |
|
1437
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
283 |
|
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
284 |
[item notNil] whileTrue:[ |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
285 |
item monitoringCycle. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
286 |
Processor yield. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
287 |
index := index + 1. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
288 |
item := self at:index ifAbsent:nil. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
289 |
] |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
290 |
! |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
291 |
|
1390 | 292 |
startMonitoringTask |
2223
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
293 |
"start the monitoring task; backgrund process finishes, when no (more) dependencies exist, |
2743 | 294 |
and the additionalItemsToMonitorSemaphore is not signalled |
295 |
(aka: no more background children to read)" |
|
296 |
||
1439
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
297 |
|name| |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
298 |
|
2744
21b90562122b
Fix monitoring task starting (bug introduced in last version)
Stefan Vogel <sv@exept.de>
parents:
2743
diff
changeset
|
299 |
(monitoringTask isNil |
21b90562122b
Fix monitoring task starting (bug introduced in last version)
Stefan Vogel <sv@exept.de>
parents:
2743
diff
changeset
|
300 |
and:[self monitoringTaskDelay notNil |
2743 | 301 |
and:[(dependents size ~~ 0) or:[additionalItemsToMonitorSemaphore notNil]]] |
1390 | 302 |
) ifTrue:[ |
3832 | 303 |
monitoringTask := |
304 |
[ |
|
305 |
[(dependents size ~~ 0) or:[additionalItemsToMonitorSemaphore notNil]] whileTrue:[ |
|
306 |
self monitoringCycle. |
|
307 |
additionalItemsToMonitorSemaphore isNil ifTrue:[ |
|
308 |
Delay waitForSeconds:self monitoringTaskDelay |
|
309 |
] ifFalse:[ |
|
310 |
additionalItemsToMonitorSemaphore waitWithTimeout:self monitoringTaskDelay. |
|
311 |
] |
|
312 |
]. |
|
313 |
] newProcess. |
|
2273 | 314 |
|
315 |
monitoringTask priorityRange:(Processor userBackgroundPriority to:Processor activePriority). |
|
2412 | 316 |
monitoringTask restartable:true. |
2273 | 317 |
monitoringTask resume. |
1437
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
318 |
|
1439
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
319 |
name := application notNil ifTrue:[application class name] ifFalse:['???']. |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
320 |
monitoringTask name:'HierarchicalList: ', name. |
1390 | 321 |
]. |
322 |
^ true. |
|
323 |
! |
|
324 |
||
325 |
stopMonitoringTask |
|
2743 | 326 |
"stop the monitoring task" |
327 |
||
1616 | 328 |
|task| |
329 |
||
330 |
(task := monitoringTask) notNil ifTrue:[ |
|
1390 | 331 |
monitoringTask := nil. |
1616 | 332 |
|
3832 | 333 |
Error |
334 |
handle:[:ex| ] |
|
335 |
do:[ |
|
336 |
task terminateWithAllSubprocessesInGroup. |
|
337 |
task waitUntilTerminated. |
|
338 |
] |
|
1390 | 339 |
] |
2223
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
340 |
! |
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 |
triggerUpdateCycle |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
343 |
additionalItemsToMonitorSemaphore isNil ifTrue:[ |
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 |
additionalItemsToMonitorSemaphore isNil ifTrue:[ |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
346 |
additionalItemsToMonitorSemaphore := Semaphore new. |
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 |
] valueUninterruptably |
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 |
|
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
351 |
monitoringTaskDelay isNil ifTrue:[ |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
352 |
monitoringTaskDelay := 10 |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
353 |
]. |
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 |
additionalItemsToMonitorSemaphore signalOnce. |
c34e7fd25e53
monitoring; delayed for directories; never for remoteDirectories
penk
parents:
1961
diff
changeset
|
356 |
self startMonitoringTask. |
1390 | 357 |
! ! |
358 |
||
359 |
!HierarchicalList methodsFor:'protocol'! |
|
360 |
||
361 |
childrenFor:anItem |
|
362 |
"returns the children for an item or an empty list |
|
363 |
" |
|
364 |
^ #() |
|
365 |
! |
|
366 |
||
367 |
iconFor:anItem |
|
368 |
"returns the icon for an item or nil |
|
369 |
" |
|
370 |
^ nil |
|
371 |
! |
|
372 |
||
373 |
labelFor:anItem |
|
3848 | 374 |
"returns the label for an item or nil" |
375 |
||
1390 | 376 |
^ nil |
377 |
! |
|
378 |
||
379 |
middleButtonMenuFor:anItem |
|
380 |
"returns the middleButton menu for an item or nil |
|
381 |
" |
|
382 |
^ nil |
|
383 |
||
384 |
||
385 |
! ! |
|
386 |
||
387 |
!HierarchicalList class methodsFor:'documentation'! |
|
388 |
||
389 |
version |
|
4676 | 390 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalList.st,v 1.26 2014-11-19 21:46:22 cg Exp $' |
3832 | 391 |
! |
392 |
||
393 |
version_CVS |
|
4676 | 394 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalList.st,v 1.26 2014-11-19 21:46:22 cg Exp $' |
1390 | 395 |
! ! |
4676 | 396 |