2415
|
1 |
"{ Package: 'stx:libview2' }"
|
|
2 |
|
|
3 |
ProtocolAdaptor subclass:#DictionaryAdaptor
|
|
4 |
instanceVariableNames:'myAspect'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Interface-Support-Models'
|
|
8 |
!
|
|
9 |
|
|
10 |
!DictionaryAdaptor class methodsFor:'documentation'!
|
|
11 |
|
|
12 |
documentation
|
|
13 |
"
|
|
14 |
Similar to AspectAdaptor, but accesses a Dictionary instead of
|
|
15 |
a classes instance variables.
|
|
16 |
|
|
17 |
[author:]
|
|
18 |
Stefan Vogel (stefan@zwerg)
|
|
19 |
|
|
20 |
[instance variables:]
|
|
21 |
|
|
22 |
[class variables:]
|
|
23 |
|
|
24 |
[see also:]
|
|
25 |
|
|
26 |
"
|
|
27 |
!
|
|
28 |
|
|
29 |
examples
|
|
30 |
"
|
|
31 |
[exBegin]
|
|
32 |
|dialog dict dataModel|
|
|
33 |
|
|
34 |
dict := Dictionary new.
|
|
35 |
dict
|
|
36 |
at:#field1 put:'hello';
|
|
37 |
at:#field2 put:'one';
|
|
38 |
at:#field3 put:'two';
|
|
39 |
at:#field4 put:'three'.
|
|
40 |
|
|
41 |
dialog := DialogBox new.
|
|
42 |
dialog addTextLabel:'1:'.
|
|
43 |
dialog addInputFieldOn:(DictionaryAdaptor new
|
|
44 |
subject:dict;
|
|
45 |
aspect:#field1).
|
|
46 |
dialog addTextLabel:'2:'.
|
|
47 |
dialog addInputFieldOn:(DictionaryAdaptor new
|
|
48 |
subject:dict;
|
|
49 |
forAspect:#field2).
|
|
50 |
dialog addTextLabel:'3:'.
|
|
51 |
dialog addInputFieldOn:(DictionaryAdaptor new
|
|
52 |
subject:dict;
|
|
53 |
aspect:#field3).
|
|
54 |
dialog addTextLabel:'4:'.
|
|
55 |
dialog addInputFieldOn:(DictionaryAdaptor new
|
|
56 |
subject:dict;
|
|
57 |
forAspect:#field4).
|
|
58 |
dialog addOkButton.
|
|
59 |
dict inspect.
|
|
60 |
dialog open.
|
|
61 |
dialog accepted ifTrue:[
|
|
62 |
Transcript showCR:'data now: ' , dict printString
|
|
63 |
]
|
|
64 |
[exEnd]
|
|
65 |
"
|
|
66 |
! !
|
|
67 |
|
|
68 |
!DictionaryAdaptor class methodsFor:'instance creation'!
|
|
69 |
|
|
70 |
forAspect:anAspect
|
|
71 |
"create and return a new adaptor, which forwards requests
|
|
72 |
to anObject, using anAspect to access a Dictionary.
|
|
73 |
The returned object can be used in place of a ValueHolder"
|
|
74 |
|
|
75 |
^ self new forAspect:anAspect
|
|
76 |
!
|
|
77 |
|
|
78 |
subject:anObject sendsUpdates:aBoolean aspect:aspect
|
|
79 |
"create and return a new adaptor, which forwards requests
|
|
80 |
to anObject, using #at:aspect and #at:aspect put: for access.
|
|
81 |
The returned object can be used in place of a ValueHolder"
|
|
82 |
|
|
83 |
^ (self subject:anObject sendsUpdates:aBoolean) aspect:aspect
|
|
84 |
! !
|
|
85 |
|
|
86 |
!DictionaryAdaptor methodsFor:'accessing-spec'!
|
|
87 |
|
|
88 |
aspect:aSelector
|
|
89 |
"set the adapters change aspect - this is the aspect of the update message,
|
|
90 |
on which the adaptor reacts"
|
|
91 |
|
|
92 |
myAspect := aSelector.
|
|
93 |
!
|
|
94 |
|
|
95 |
forAspect
|
|
96 |
"get the adapters aspect"
|
|
97 |
|
|
98 |
^ myAspect
|
|
99 |
!
|
|
100 |
|
|
101 |
forAspect:aSelector
|
|
102 |
"set the adapters aspect"
|
|
103 |
|
|
104 |
myAspect := aSelector.
|
|
105 |
! !
|
|
106 |
|
|
107 |
!DictionaryAdaptor methodsFor:'accessing-value'!
|
|
108 |
|
|
109 |
setValue:newValue
|
|
110 |
"set the value - this forwards a putMessage to the target"
|
|
111 |
|
|
112 |
|target oldValue|
|
|
113 |
|
|
114 |
target := self subjectValue.
|
|
115 |
target isNil ifTrue:[^ nil].
|
|
116 |
|
|
117 |
oldValue := target at:myAspect.
|
|
118 |
oldValue ~~ newValue ifTrue:[
|
|
119 |
target at:myAspect put:newValue.
|
|
120 |
]
|
|
121 |
!
|
|
122 |
|
|
123 |
value
|
|
124 |
"translate a query for my value from my user
|
|
125 |
into an aspect access towards my subject"
|
|
126 |
|
|
127 |
|target|
|
|
128 |
|
|
129 |
target := self subjectValue.
|
|
130 |
target isNil ifTrue:[^ nil].
|
|
131 |
^ target at:myAspect ifAbsent:[].
|
|
132 |
!
|
|
133 |
|
|
134 |
value:newValue
|
|
135 |
"set the value - this changes the target with #at:put:
|
|
136 |
and sends out a changeNotification if the value did really change."
|
|
137 |
|
|
138 |
|target oldValue|
|
|
139 |
|
|
140 |
target := self subjectValue.
|
|
141 |
target isNil ifTrue:[^ nil].
|
|
142 |
|
|
143 |
oldValue := target at:myAspect ifAbsent:[].
|
|
144 |
oldValue ~~ newValue ifTrue:[
|
|
145 |
target at:myAspect put:newValue.
|
|
146 |
subjectSendsUpdates ifFalse:[
|
|
147 |
self changed:#value
|
|
148 |
]
|
|
149 |
]
|
|
150 |
! !
|
|
151 |
|
|
152 |
!DictionaryAdaptor 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 and:[something == myAspect])
|
|
159 |
or:[changedObject == subjectChannel]) ifTrue:[
|
|
160 |
self changed:#value
|
|
161 |
].
|
|
162 |
! !
|
|
163 |
|
|
164 |
!DictionaryAdaptor class methodsFor:'documentation'!
|
|
165 |
|
|
166 |
version
|
|
167 |
^ '$Header: /cvs/stx/stx/libview2/DictionaryAdaptor.st,v 1.1 2008-04-16 17:19:29 stefan Exp $'
|
|
168 |
! !
|