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