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