|
Class: AspectAdaptor
Object
|
+--Model
|
+--ValueModel
|
+--ProtocolAdaptor
|
+--AspectAdaptor
|
+--AspectAdaptorWithDefault
- Package:
- stx:libview2
- Category:
- Interface-Support-Models
- Version:
- rev:
1.25
date: 2016/03/25 16:07:03
- user: cg
- file: AspectAdaptor.st directory: libview2
- module: stx stc-classLibrary: libview2
- Author:
- Claus Gittinger
an AspectAdaptor forwards updates and change messages from/to a complex model.
Consider the case where editFields are required for the
elements (instance variables) of a compound object:
- without an aspect adaptor, you needed to copy the individual
values out-of the object and move these into multiple valueHolders.
Then, let the editFields modify the valueHolders contents and
finally, fetch the values and put them back into the compound object.
An aspectAdaptor makes this easier, by playing model with
value/value: symbols towards the editField, and forwarding changes and
updates to/from the compound object using different aspect symbols
and access messages.
Notice:
this class was implemented using protocol information
from alpha testers - it may not be complete or compatible to
the corresponding ST-80 class.
If you encounter any incompatibilities, please forward a note
describing the incompatibility verbal (i.e. no code) to the ST/X team.
ValueHolder
Model
instance creation
-
accessWith: getSelector assignWith: putSelector
-
create and return an adaptor which uses getSelector to fetch a value
and setSelector to change it.
-
forAspect: anAspect
-
create and return a new adaptor, which forwards requests
to anObject, using anAspect as get-selector and anAspect-colon as putSelector
for access. The returned object can be used in place of a ValueHolder
-
subject: anObject sendsUpdates: aBoolean accessWith: getSel assignWith: putSel aspect: aspect
-
create and return a new adaptor, which forwards requests
to anObject, using getSel/putSel for access.
The returned object can be used in place of a ValueHolder
accessing-spec
-
accessWith: getSelector assignWith: putSelector
-
setup the receiver to use getSelector to fetch a value
and putSelector to change it.
-
accessWith: getSelector assignWith: putSelector aspect: aspectSymbol
-
setup the receiver to use getSelector to fetch a value
and putSelector to change it.
-
aspect: aSelector
-
set the adapters change aspect - this is the aspect of the update message,
on which the adaptor reacts
-
forAspect
-
get the adapters aspect - if none was defined, the getMsg is returned
-
forAspect: aSelector
-
set the adapters aspect - this sets both the get- and put-Messages
(the putMessage is the aspect with a colon)
accessing-value
-
defaultValueIfNoSubject
-
if there is no subject (taget to provide the value),
this value is returned.
-
setValue: newValue
-
set the value - this forwards a putMessage to the target
-
value
-
translate a query for my value from my user
into an aspect access towards my subject
-
value: newValue
-
set the value - this forwards a putMessage to the target
and sends out a changeNotification if the value did really change.
change & update
-
update: something with: aParameter from: changedObject
-
translate an update from the model into a #value-change
via my depenedents ...
a dialog on a points x/y coordinates:
|dialog data f|
data := 0@0.
dialog := DialogBox new.
dialog addTextLabel:'x:'.
f := dialog addInputFieldOn:(AspectAdaptor new
subject:data;
accessWith:#x
assignWith:#x:).
f converter:(PrintConverter new initForNumber).
dialog addTextLabel:'y:'.
f := dialog addInputFieldOn:(AspectAdaptor new
subject:data;
forAspect:#y).
f converter:(PrintConverter new initForNumber).
dialog addOkButton.
data inspect.
dialog open.
dialog accepted ifTrue:[
Transcript showCR:'data now: ' , data printString
]
|
a dialog on a four-field complex model:
|dialog data dataModel|
data := #('hello' 'one' 'two' 'three').
dataModel := Plug new.
dataModel respondTo:#field1 with:[data at:1].
dataModel respondTo:#field2 with:[data at:2].
dataModel respondTo:#field3 with:[data at:3].
dataModel respondTo:#field4 with:[data at:4].
dataModel respondTo:#field1: with:[:arg | data at:1 put:arg].
dataModel respondTo:#field2: with:[:arg | data at:2 put:arg].
dataModel respondTo:#field3: with:[:arg | data at:3 put:arg].
dataModel respondTo:#field4: with:[:arg | data at:4 put:arg].
dialog := DialogBox new.
dialog addTextLabel:'1:'.
dialog addInputFieldOn:(AspectAdaptor new
subject:dataModel;
accessWith:#field1
assignWith:#field1:).
dialog addTextLabel:'2:'.
dialog addInputFieldOn:(AspectAdaptor new
subject:dataModel;
forAspect:#field2).
dialog addTextLabel:'3:'.
dialog addInputFieldOn:(AspectAdaptor new
subject:dataModel;
accessWith:#field3
assignWith:#field3:
aspect:#field3).
dialog addTextLabel:'4:'.
dialog addInputFieldOn:(AspectAdaptor new
subject:dataModel;
forAspect:#field4).
dialog addOkButton.
dataModel inspect.
dialog open.
dialog accepted ifTrue:[
Transcript showCR:'data now: ' , data printString
]
|
|