author | ca |
Tue, 03 Apr 2001 08:46:36 +0200 | |
changeset 1961 | 86effae0802b |
parent 1869 | 2d7fbc8d5429 |
child 2223 | c34e7fd25e53 |
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 |
" |
|
12 |
||
13 |
||
1751 | 14 |
"{ Package: 'stx:libwidg2' }" |
15 |
||
1390 | 16 |
List subclass:#HierarchicalList |
1733 | 17 |
instanceVariableNames:'recursionLock root showRoot application monitoringTask |
18 |
monitoringTaskDelay' |
|
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. |
|
45 |
Special change notifications are emitted, whenever the list |
|
46 |
changed. |
|
47 |
||
48 |
[Instance variables:] |
|
49 |
root <HierarchicalItem> first item into list |
|
50 |
showRoot <Boolean> show or hide root item |
|
51 |
application <Application> the user is able to set an application |
|
52 |
which can be accessed by an item. |
|
53 |
[author:] |
|
54 |
Claus Atzkern |
|
55 |
||
56 |
[see also:] |
|
57 |
HierarchicalItem |
|
58 |
HierarchicalListView |
|
59 |
" |
|
60 |
||
61 |
||
62 |
! ! |
|
63 |
||
1818 | 64 |
!HierarchicalList methodsFor:'accessing-look'! |
1390 | 65 |
|
66 |
showRoot |
|
67 |
"show or hide root item |
|
68 |
" |
|
69 |
^ showRoot ? true |
|
70 |
||
71 |
||
72 |
! |
|
73 |
||
74 |
showRoot:aBoolean |
|
75 |
"show or hide root item |
|
76 |
" |
|
77 |
aBoolean ~~ self showRoot ifTrue:[ |
|
78 |
showRoot := aBoolean. |
|
79 |
||
80 |
root notNil ifTrue:[ |
|
1869 | 81 |
showRoot ifTrue:[ |
82 |
super addFirst:root |
|
83 |
] ifFalse:[ |
|
84 |
super removeFirst. |
|
85 |
root expand |
|
86 |
] |
|
1390 | 87 |
] |
88 |
] |
|
89 |
||
90 |
! ! |
|
91 |
||
1818 | 92 |
!HierarchicalList methodsFor:'accessing-monitoring task'! |
1390 | 93 |
|
94 |
monitoringTaskDelay |
|
95 |
"get the delay time of the monitoring task measured in seconds |
|
96 |
or nil( monitoring disabled ). The task runs through all items |
|
97 |
of the list performing #monitoringCycle and than at end of the |
|
98 |
list the task is suspended for monitoringTaskDelay seconds. |
|
99 |
" |
|
100 |
^ monitoringTaskDelay |
|
101 |
! |
|
102 |
||
103 |
monitoringTaskDelay:inSecondsOrNil |
|
104 |
"set the delay time of the monitoring task measured in seconds |
|
105 |
or nil( monitoring disabled ). The task runs through all items |
|
106 |
of the list performing #monitoringCycle and than at end of the |
|
107 |
list the task is suspended for monitoringTaskDelay seconds. |
|
108 |
" |
|
109 |
inSecondsOrNil isNil ifTrue:[ |
|
1439
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
110 |
self stopMonitoringTask. |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
111 |
monitoringTaskDelay := nil. |
1390 | 112 |
] ifFalse:[ |
1439
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
113 |
monitoringTaskDelay := inSecondsOrNil. |
1390 | 114 |
self startMonitoringTask |
115 |
]. |
|
116 |
! ! |
|
117 |
||
1818 | 118 |
!HierarchicalList methodsFor:'accessing-mvc'! |
1390 | 119 |
|
1439
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
120 |
addDependent:anObject |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
121 |
"restart the monitoringTask if neccessary |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
122 |
" |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
123 |
super addDependent:anObject. |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
124 |
self startMonitoringTask. |
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 |
! |
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 |
self recursionLock. |
139 |
application := anApplication. |
|
1390 | 140 |
! |
141 |
||
142 |
applicationsDo:aOneArgBlock |
|
143 |
"evaluate the block on each dependent application |
|
144 |
" |
|
145 |
|appl| |
|
146 |
||
147 |
dependents notNil ifTrue:[ |
|
148 |
dependents do:[:aDep| |
|
149 |
appl := aDep perform:#application ifNotUnderstood:nil. |
|
150 |
||
151 |
appl notNil ifTrue:[ |
|
152 |
aOneArgBlock value:appl |
|
153 |
] |
|
154 |
] |
|
155 |
] |
|
1439
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 |
|
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
158 |
removeDependent:anObject |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
159 |
"stop the monitoringTask if no more dependencies exists |
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 |
super removeDependent:anObject. |
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 |
dependents size == 0 ifTrue:[ |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
164 |
self stopMonitoringTask |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
165 |
]. |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
166 |
|
1390 | 167 |
! ! |
168 |
||
1818 | 169 |
!HierarchicalList methodsFor:'accessing-root'! |
1390 | 170 |
|
171 |
root |
|
172 |
"get the root item |
|
173 |
" |
|
174 |
^ root |
|
175 |
||
176 |
! |
|
177 |
||
178 |
root:aRoot |
|
179 |
"set the root item |
|
180 |
" |
|
181 |
|children monitoring| |
|
182 |
||
183 |
self stopMonitoringTask. |
|
184 |
||
185 |
root notNil ifTrue:[ |
|
186 |
root parent:nil. |
|
187 |
root := nil. |
|
188 |
super removeAll. |
|
189 |
]. |
|
190 |
||
191 |
(root := aRoot) notNil ifTrue:[ |
|
1869 | 192 |
self showRoot ifFalse:[root expand]. |
193 |
||
1390 | 194 |
root parent:self. |
195 |
children := OrderedCollection new. |
|
196 |
self showRoot ifTrue:[children add:root]. |
|
197 |
root addVisibleChildrenTo:children. |
|
198 |
super addAll:children beforeIndex:1 |
|
199 |
]. |
|
200 |
self startMonitoringTask. |
|
201 |
! ! |
|
202 |
||
203 |
!HierarchicalList methodsFor:'private'! |
|
204 |
||
1733 | 205 |
initContents:aSize |
206 |
recursionLock isNil ifTrue:[ |
|
207 |
recursionLock := RecursionLock new |
|
208 |
]. |
|
209 |
^ super initContents:aSize. |
|
210 |
! |
|
211 |
||
1390 | 212 |
itemAddAll:aListOfItems beforeIndex:anIndex |
213 |
"insert all items before an index |
|
214 |
" |
|
215 |
super addAll:aListOfItems beforeIndex:anIndex |
|
216 |
! |
|
217 |
||
218 |
itemChanged:what with:aPara from:anItem |
|
219 |
"catch notification from item; throw changeNotifications |
|
220 |
to dependencies; |
|
221 |
**** don't know what to do with a parameter and argument what |
|
222 |
**** list protocol **** |
|
223 |
" |
|
224 |
|index arrIdx "{ Class: SmallInteger }"| |
|
225 |
||
226 |
(index := super identityIndexOf:anItem) ~~ 0 ifTrue:[ |
|
227 |
arrIdx := index + firstIndex - 1. |
|
228 |
contentsArray basicAt:arrIdx put:anItem. |
|
229 |
||
230 |
dependents size ~~ 0 ifTrue:[ |
|
231 |
what isNil ifTrue:[self changed:#at: with:index] |
|
232 |
ifFalse:[self changed:#at: with:(Array with:index with:what)] |
|
233 |
] |
|
234 |
] |
|
235 |
! |
|
236 |
||
237 |
itemRemoveFromIndex:start toIndex:stop |
|
238 |
"remove the items stored under startIndex up to and including |
|
239 |
the items under stopIndex. |
|
240 |
" |
|
241 |
^ super removeFromIndex:start toIndex:stop |
|
242 |
! |
|
243 |
||
244 |
parentOrModel |
|
245 |
"always returns nil |
|
246 |
" |
|
247 |
^ nil |
|
1733 | 248 |
! |
249 |
||
250 |
recursionLock |
|
251 |
^ recursionLock |
|
252 |
||
1390 | 253 |
! ! |
254 |
||
255 |
!HierarchicalList methodsFor:'private monitoring task'! |
|
256 |
||
1437
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
257 |
monitoringCycle |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
258 |
"the block evaluated |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
259 |
" |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
260 |
|index item| |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
261 |
|
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
262 |
item := root. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
263 |
index := showRoot ifTrue:[1] ifFalse:[0]. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
264 |
|
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
265 |
[item notNil] whileTrue:[ |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
266 |
item monitoringCycle. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
267 |
Processor yield. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
268 |
index := index + 1. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
269 |
item := self at:index ifAbsent:nil. |
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 |
! |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
272 |
|
1390 | 273 |
startMonitoringTask |
274 |
"start the monitoring task; success only if dependencies exists |
|
275 |
" |
|
1439
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
276 |
|name| |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
277 |
|
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
278 |
( monitoringTask isNil |
1390 | 279 |
and:[monitoringTaskDelay notNil |
280 |
and:[dependents size ~~ 0]] |
|
281 |
) ifTrue:[ |
|
1439
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
282 |
monitoringTask := [ |
1961 | 283 |
[dependents size ~~ 0] whileTrue:[ |
1437
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
284 |
self monitoringCycle. |
1439
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
285 |
Delay waitForSeconds:(self monitoringTaskDelay) |
1390 | 286 |
] |
287 |
] forkAt:4. |
|
1437
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
288 |
|
1439
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
289 |
name := application notNil ifTrue:[application class name] ifFalse:['???']. |
ddcd6e87e406
wait for termination monitoringTask before continue
Claus Gittinger <cg@exept.de>
parents:
1437
diff
changeset
|
290 |
monitoringTask name:'HierarchicalList: ', name. |
1390 | 291 |
]. |
292 |
^ true. |
|
293 |
! |
|
294 |
||
295 |
stopMonitoringTask |
|
296 |
"stop the monitoring task |
|
297 |
" |
|
1616 | 298 |
|task| |
299 |
||
300 |
(task := monitoringTask) notNil ifTrue:[ |
|
1390 | 301 |
monitoringTask := nil. |
1616 | 302 |
|
303 |
Object errorSignal handle:[:ex|]do:[ |
|
304 |
task terminateWithAllSubprocesses. |
|
305 |
task waitUntilTerminated. |
|
306 |
] |
|
1390 | 307 |
] |
308 |
! ! |
|
309 |
||
310 |
!HierarchicalList methodsFor:'protocol'! |
|
311 |
||
312 |
childrenFor:anItem |
|
313 |
"returns the children for an item or an empty list |
|
314 |
" |
|
315 |
^ #() |
|
316 |
! |
|
317 |
||
318 |
iconFor:anItem |
|
319 |
"returns the icon for an item or nil |
|
320 |
" |
|
321 |
^ nil |
|
322 |
! |
|
323 |
||
324 |
labelFor:anItem |
|
325 |
"returns the label for an item or nil |
|
326 |
" |
|
327 |
^ nil |
|
328 |
||
329 |
||
330 |
! |
|
331 |
||
332 |
middleButtonMenuFor:anItem |
|
333 |
"returns the middleButton menu for an item or nil |
|
334 |
" |
|
335 |
^ nil |
|
336 |
||
337 |
||
338 |
! ! |
|
339 |
||
340 |
!HierarchicalList class methodsFor:'documentation'! |
|
341 |
||
342 |
version |
|
1961 | 343 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalList.st,v 1.11 2001-04-03 06:46:36 ca Exp $' |
1390 | 344 |
! ! |