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 |
|
|
231 |
removeDependent:anObject
|
|
232 |
"stop the monitoringTask if no more dependencies exists
|
|
233 |
"
|
|
234 |
super removeDependent:anObject.
|
|
235 |
|
|
236 |
dependents size == 0 ifTrue:[
|
|
237 |
self stopMonitoringTask
|
|
238 |
].
|
|
239 |
|
|
240 |
!
|
|
241 |
|
|
242 |
startMonitoringTask
|
|
243 |
"start the monitoring task; success only if dependencies exists
|
|
244 |
"
|
|
245 |
|task|
|
|
246 |
|
|
247 |
( monitoringTask isNil
|
|
248 |
and:[monitoringTaskDelay notNil
|
|
249 |
and:[dependents size ~~ 0]]
|
|
250 |
) ifTrue:[
|
|
251 |
task := monitoringTask := [|index item delay|
|
|
252 |
index := showRoot ifTrue:[1] ifFalse:[0].
|
|
253 |
|
|
254 |
[true] whileTrue:[
|
|
255 |
item := index == 0 ifTrue:[root]
|
|
256 |
ifFalse:[self at:index ifAbsent:nil].
|
|
257 |
|
|
258 |
item isNil ifTrue:[
|
|
259 |
delay := self monitoringTaskDelay.
|
|
260 |
|
|
261 |
delay isNil ifTrue:[ "/ process might terminate
|
|
262 |
task ~~ monitoringTask ifTrue:[
|
|
263 |
self terminate
|
|
264 |
].
|
|
265 |
Processor yield
|
|
266 |
] ifFalse:[
|
|
267 |
Delay waitForSeconds:delay.
|
|
268 |
|
|
269 |
task ~~ monitoringTask ifTrue:[ "/ task has changed
|
|
270 |
self terminate
|
|
271 |
]
|
|
272 |
].
|
|
273 |
index := showRoot ifTrue:[1] ifFalse:[0].
|
|
274 |
] ifFalse:[
|
|
275 |
item monitoringCycle.
|
|
276 |
Processor yield.
|
|
277 |
index := index + 1.
|
|
278 |
]
|
|
279 |
]
|
|
280 |
] forkAt:4.
|
|
281 |
].
|
|
282 |
^ true.
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
!
|
|
287 |
|
|
288 |
stopMonitoringTask
|
|
289 |
"stop the monitoring task
|
|
290 |
"
|
|
291 |
|task|
|
|
292 |
|
|
293 |
(task := monitoringTask) notNil ifTrue:[
|
|
294 |
monitoringTask := nil.
|
|
295 |
task terminate
|
|
296 |
]
|
|
297 |
|
|
298 |
|
|
299 |
! !
|
|
300 |
|
|
301 |
!HierarchicalList methodsFor:'protocol'!
|
|
302 |
|
|
303 |
childrenFor:anItem
|
|
304 |
"returns the children for an item or an empty list
|
|
305 |
"
|
|
306 |
^ #()
|
|
307 |
!
|
|
308 |
|
|
309 |
iconFor:anItem
|
|
310 |
"returns the icon for an item or nil
|
|
311 |
"
|
|
312 |
^ nil
|
|
313 |
!
|
|
314 |
|
|
315 |
labelFor:anItem
|
|
316 |
"returns the label for an item or nil
|
|
317 |
"
|
|
318 |
^ nil
|
|
319 |
|
|
320 |
|
|
321 |
!
|
|
322 |
|
|
323 |
middleButtonMenuFor:anItem
|
|
324 |
"returns the middleButton menu for an item or nil
|
|
325 |
"
|
|
326 |
^ nil
|
|
327 |
|
|
328 |
|
|
329 |
! !
|
|
330 |
|
|
331 |
!HierarchicalList class methodsFor:'documentation'!
|
|
332 |
|
|
333 |
version
|
1431
|
334 |
^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalList.st,v 1.3 1999-07-06 16:49:23 cg Exp $'
|
1390
|
335 |
! !
|