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 |
|
69
|
13 |
ProtocolAdaptor subclass:#AspectAdaptor
|
|
14 |
instanceVariableNames:'myAspect getMsg putMsg'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
71
|
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 |
version
|
|
37 |
"
|
85
|
38 |
$Header: /cvs/stx/stx/libview2/AspectAdaptor.st,v 1.5 1995-07-23 02:25:16 claus Exp $
|
69
|
39 |
"
|
|
40 |
!
|
|
41 |
|
|
42 |
documentation
|
|
43 |
"
|
|
44 |
an AspectAdaptor forwards updates and change messages
|
|
45 |
from/to a complex model.
|
|
46 |
|
|
47 |
Consider the case where editFields are required for the
|
|
48 |
elements (instance variables) of a more complex model.
|
|
49 |
Without an aspect adaptor, you needed to copy the individual
|
|
50 |
values out-of and into multiple valueHolders.
|
|
51 |
An aspectAdaptor makes this easier, by playing model with
|
85
|
52 |
value/value: symbols towards the editField, and forwarding changes and
|
69
|
53 |
updates to/from the complex model using different aspect symbols.
|
|
54 |
|
|
55 |
Notice: this class was implemented using protocol information
|
|
56 |
from alpha testers and PD code - it may not be complete or compatible to
|
|
57 |
the corresponding ST-80 class. If you encounter any incompatibilities,
|
|
58 |
please forward a note to the ST/X team.
|
|
59 |
"
|
|
60 |
!
|
|
61 |
|
|
62 |
examples
|
|
63 |
"
|
|
64 |
a dialog on a points x/y coordinates:
|
|
65 |
|
|
66 |
|dialog data f|
|
|
67 |
|
|
68 |
data := 0@0.
|
|
69 |
|
|
70 |
dialog := DialogBox new.
|
|
71 |
dialog addTextLabel:'x:'.
|
|
72 |
f := dialog addInputFieldOn:(AspectAdaptor new
|
|
73 |
subject:data;
|
|
74 |
accessWith:#x
|
|
75 |
assignWith:#x:).
|
|
76 |
f converter:(PrintConverter new initForNumber).
|
|
77 |
|
|
78 |
dialog addTextLabel:'y:'.
|
|
79 |
f := dialog addInputFieldOn:(AspectAdaptor new
|
|
80 |
subject:data;
|
|
81 |
forAspect:#y).
|
|
82 |
f converter:(PrintConverter new initForNumber).
|
|
83 |
|
|
84 |
dialog addOkButton.
|
|
85 |
data inspect.
|
|
86 |
dialog open.
|
|
87 |
|
|
88 |
dialog accepted ifTrue:[
|
|
89 |
Transcript showCr:'data now: ' , data printString
|
|
90 |
]
|
|
91 |
|
|
92 |
|
|
93 |
a dialog on a four-field complex model:
|
|
94 |
|
|
95 |
|
|
96 |
|dialog data dataModel|
|
|
97 |
|
|
98 |
data := #('hello' 'one' 'two' 'three').
|
|
99 |
dataModel := Plug new.
|
|
100 |
dataModel respondTo:#field1 with:[data at:1].
|
|
101 |
dataModel respondTo:#field2 with:[data at:2].
|
|
102 |
dataModel respondTo:#field3 with:[data at:3].
|
|
103 |
dataModel respondTo:#field4 with:[data at:4].
|
|
104 |
dataModel respondTo:#field1: with:[:arg | data at:1 put:arg].
|
|
105 |
dataModel respondTo:#field2: with:[:arg | data at:2 put:arg].
|
|
106 |
dataModel respondTo:#field3: with:[:arg | data at:3 put:arg].
|
|
107 |
dataModel respondTo:#field4: with:[:arg | data at:4 put:arg].
|
|
108 |
|
|
109 |
dialog := DialogBox new.
|
|
110 |
dialog addTextLabel:'1:'.
|
|
111 |
dialog addInputFieldOn:(AspectAdaptor new
|
|
112 |
subject:dataModel;
|
|
113 |
accessWith:#field1
|
|
114 |
assignWith:#field1:).
|
|
115 |
dialog addTextLabel:'2:'.
|
|
116 |
dialog addInputFieldOn:(AspectAdaptor new
|
|
117 |
subject:dataModel;
|
|
118 |
forAspect:#field2).
|
|
119 |
dialog addTextLabel:'3:'.
|
|
120 |
dialog addInputFieldOn:(AspectAdaptor new
|
|
121 |
subject:dataModel;
|
|
122 |
accessWith:#field3
|
|
123 |
assignWith:#field3:
|
|
124 |
aspect:#field3).
|
|
125 |
dialog addTextLabel:'4:'.
|
|
126 |
dialog addInputFieldOn:(AspectAdaptor new
|
|
127 |
subject:dataModel;
|
|
128 |
forAspect:#field4).
|
|
129 |
dialog addOkButton.
|
|
130 |
dataModel inspect.
|
|
131 |
dialog open.
|
|
132 |
dialog accepted ifTrue:[
|
|
133 |
Transcript showCr:'data now: ' , data printString
|
|
134 |
]
|
|
135 |
"
|
|
136 |
! !
|
|
137 |
|
|
138 |
!AspectAdaptor class methodsFor:'instance creation'!
|
|
139 |
|
|
140 |
accessWith:getSelector assignWith:putSelector
|
83
|
141 |
"create and return an adaptor which uses getSelector to fetch a value
|
|
142 |
and setSelector to change it."
|
|
143 |
|
69
|
144 |
^ (self new) accessWith:getSelector assignWith:putSelector
|
85
|
145 |
!
|
|
146 |
|
|
147 |
subject:anObject sendsUpdates:aBoolean accessWith:getSel assignWith:putSel aspect:aspect
|
|
148 |
^ (self subject:anObject sendsUpdates:aBoolean)
|
|
149 |
accessWith:getSel assignWith:putSel aspect:aspect
|
69
|
150 |
! !
|
|
151 |
|
|
152 |
!AspectAdaptor methodsFor:'change & update'!
|
|
153 |
|
|
154 |
update:something with:aParameter from:changedObject
|
|
155 |
"translate an update from the model into a #value-change
|
|
156 |
via my depenedents ..."
|
|
157 |
|
|
158 |
((changedObject == subject)
|
|
159 |
or:[changedObject == subjectChannel]) ifTrue:[
|
|
160 |
something == self forAspect ifTrue:[
|
|
161 |
self changed:#value
|
|
162 |
].
|
|
163 |
^ self
|
|
164 |
].
|
|
165 |
! !
|
|
166 |
|
|
167 |
!AspectAdaptor methodsFor:'accessing-value'!
|
|
168 |
|
|
169 |
value
|
|
170 |
"translate a query for my value from my user
|
|
171 |
into an aspect access towards my subject"
|
|
172 |
|
|
173 |
|target|
|
|
174 |
|
|
175 |
target := super value.
|
|
176 |
^ target perform:getMsg
|
|
177 |
!
|
|
178 |
|
|
179 |
setValue:newValue
|
|
180 |
|target oldValue|
|
|
181 |
|
|
182 |
target := super value.
|
|
183 |
oldValue := target perform:getMsg.
|
|
184 |
oldValue ~~ newValue ifTrue:[
|
|
185 |
target perform:putMsg with:newValue.
|
|
186 |
]
|
|
187 |
!
|
|
188 |
|
|
189 |
value:newValue
|
|
190 |
|target oldValue|
|
|
191 |
|
|
192 |
target := super value.
|
|
193 |
oldValue := target perform:getMsg.
|
|
194 |
oldValue ~~ newValue ifTrue:[
|
|
195 |
target perform:putMsg with:newValue.
|
|
196 |
subjectSendsUpdates ifFalse:[
|
|
197 |
self changed:#value
|
|
198 |
]
|
|
199 |
]
|
|
200 |
! !
|
|
201 |
|
|
202 |
!AspectAdaptor methodsFor:'accessing-spec'!
|
|
203 |
|
|
204 |
forAspect
|
|
205 |
myAspect isNil ifTrue:[
|
|
206 |
^ getMsg
|
|
207 |
].
|
|
208 |
^ myAspect
|
|
209 |
!
|
|
210 |
|
|
211 |
forAspect:aSelector
|
|
212 |
getMsg := myAspect := aSelector.
|
|
213 |
putMsg := (aSelector , ':') asSymbol.
|
|
214 |
!
|
|
215 |
|
|
216 |
accessWith:getSelector assignWith:putSelector
|
83
|
217 |
"setup the recevier to use getSelector to fetch a value
|
|
218 |
and setSelector to change it."
|
|
219 |
|
69
|
220 |
getMsg := getSelector.
|
|
221 |
putMsg := putSelector
|
|
222 |
!
|
|
223 |
|
|
224 |
accessWith:getSelector assignWith:putSelector aspect:aspectSymbol
|
83
|
225 |
"setup the recevier to use getSelector to fetch a value
|
|
226 |
and setSelector to change it."
|
|
227 |
|
69
|
228 |
getMsg := getSelector.
|
|
229 |
putMsg := putSelector.
|
|
230 |
myAspect := aspectSymbol
|
|
231 |
! !
|