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