74
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
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 |
|
125
|
13 |
ProtocolAdaptor subclass:#AspectAdaptor
|
217
|
14 |
instanceVariableNames:'myAspect getMsg putMsg'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Interface-Support-Models'
|
69
|
18 |
!
|
|
19 |
|
|
20 |
!AspectAdaptor class methodsFor:'documentation'!
|
|
21 |
|
|
22 |
copyright
|
|
23 |
"
|
|
24 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
71
|
25 |
All Rights Reserved
|
69
|
26 |
|
|
27 |
This software is furnished under a license and may be used
|
|
28 |
only in accordance with the terms of that license and with the
|
|
29 |
inclusion of the above copyright notice. This software may not
|
|
30 |
be provided or otherwise made available to, or used by, any
|
|
31 |
other person. No title to or ownership of the software is
|
|
32 |
hereby transferred.
|
|
33 |
"
|
|
34 |
!
|
|
35 |
|
|
36 |
documentation
|
|
37 |
"
|
|
38 |
an AspectAdaptor forwards updates and change messages
|
|
39 |
from/to a complex model.
|
|
40 |
|
|
41 |
Consider the case where editFields are required for the
|
789
|
42 |
elements (instance variables) of a compound object:
|
238
|
43 |
- without an aspect adaptor, you needed to copy the individual
|
|
44 |
values out-of the object and move these into multiple valueHolders.
|
|
45 |
Then, let the editFields modify the valueHolders contents and
|
|
46 |
finally, fetch the values and put them back into the compound object.
|
|
47 |
|
69
|
48 |
An aspectAdaptor makes this easier, by playing model with
|
85
|
49 |
value/value: symbols towards the editField, and forwarding changes and
|
789
|
50 |
updates to/from the compound object using different aspect symbols
|
238
|
51 |
and access messages.
|
69
|
52 |
|
231
|
53 |
Notice:
|
|
54 |
this class was implemented using protocol information
|
|
55 |
from alpha testers - it may not be complete or compatible to
|
|
56 |
the corresponding ST-80 class.
|
|
57 |
If you encounter any incompatibilities, please forward a note
|
|
58 |
describing the incompatibility verbal (i.e. no code) to the ST/X team.
|
217
|
59 |
|
223
|
60 |
[author:]
|
|
61 |
Claus Gittinger
|
|
62 |
|
217
|
63 |
[see also:]
|
|
64 |
ValueHolder Model
|
69
|
65 |
"
|
|
66 |
!
|
|
67 |
|
|
68 |
examples
|
|
69 |
"
|
|
70 |
a dialog on a points x/y coordinates:
|
231
|
71 |
[exBegin]
|
|
72 |
|dialog data f|
|
69
|
73 |
|
231
|
74 |
data := 0@0.
|
69
|
75 |
|
231
|
76 |
dialog := DialogBox new.
|
|
77 |
dialog addTextLabel:'x:'.
|
|
78 |
f := dialog addInputFieldOn:(AspectAdaptor new
|
|
79 |
subject:data;
|
|
80 |
accessWith:#x
|
|
81 |
assignWith:#x:).
|
|
82 |
f converter:(PrintConverter new initForNumber).
|
69
|
83 |
|
231
|
84 |
dialog addTextLabel:'y:'.
|
|
85 |
f := dialog addInputFieldOn:(AspectAdaptor new
|
|
86 |
subject:data;
|
|
87 |
forAspect:#y).
|
|
88 |
f converter:(PrintConverter new initForNumber).
|
69
|
89 |
|
231
|
90 |
dialog addOkButton.
|
|
91 |
data inspect.
|
|
92 |
dialog open.
|
69
|
93 |
|
231
|
94 |
dialog accepted ifTrue:[
|
268
|
95 |
Transcript showCR:'data now: ' , data printString
|
231
|
96 |
]
|
|
97 |
[exEnd]
|
69
|
98 |
|
|
99 |
|
|
100 |
a dialog on a four-field complex model:
|
231
|
101 |
[exBegin]
|
|
102 |
|dialog data dataModel|
|
69
|
103 |
|
231
|
104 |
data := #('hello' 'one' 'two' 'three').
|
|
105 |
dataModel := Plug new.
|
|
106 |
dataModel respondTo:#field1 with:[data at:1].
|
|
107 |
dataModel respondTo:#field2 with:[data at:2].
|
|
108 |
dataModel respondTo:#field3 with:[data at:3].
|
|
109 |
dataModel respondTo:#field4 with:[data at:4].
|
|
110 |
dataModel respondTo:#field1: with:[:arg | data at:1 put:arg].
|
|
111 |
dataModel respondTo:#field2: with:[:arg | data at:2 put:arg].
|
|
112 |
dataModel respondTo:#field3: with:[:arg | data at:3 put:arg].
|
|
113 |
dataModel respondTo:#field4: with:[:arg | data at:4 put:arg].
|
69
|
114 |
|
231
|
115 |
dialog := DialogBox new.
|
|
116 |
dialog addTextLabel:'1:'.
|
|
117 |
dialog addInputFieldOn:(AspectAdaptor new
|
|
118 |
subject:dataModel;
|
|
119 |
accessWith:#field1
|
|
120 |
assignWith:#field1:).
|
|
121 |
dialog addTextLabel:'2:'.
|
|
122 |
dialog addInputFieldOn:(AspectAdaptor new
|
|
123 |
subject:dataModel;
|
|
124 |
forAspect:#field2).
|
|
125 |
dialog addTextLabel:'3:'.
|
|
126 |
dialog addInputFieldOn:(AspectAdaptor new
|
|
127 |
subject:dataModel;
|
|
128 |
accessWith:#field3
|
|
129 |
assignWith:#field3:
|
|
130 |
aspect:#field3).
|
|
131 |
dialog addTextLabel:'4:'.
|
|
132 |
dialog addInputFieldOn:(AspectAdaptor new
|
|
133 |
subject:dataModel;
|
|
134 |
forAspect:#field4).
|
|
135 |
dialog addOkButton.
|
|
136 |
dataModel inspect.
|
|
137 |
dialog open.
|
|
138 |
dialog accepted ifTrue:[
|
268
|
139 |
Transcript showCR:'data now: ' , data printString
|
231
|
140 |
]
|
|
141 |
[exEnd]
|
69
|
142 |
"
|
|
143 |
! !
|
|
144 |
|
|
145 |
!AspectAdaptor class methodsFor:'instance creation'!
|
|
146 |
|
|
147 |
accessWith:getSelector assignWith:putSelector
|
83
|
148 |
"create and return an adaptor which uses getSelector to fetch a value
|
|
149 |
and setSelector to change it."
|
|
150 |
|
69
|
151 |
^ (self new) accessWith:getSelector assignWith:putSelector
|
85
|
152 |
!
|
|
153 |
|
439
|
154 |
forAspect:anAspect
|
|
155 |
"create and return a new adaptor, which forwards requests
|
|
156 |
to anObject, using anAspect as get-selector and anAspect-colon as putSelector
|
|
157 |
for access. The returned object can be used in place of a ValueHolder"
|
|
158 |
|
|
159 |
^ self new forAspect:anAspect
|
|
160 |
|
|
161 |
"Modified: 22.1.1997 / 12:00:42 / cg"
|
|
162 |
!
|
|
163 |
|
85
|
164 |
subject:anObject sendsUpdates:aBoolean accessWith:getSel assignWith:putSel aspect:aspect
|
379
|
165 |
"create and return a new adaptor, which forwards requests
|
|
166 |
to anObject, using getSel/putSel for access.
|
|
167 |
The returned object can be used in place of a ValueHolder"
|
|
168 |
|
85
|
169 |
^ (self subject:anObject sendsUpdates:aBoolean)
|
379
|
170 |
accessWith:getSel assignWith:putSel aspect:aspect
|
|
171 |
|
|
172 |
"Modified: 22.1.1997 / 12:00:42 / cg"
|
69
|
173 |
! !
|
|
174 |
|
125
|
175 |
!AspectAdaptor methodsFor:'accessing-spec'!
|
|
176 |
|
|
177 |
accessWith:getSelector assignWith:putSelector
|
|
178 |
"setup the recevier to use getSelector to fetch a value
|
381
|
179 |
and putSelector to change it."
|
125
|
180 |
|
|
181 |
getMsg := getSelector.
|
|
182 |
putMsg := putSelector
|
381
|
183 |
|
|
184 |
"Modified: 22.1.1997 / 18:28:46 / cg"
|
125
|
185 |
!
|
|
186 |
|
|
187 |
accessWith:getSelector assignWith:putSelector aspect:aspectSymbol
|
|
188 |
"setup the recevier to use getSelector to fetch a value
|
381
|
189 |
and putSelector to change it."
|
125
|
190 |
|
|
191 |
getMsg := getSelector.
|
|
192 |
putMsg := putSelector.
|
|
193 |
myAspect := aspectSymbol
|
381
|
194 |
|
|
195 |
"Modified: 22.1.1997 / 18:28:51 / cg"
|
125
|
196 |
!
|
|
197 |
|
409
|
198 |
aspect:aSelector
|
|
199 |
"set the adapters change aspect - this is the aspect of the update message,
|
|
200 |
on which the adaptor reacts"
|
|
201 |
|
|
202 |
myAspect := aSelector.
|
|
203 |
!
|
|
204 |
|
125
|
205 |
forAspect
|
381
|
206 |
"get the adapters aspect - if none was defined, the getMsg is returned"
|
|
207 |
|
125
|
208 |
myAspect isNil ifTrue:[
|
381
|
209 |
^ getMsg
|
125
|
210 |
].
|
|
211 |
^ myAspect
|
381
|
212 |
|
|
213 |
"Modified: 22.1.1997 / 18:27:24 / cg"
|
125
|
214 |
!
|
|
215 |
|
|
216 |
forAspect:aSelector
|
381
|
217 |
"set the adapters aspect - this sets both the get- and put-Messages
|
|
218 |
(the putMessage is the aspect with a colon)"
|
|
219 |
|
125
|
220 |
getMsg := myAspect := aSelector.
|
|
221 |
putMsg := (aSelector , ':') asSymbol.
|
381
|
222 |
|
|
223 |
"Modified: 22.1.1997 / 18:29:05 / cg"
|
125
|
224 |
! !
|
|
225 |
|
|
226 |
!AspectAdaptor methodsFor:'accessing-value'!
|
|
227 |
|
|
228 |
setValue:newValue
|
381
|
229 |
"set the value - this forwards a putMessage to the target"
|
|
230 |
|
125
|
231 |
|target oldValue|
|
|
232 |
|
|
233 |
target := super value.
|
|
234 |
oldValue := target perform:getMsg.
|
|
235 |
oldValue ~~ newValue ifTrue:[
|
381
|
236 |
target perform:putMsg with:newValue.
|
125
|
237 |
]
|
381
|
238 |
|
|
239 |
"Modified: 22.1.1997 / 18:28:40 / cg"
|
125
|
240 |
!
|
|
241 |
|
|
242 |
value
|
|
243 |
"translate a query for my value from my user
|
|
244 |
into an aspect access towards my subject"
|
|
245 |
|
|
246 |
|target|
|
|
247 |
|
|
248 |
target := super value.
|
409
|
249 |
target isNil ifTrue:[^ nil].
|
125
|
250 |
^ target perform:getMsg
|
|
251 |
!
|
|
252 |
|
|
253 |
value:newValue
|
381
|
254 |
"set the value - this forwards a putMessage to the target
|
|
255 |
and sends out a changeNotification if the value did really change."
|
|
256 |
|
125
|
257 |
|target oldValue|
|
|
258 |
|
|
259 |
target := super value.
|
|
260 |
oldValue := target perform:getMsg.
|
|
261 |
oldValue ~~ newValue ifTrue:[
|
381
|
262 |
target perform:putMsg with:newValue.
|
|
263 |
subjectSendsUpdates ifFalse:[
|
|
264 |
self changed:#value
|
|
265 |
]
|
125
|
266 |
]
|
381
|
267 |
|
|
268 |
"Modified: 22.1.1997 / 18:29:59 / cg"
|
125
|
269 |
! !
|
|
270 |
|
69
|
271 |
!AspectAdaptor methodsFor:'change & update'!
|
|
272 |
|
|
273 |
update:something with:aParameter from:changedObject
|
|
274 |
"translate an update from the model into a #value-change
|
|
275 |
via my depenedents ..."
|
|
276 |
|
448
|
277 |
((changedObject == subject and:[something == self forAspect])
|
69
|
278 |
or:[changedObject == subjectChannel]) ifTrue:[
|
448
|
279 |
self changed:#value
|
69
|
280 |
].
|
|
281 |
! !
|
|
282 |
|
129
|
283 |
!AspectAdaptor class methodsFor:'documentation'!
|
|
284 |
|
|
285 |
version
|
789
|
286 |
^ '$Header: /cvs/stx/stx/libview2/AspectAdaptor.st,v 1.20 1998-01-29 14:46:38 stefan Exp $'
|
129
|
287 |
! !
|