139 dialog open. |
141 dialog open. |
140 dialog accepted ifTrue:[ |
142 dialog accepted ifTrue:[ |
141 Transcript showCR:'data now: ' , data printString |
143 Transcript showCR:'data now: ' , data printString |
142 ] |
144 ] |
143 [exEnd] |
145 [exEnd] |
|
146 |
|
147 a dialog on elements of a dictionary: |
|
148 (notice: the dicationary elements change as soon as a field of the dialog is |
|
149 left - i.e. I write immediately to the model) |
|
150 [exBegin] |
|
151 |dialog data| |
|
152 |
|
153 data := JSONObject new |
|
154 at:'Name' put:'Fritz'; |
|
155 at:'Tel' put:'1234567'; |
|
156 at:'City' put:'Stuttgart'; |
|
157 yourself. |
|
158 |
|
159 dialog := DialogBox new. |
|
160 dialog addTextLabel:'Name:'. |
|
161 dialog addInputFieldOn:(AspectAdaptor new |
|
162 subject:data; |
|
163 accessWith:#Name |
|
164 assignWith:#Name:). |
|
165 dialog addTextLabel:'Tel:'. |
|
166 dialog addInputFieldOn:(AspectAdaptor new |
|
167 subject:data; |
|
168 forAspect:#Tel). |
|
169 dialog addTextLabel:'City:'. |
|
170 dialog addInputFieldOn:(AspectAdaptor new |
|
171 subject:data; |
|
172 forAspect:#City). |
|
173 dialog addOkButton. |
|
174 data inspect. |
|
175 dialog open. |
|
176 dialog accepted ifTrue:[ |
|
177 Transcript showCR:'data now: ' , data printString |
|
178 ] |
|
179 [exEnd] |
144 " |
180 " |
145 ! ! |
181 ! ! |
146 |
182 |
147 !AspectAdaptor class methodsFor:'instance creation'! |
183 !AspectAdaptor class methodsFor:'instance creation'! |
148 |
184 |
149 accessWith:getSelector assignWith:putSelector |
185 accessWith:getSelector assignWith:putSelector |
150 "create and return an adaptor which uses getSelector to fetch a value |
186 "create and return an adaptor which uses getSelector to fetch a value |
151 and setSelector to change it." |
187 from the subject and setSelector to change it. |
|
188 The returned object can be used in place of a ValueHolder" |
152 |
189 |
153 ^ (self new) accessWith:getSelector assignWith:putSelector |
190 ^ (self new) accessWith:getSelector assignWith:putSelector |
|
191 |
|
192 "Modified (comment): / 25-07-2022 / 08:21:28 / cg" |
154 ! |
193 ! |
155 |
194 |
156 forAspect:anAspect |
195 forAspect:anAspect |
157 "create and return a new adaptor, which forwards requests |
196 "create and return a new adaptor, which forwards requests |
|
197 to the subject, using anAspect as get-selector and anAspect-colon as putSelector |
|
198 for access. |
|
199 The returned object can be used in place of a ValueHolder" |
|
200 |
|
201 ^ self new forAspect:anAspect |
|
202 |
|
203 "Modified: / 22-01-1997 / 12:00:42 / cg" |
|
204 "Modified (comment): / 25-07-2022 / 08:20:55 / cg" |
|
205 ! |
|
206 |
|
207 forAspect:anAspect subject:anObject |
|
208 "create and return a new adaptor, which forwards requests |
158 to anObject, using anAspect as get-selector and anAspect-colon as putSelector |
209 to anObject, using anAspect as get-selector and anAspect-colon as putSelector |
159 for access. The returned object can be used in place of a ValueHolder" |
210 for access. |
160 |
211 The returned object can be used in place of a ValueHolder" |
161 ^ self new forAspect:anAspect |
212 |
162 |
213 ^ (self new forAspect:anAspect) subject:anObject |
163 "Modified: 22.1.1997 / 12:00:42 / cg" |
214 |
|
215 "Created: / 25-07-2022 / 08:20:17 / cg" |
|
216 ! |
|
217 |
|
218 forAspect:anAspect subjectChannel:aSubjectProvider |
|
219 "create and return a new adaptor, which forwards requests |
|
220 to the object provided by aSubjectProvider, |
|
221 accessing the subject via #value from aSubjectProvider. |
|
222 using anAspect as get-selector and anAspect-colon as putSelector for access. |
|
223 The returned object can be used in place of a ValueHolder" |
|
224 |
|
225 ^ (self new forAspect:anAspect) subjectChannel:aSubjectProvider |
|
226 |
|
227 "Created: / 25-07-2022 / 08:22:33 / cg" |
164 ! |
228 ! |
165 |
229 |
166 subject:anObject sendsUpdates:aBoolean accessWith:getSel assignWith:putSel aspect:aspect |
230 subject:anObject sendsUpdates:aBoolean accessWith:getSel assignWith:putSel aspect:aspect |
167 "create and return a new adaptor, which forwards requests |
231 "create and return a new adaptor, which forwards requests |
168 to anObject, using getSel/putSel for access. |
232 to anObject, using getSel/putSel for access. |
196 |
260 |
197 "Modified: 22.1.1997 / 18:28:51 / cg" |
261 "Modified: 22.1.1997 / 18:28:51 / cg" |
198 ! |
262 ! |
199 |
263 |
200 aspect:aSelector |
264 aspect:aSelector |
201 "set the adapters change aspect - this is the aspect of the update message, |
265 "set the adaptor's change aspect - this is the aspect of the update message, |
202 on which the adaptor reacts" |
266 on which the adaptor reacts" |
203 |
267 |
204 myAspect := aSelector. |
268 myAspect := aSelector. |
|
269 |
|
270 "Modified (comment): / 25-07-2022 / 08:19:45 / cg" |
205 ! |
271 ! |
206 |
272 |
207 forAspect |
273 forAspect |
208 "get the adapters aspect - if none was defined, the getMsg is returned" |
274 "get the adaptor's aspect - if none was defined, the getMsg is returned" |
209 |
275 |
210 myAspect isNil ifTrue:[ |
276 myAspect isNil ifTrue:[ |
211 ^ getMsg |
277 ^ getMsg |
212 ]. |
278 ]. |
213 ^ myAspect |
279 ^ myAspect |
214 |
280 |
215 "Modified: 22.1.1997 / 18:27:24 / cg" |
281 "Modified: / 22-01-1997 / 18:27:24 / cg" |
|
282 "Modified (comment): / 25-07-2022 / 08:19:53 / cg" |
216 ! |
283 ! |
217 |
284 |
218 forAspect:aSelector |
285 forAspect:aSelector |
219 "set the adapters aspect - this sets both the get- and put-Messages |
286 "set the adaptor's aspect - this sets both the get- and put-Messages |
220 (the putMessage is the aspect with a colon)" |
287 (the putMessage is the aspect with a colon)" |
221 |
288 |
222 getMsg := myAspect := aSelector. |
289 getMsg := myAspect := aSelector. |
223 putMsg := aSelector asMutator. |
290 putMsg := aSelector asMutator. |
224 |
291 |
225 "Modified: 22.1.1997 / 18:29:05 / cg" |
292 "Modified: / 22-01-1997 / 18:29:05 / cg" |
|
293 "Modified (comment): / 25-07-2022 / 08:19:49 / cg" |
226 ! ! |
294 ! ! |
227 |
295 |
228 !AspectAdaptor methodsFor:'accessing-value'! |
296 !AspectAdaptor methodsFor:'accessing-value'! |
229 |
297 |
230 defaultValueIfNoSubject |
298 defaultValueIfNoSubject |