author | Claus Gittinger <cg@exept.de> |
Thu, 08 Jul 1999 13:26:59 +0200 | |
changeset 1437 | 3ff0d67ec0af |
parent 1431 | 0cc20a8f2f7c |
child 1439 | ddcd6e87e406 |
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 |
15 |
instanceVariableNames:'root showRoot application monitoringTask monitoringTaskDelay' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
1430 | 18 |
category:'Views-Support' |
1390 | 19 |
! |
20 |
||
21 |
!HierarchicalList class methodsFor:'documentation'! |
|
22 |
||
1431 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
||
36 |
! |
|
37 |
||
1390 | 38 |
documentation |
39 |
" |
|
40 |
Hierarchical Lists are mostly like List, but adding and removing |
|
41 |
elements are handled by the items itself. |
|
42 |
Special change notifications are emitted, whenever the list |
|
43 |
changed. |
|
44 |
||
45 |
[Instance variables:] |
|
46 |
root <HierarchicalItem> first item into list |
|
47 |
showRoot <Boolean> show or hide root item |
|
48 |
application <Application> the user is able to set an application |
|
49 |
which can be accessed by an item. |
|
50 |
[author:] |
|
51 |
Claus Atzkern |
|
52 |
||
53 |
[see also:] |
|
54 |
HierarchicalItem |
|
55 |
HierarchicalListView |
|
56 |
" |
|
57 |
||
58 |
||
59 |
! ! |
|
60 |
||
61 |
!HierarchicalList methodsFor:'accessing look'! |
|
62 |
||
63 |
showRoot |
|
64 |
"show or hide root item |
|
65 |
" |
|
66 |
^ showRoot ? true |
|
67 |
||
68 |
||
69 |
! |
|
70 |
||
71 |
showRoot:aBoolean |
|
72 |
"show or hide root item |
|
73 |
" |
|
74 |
aBoolean ~~ self showRoot ifTrue:[ |
|
75 |
showRoot := aBoolean. |
|
76 |
||
77 |
root notNil ifTrue:[ |
|
78 |
showRoot ifTrue:[super addFirst:root] |
|
79 |
ifFalse:[super removeFirst] |
|
80 |
] |
|
81 |
] |
|
82 |
||
83 |
! ! |
|
84 |
||
85 |
!HierarchicalList methodsFor:'accessing monitoring task'! |
|
86 |
||
87 |
monitoringTaskDelay |
|
88 |
"get the delay time of the monitoring task measured in seconds |
|
89 |
or nil( monitoring disabled ). The task runs through all items |
|
90 |
of the list performing #monitoringCycle and than at end of the |
|
91 |
list the task is suspended for monitoringTaskDelay seconds. |
|
92 |
" |
|
93 |
^ monitoringTaskDelay |
|
94 |
! |
|
95 |
||
96 |
monitoringTaskDelay:inSecondsOrNil |
|
97 |
"set the delay time of the monitoring task measured in seconds |
|
98 |
or nil( monitoring disabled ). The task runs through all items |
|
99 |
of the list performing #monitoringCycle and than at end of the |
|
100 |
list the task is suspended for monitoringTaskDelay seconds. |
|
101 |
" |
|
102 |
monitoringTaskDelay := inSecondsOrNil. |
|
103 |
||
104 |
inSecondsOrNil isNil ifTrue:[ |
|
105 |
self stopMonitoringTask |
|
106 |
] ifFalse:[ |
|
107 |
self startMonitoringTask |
|
108 |
]. |
|
109 |
! ! |
|
110 |
||
111 |
!HierarchicalList methodsFor:'accessing mvc'! |
|
112 |
||
113 |
application |
|
114 |
"returns the responsible application; if no application is defined, |
|
115 |
nil is returned |
|
116 |
" |
|
117 |
^ application |
|
118 |
! |
|
119 |
||
120 |
application:anApplication |
|
121 |
"set the responsible application |
|
122 |
" |
|
123 |
application := anApplication |
|
124 |
! |
|
125 |
||
126 |
applicationsDo:aOneArgBlock |
|
127 |
"evaluate the block on each dependent application |
|
128 |
" |
|
129 |
|appl| |
|
130 |
||
131 |
dependents notNil ifTrue:[ |
|
132 |
dependents do:[:aDep| |
|
133 |
appl := aDep perform:#application ifNotUnderstood:nil. |
|
134 |
||
135 |
appl notNil ifTrue:[ |
|
136 |
aOneArgBlock value:appl |
|
137 |
] |
|
138 |
] |
|
139 |
] |
|
140 |
! ! |
|
141 |
||
142 |
!HierarchicalList methodsFor:'accessing root'! |
|
143 |
||
144 |
root |
|
145 |
"get the root item |
|
146 |
" |
|
147 |
^ root |
|
148 |
||
149 |
! |
|
150 |
||
151 |
root:aRoot |
|
152 |
"set the root item |
|
153 |
" |
|
154 |
|children monitoring| |
|
155 |
||
156 |
self stopMonitoringTask. |
|
157 |
||
158 |
root notNil ifTrue:[ |
|
159 |
root parent:nil. |
|
160 |
root := nil. |
|
161 |
super removeAll. |
|
162 |
]. |
|
163 |
||
164 |
(root := aRoot) notNil ifTrue:[ |
|
165 |
root parent:self. |
|
166 |
children := OrderedCollection new. |
|
167 |
self showRoot ifTrue:[children add:root]. |
|
168 |
root addVisibleChildrenTo:children. |
|
169 |
super addAll:children beforeIndex:1 |
|
170 |
]. |
|
171 |
self startMonitoringTask. |
|
172 |
! ! |
|
173 |
||
174 |
!HierarchicalList methodsFor:'private'! |
|
175 |
||
176 |
isHierarchicalItem |
|
177 |
"used to decide if the parent is a hierarchical item |
|
178 |
or the model |
|
179 |
" |
|
180 |
^ false |
|
181 |
! |
|
182 |
||
183 |
itemAddAll:aListOfItems beforeIndex:anIndex |
|
184 |
"insert all items before an index |
|
185 |
" |
|
186 |
super addAll:aListOfItems beforeIndex:anIndex |
|
187 |
! |
|
188 |
||
189 |
itemChanged:what with:aPara from:anItem |
|
190 |
"catch notification from item; throw changeNotifications |
|
191 |
to dependencies; |
|
192 |
**** don't know what to do with a parameter and argument what |
|
193 |
**** list protocol **** |
|
194 |
" |
|
195 |
|index arrIdx "{ Class: SmallInteger }"| |
|
196 |
||
197 |
(index := super identityIndexOf:anItem) ~~ 0 ifTrue:[ |
|
198 |
arrIdx := index + firstIndex - 1. |
|
199 |
contentsArray basicAt:arrIdx put:anItem. |
|
200 |
||
201 |
dependents size ~~ 0 ifTrue:[ |
|
202 |
what isNil ifTrue:[self changed:#at: with:index] |
|
203 |
ifFalse:[self changed:#at: with:(Array with:index with:what)] |
|
204 |
] |
|
205 |
] |
|
206 |
! |
|
207 |
||
208 |
itemRemoveFromIndex:start toIndex:stop |
|
209 |
"remove the items stored under startIndex up to and including |
|
210 |
the items under stopIndex. |
|
211 |
" |
|
212 |
^ super removeFromIndex:start toIndex:stop |
|
213 |
! |
|
214 |
||
215 |
parentOrModel |
|
216 |
"always returns nil |
|
217 |
" |
|
218 |
^ nil |
|
219 |
! ! |
|
220 |
||
221 |
!HierarchicalList methodsFor:'private monitoring task'! |
|
222 |
||
223 |
addDependent:anObject |
|
224 |
"restart the monitoringTask if neccessary |
|
225 |
" |
|
226 |
super addDependent:anObject. |
|
227 |
self startMonitoringTask. |
|
228 |
||
229 |
! |
|
230 |
||
1437
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
231 |
monitoringCycle |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
232 |
"the block evaluated |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
233 |
" |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
234 |
|index item| |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
235 |
|
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
236 |
item := root. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
237 |
index := showRoot ifTrue:[1] ifFalse:[0]. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
238 |
|
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
239 |
[item notNil] whileTrue:[ |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
240 |
item monitoringCycle. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
241 |
Processor yield. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
242 |
index := index + 1. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
243 |
item := self at:index ifAbsent:nil. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
244 |
] |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
245 |
! |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
246 |
|
1390 | 247 |
removeDependent:anObject |
248 |
"stop the monitoringTask if no more dependencies exists |
|
249 |
" |
|
250 |
super removeDependent:anObject. |
|
251 |
||
252 |
dependents size == 0 ifTrue:[ |
|
253 |
self stopMonitoringTask |
|
254 |
]. |
|
255 |
||
256 |
! |
|
257 |
||
258 |
startMonitoringTask |
|
259 |
"start the monitoring task; success only if dependencies exists |
|
260 |
" |
|
261 |
( monitoringTask isNil |
|
262 |
and:[monitoringTaskDelay notNil |
|
263 |
and:[dependents size ~~ 0]] |
|
264 |
) ifTrue:[ |
|
1437
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
265 |
monitoringTask := [|delay| |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
266 |
[(delay := self monitoringTaskDelay) notNil] whileTrue:[ |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
267 |
self monitoringCycle. |
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
268 |
Delay waitForSeconds:delay. |
1390 | 269 |
] |
270 |
] forkAt:4. |
|
1437
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 |
monitoringTask addExitAction:[ monitoringTask := nil ]. |
1390 | 273 |
]. |
274 |
^ true. |
|
275 |
||
276 |
! |
|
277 |
||
278 |
stopMonitoringTask |
|
279 |
"stop the monitoring task |
|
280 |
" |
|
281 |
|task| |
|
282 |
||
283 |
(task := monitoringTask) notNil ifTrue:[ |
|
284 |
monitoringTask := nil. |
|
285 |
task terminate |
|
286 |
] |
|
287 |
||
288 |
||
289 |
! ! |
|
290 |
||
291 |
!HierarchicalList methodsFor:'protocol'! |
|
292 |
||
293 |
childrenFor:anItem |
|
294 |
"returns the children for an item or an empty list |
|
295 |
" |
|
296 |
^ #() |
|
297 |
! |
|
298 |
||
299 |
iconFor:anItem |
|
300 |
"returns the icon for an item or nil |
|
301 |
" |
|
302 |
^ nil |
|
303 |
! |
|
304 |
||
305 |
labelFor:anItem |
|
306 |
"returns the label for an item or nil |
|
307 |
" |
|
308 |
^ nil |
|
309 |
||
310 |
||
311 |
! |
|
312 |
||
313 |
middleButtonMenuFor:anItem |
|
314 |
"returns the middleButton menu for an item or nil |
|
315 |
" |
|
316 |
^ nil |
|
317 |
||
318 |
||
319 |
! ! |
|
320 |
||
321 |
!HierarchicalList class methodsFor:'documentation'! |
|
322 |
||
323 |
version |
|
1437
3ff0d67ec0af
separate monitoringCycle from startMonitoringCycle
Claus Gittinger <cg@exept.de>
parents:
1431
diff
changeset
|
324 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalList.st,v 1.4 1999-07-08 11:26:59 cg Exp $' |
1390 | 325 |
! ! |