author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 15 Mar 2014 14:58:13 +0100 | |
changeset 3311 | 514c65e7f366 |
parent 3310 | b0eef4f85fc9 |
child 3440 | 4db110335eaa |
permissions | -rw-r--r-- |
75 | 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 |
" |
|
1397 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
75 | 14 |
ValueModel subclass:#PluggableAdaptor |
223 | 15 |
instanceVariableNames:'model getBlock putBlock updateBlock' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Interface-Support-Models' |
|
75 | 19 |
! |
20 |
||
21 |
!PluggableAdaptor class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
Allows forwarding of value/value:/change messages via blocks. |
|
40 |
Kind of what ST/X always did .... |
|
41 |
||
42 |
PluggableAdaptor is the most general of the adaptor models - |
|
43 |
any other adapter can be simulated. However, they incur certain |
|
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
44 |
overhead and complexity. |
82 | 45 |
Therefore, in many situations, an AspectAdaptor is the better choice. |
223 | 46 |
|
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
47 |
Notice: |
231 | 48 |
this class was implemented using protocol information |
49 |
from alpha testers - it may not be complete or compatible to |
|
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
50 |
the corresponding ST-80 class. |
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
51 |
If you encounter any incompatibilities, please forward a note |
231 | 52 |
describing the incompatibility verbal (i.e. no code) to the ST/X team. |
53 |
||
223 | 54 |
[author:] |
55 |
Claus Gittinger |
|
76 | 56 |
" |
57 |
! |
|
75 | 58 |
|
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
59 |
examples |
76 | 60 |
" |
61 |
an adaptor for the variable x: |
|
231 | 62 |
[exBegin] |
63 |
|m x t| |
|
75 | 64 |
|
231 | 65 |
m := (PluggableAdaptor new) |
66 |
getBlock:[:m | x] |
|
268 | 67 |
putBlock:[:m :newValue | x := newValue. Transcript showCR:x] |
68 |
updateBlock:[:m :aspect :param | Transcript showCR:'changed']. |
|
231 | 69 |
t := Toggle new. |
70 |
t model:m. |
|
71 |
t label:'toggle me'. |
|
72 |
t open. |
|
73 |
[exEnd] |
|
75 | 74 |
|
75 |
||
76 | 76 |
an adaptor to send #destroy: |
231 | 77 |
[exBegin] |
78 |
|m t| |
|
75 | 79 |
|
231 | 80 |
m := (PluggableAdaptor new) |
81 |
getBlock:[:m | false] |
|
82 |
putBlock:[:m :newValue | t destroy] |
|
83 |
updateBlock:[:m :aspect :param | ]. |
|
84 |
t := Button new. |
|
85 |
t model:m. |
|
86 |
t label:'close me'. |
|
87 |
t open. |
|
88 |
[exEnd] |
|
75 | 89 |
|
90 |
||
91 |
as above, more convenient setup: |
|
231 | 92 |
[exBegin] |
93 |
|m t| |
|
75 | 94 |
|
231 | 95 |
t := Button new. |
75 | 96 |
|
231 | 97 |
m := (PluggableAdaptor on:t) performAction:#destroy. |
98 |
t model:m. |
|
99 |
t label:'close me'. |
|
100 |
t open. |
|
101 |
[exEnd] |
|
75 | 102 |
|
103 |
extract values from a complex model: |
|
231 | 104 |
[exBegin] |
105 |
|model dialog name pId| |
|
75 | 106 |
|
231 | 107 |
model := Plug new. |
108 |
model respondTo:#name with:[name]. |
|
109 |
model respondTo:#name: with:[:newValue | name := newValue]. |
|
110 |
model respondTo:#passportId with:[pId]. |
|
111 |
model respondTo:#passportId: with:[:newValue | pId := newValue]. |
|
112 |
name := 'John Smith'. |
|
113 |
pId := 56785432. |
|
75 | 114 |
|
231 | 115 |
dialog := Dialog new. |
116 |
||
117 |
dialog addInputFieldOn:((PluggableAdaptor on:model) |
|
118 |
getBlock:[:m | m name] |
|
119 |
putBlock:[:m :v | m name:v] |
|
120 |
updateBlock:[:m :a :p | false]). |
|
75 | 121 |
|
231 | 122 |
dialog addVerticalSpace. |
75 | 123 |
|
231 | 124 |
dialog addInputFieldOn:((PluggableAdaptor on:model) |
125 |
getBlock:[:m | m passportId printString] |
|
126 |
putBlock:[:m :v | m passportId:v asNumber] |
|
127 |
updateBlock:[:m :a :p | false]). |
|
128 |
dialog addAbortButton; addOkButton. |
|
129 |
dialog width:200; sizeFixed:true. |
|
130 |
dialog open. |
|
75 | 131 |
|
231 | 132 |
dialog accept value ifTrue:[ |
268 | 133 |
Transcript showCR:'accepted.'. |
231 | 134 |
]. |
268 | 135 |
Transcript showCR:' Name: ' , model name. |
136 |
Transcript showCR:' ID : ' , model passportId printString. |
|
231 | 137 |
[exEnd] |
138 |
||
75 | 139 |
|
140 |
||
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
141 |
extract values from an association into different labels: |
231 | 142 |
[exBegin] |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
143 |
|assoc t l| |
82 | 144 |
|
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
145 |
assoc := 'hello' -> 'world'. |
82 | 146 |
|
231 | 147 |
t := HorizontalPanelView new. |
148 |
t extent:200@50. |
|
149 |
t horizontalLayout:#fitSpace. |
|
82 | 150 |
|
231 | 151 |
l := Label in:t. |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
152 |
l model:((PluggableAdaptor on:assoc) getSelector:#key putSelector:#key:); |
231 | 153 |
labelMessage:#value; aspect:#value; |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
154 |
level:-1. |
231 | 155 |
l := Label in:t. |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
156 |
l model:((PluggableAdaptor on:assoc) getSelector:#value putSelector:#value:); |
231 | 157 |
labelMessage:#value; aspect:#value; |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
158 |
level:-1. |
231 | 159 |
t open. |
82 | 160 |
|
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
161 |
(Delay forSeconds:3) wait. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
162 |
assoc key:'goodbye'. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
163 |
assoc changed. |
231 | 164 |
[exEnd] |
82 | 165 |
|
166 |
extract values from an array into different labels: |
|
231 | 167 |
[exBegin] |
168 |
|a t l| |
|
75 | 169 |
|
231 | 170 |
a := #('one' 'two' 'three'). |
75 | 171 |
|
231 | 172 |
t := HorizontalPanelView new. |
173 |
t extent:200@50. |
|
174 |
t horizontalLayout:#fitSpace. |
|
75 | 175 |
|
231 | 176 |
l := Label in:t. |
177 |
l model:((PluggableAdaptor on:a) collectionIndex:1); |
|
178 |
labelMessage:#value; aspect:#value; |
|
179 |
level:-1; |
|
180 |
sizeFixed:true. |
|
181 |
l := Label in:t. |
|
182 |
l model:((PluggableAdaptor on:a) collectionIndex:2); |
|
183 |
labelMessage:#value; aspect:#value; |
|
184 |
level:-1; |
|
185 |
sizeFixed:true. |
|
186 |
l := Label in:t. |
|
187 |
l model:((PluggableAdaptor on:a) collectionIndex:3); |
|
188 |
labelMessage:#value; aspect:#value; |
|
189 |
level:-1; |
|
190 |
sizeFixed:true. |
|
191 |
t open. |
|
75 | 192 |
|
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
193 |
(Delay forSeconds:3) wait. |
231 | 194 |
a at:1 put:'1'. |
195 |
a changed. |
|
196 |
[exEnd] |
|
75 | 197 |
" |
198 |
! ! |
|
199 |
||
200 |
!PluggableAdaptor class methodsFor:'instance creation'! |
|
201 |
||
202 |
on:anObject |
|
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
203 |
"create & return a new protocolAdaptor. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
204 |
Any get/put and updateBlocks are still to be defined" |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
205 |
|
75 | 206 |
^ self new model:anObject |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
207 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
208 |
"Modified: 21.2.1997 / 18:31:22 / cg" |
2743 | 209 |
! |
210 |
||
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
211 |
on:anObject getter:getterBlock |
2881 | 212 |
^ (self on:anObject) getter:getterBlock |
2743 | 213 |
|
214 |
"Created: / 08-08-2004 / 21:54:04 / janfrog" |
|
215 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
2881 | 216 |
"Modified: / 22-12-2010 / 11:29:14 / cg" |
2743 | 217 |
! |
218 |
||
219 |
on:anObject getter:getterBlock setter:setterBlock |
|
2881 | 220 |
^ (self on:anObject) getter:getterBlock setter:setterBlock |
2743 | 221 |
|
222 |
"Created: / 08-08-2004 / 21:53:58 / janfrog" |
|
223 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
2881 | 224 |
"Modified: / 22-12-2010 / 11:29:18 / cg" |
2743 | 225 |
! |
226 |
||
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
227 |
on:anObject setter:setterBlock |
2743 | 228 |
^ (self on:anObject) |
229 |
setter:setterBlock |
|
230 |
||
231 |
"Created: / 08-08-2004 / 21:54:12 / janfrog" |
|
232 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
75 | 233 |
! ! |
234 |
||
125 | 235 |
!PluggableAdaptor methodsFor:'accessing'! |
75 | 236 |
|
2622 | 237 |
getBlock |
238 |
^ getBlock |
|
239 |
! |
|
240 |
||
241 |
putBlock |
|
242 |
^ putBlock |
|
243 |
! |
|
244 |
||
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
245 |
setValue:newValue |
125 | 246 |
putBlock notNil ifTrue:[ |
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
247 |
^ putBlock value:model value:newValue |
75 | 248 |
]. |
125 | 249 |
model value:newValue "/ stupid default |
75 | 250 |
! |
251 |
||
2622 | 252 |
updateBlock |
253 |
^ updateBlock |
|
254 |
! |
|
255 |
||
125 | 256 |
value |
257 |
getBlock notNil ifTrue:[ |
|
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
258 |
^ getBlock value:model |
125 | 259 |
]. |
260 |
^ model value "/ stupid default |
|
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
261 |
! |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
262 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
263 |
valueUsingSubject:someObject |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
264 |
someObject isNil ifTrue:[^ nil]. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
265 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
266 |
^ getBlock value:someObject |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
267 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
268 |
"Created: 21.2.1997 / 18:28:35 / cg" |
125 | 269 |
! ! |
75 | 270 |
|
1397 | 271 |
!PluggableAdaptor methodsFor:'change & update'! |
75 | 272 |
|
125 | 273 |
update:something with:aParameter from:changedObject |
274 |
changedObject == model ifTrue:[ |
|
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
275 |
updateBlock notNil ifTrue:[ |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
276 |
(updateBlock value:model value:something value:aParameter) |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
277 |
ifTrue:[ |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
278 |
self changed:#value |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
279 |
] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
280 |
] |
125 | 281 |
]. |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
282 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
283 |
"Modified: 21.2.1997 / 18:28:52 / cg" |
125 | 284 |
! ! |
75 | 285 |
|
1769 | 286 |
!PluggableAdaptor methodsFor:'initialization & release'! |
75 | 287 |
|
288 |
collectionIndex:idx |
|
289 |
"configure the adaptor to translate #value/#value:-messages into |
|
290 |
indexed accesses via #at:/#at:put:, using the supplied index" |
|
291 |
||
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
292 |
getBlock := [:model | model value at:idx]. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
293 |
putBlock := [:model :newValue | model value at:idx put:newValue]. |
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
294 |
updateBlock := [:model :aspect :parameter | |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
295 |
aspect isNil or:[aspect == #value] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
296 |
] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
297 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
298 |
"Modified: 21.2.1997 / 18:20:24 / cg" |
75 | 299 |
! |
300 |
||
2619 | 301 |
getBlock:newGetBlock |
302 |
"configure the adaptor to translate #value-messages into |
|
303 |
evaluation of the corresponding block. |
|
304 |
The getBlock argument block1 is called with one argument, the model, and is |
|
305 |
supposed to extract & return a value from that model." |
|
306 |
||
307 |
getBlock := newGetBlock. |
|
308 |
! |
|
309 |
||
2119 | 310 |
getBlock:newGetBlock putBlock:newPutBlock |
311 |
"configure the adaptor to translate #value/#value:-messages into |
|
312 |
evaluation of the corresponding block1/block2. |
|
313 |
The getBlock argument block1 is called with one argument, the model, and is |
|
314 |
supposed to extract & return a value from that model. |
|
315 |
The putBlock argument, block2 is called with 2 arguments, the model |
|
316 |
and the new value, and is supposed to store the new value." |
|
317 |
||
318 |
getBlock := newGetBlock. |
|
319 |
putBlock := newPutBlock. |
|
320 |
! |
|
321 |
||
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
322 |
getBlock:newGetBlock putBlock:newPutBlock updateBlock:newUpdateBlock |
75 | 323 |
"configure the adaptor to translate #value/#value:-messages into |
324 |
evaluation of the corresponding block1/block2. |
|
325 |
The getBlock argument block1 is called with one argument, the model, and is |
|
326 |
supposed to extract & return a value from that model. |
|
327 |
The putBlock argument, block2 is called with 2 arguments, the model |
|
328 |
and the new value, and is supposed to store the new value. |
|
329 |
The updateBlock argument, block3 is called with 3 arguments, the model, |
|
330 |
the aspect as changed in the model and the change parameter. It |
|
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
331 |
is called when the adaptor receives an update message from the model, |
75 | 332 |
and should return true if a new value should be fetched from the model." |
333 |
||
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
334 |
getBlock := newGetBlock. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
335 |
putBlock := newPutBlock. |
2383 | 336 |
self assert:(newUpdateBlock isNil or:[newUpdateBlock numArgs == 3]). |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
337 |
updateBlock := newUpdateBlock. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
338 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
339 |
"Modified: 21.2.1997 / 18:18:38 / cg" |
125 | 340 |
! |
75 | 341 |
|
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
342 |
getSelector:getSelector putSelector:putSelector |
125 | 343 |
"configure the adaptor to translate #value-messages into a send of |
344 |
getSelector and #value:-messages into sends of putSelector." |
|
75 | 345 |
|
125 | 346 |
getBlock := [:model | model perform:getSelector]. |
347 |
putBlock := [:model :newValue | model perform:putSelector with:newValue]. |
|
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
348 |
updateBlock := [:model :aspect :parameter | |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
349 |
aspect isNil |
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
350 |
or:[aspect == getSelector |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
351 |
or:[aspect == #value]] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
352 |
] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
353 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
354 |
"Modified: 21.2.1997 / 18:21:27 / cg" |
125 | 355 |
! |
356 |
||
357 |
model:anObject |
|
358 |
model notNil ifTrue:[ |
|
359 |
model removeDependent:self |
|
75 | 360 |
]. |
125 | 361 |
model := anObject. |
1127
4565ab2ad23c
dont get confused with a nil model.
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
362 |
model notNil ifTrue:[ |
4565ab2ad23c
dont get confused with a nil model.
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
363 |
model addDependent:self |
4565ab2ad23c
dont get confused with a nil model.
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
364 |
] |
75 | 365 |
! |
366 |
||
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
367 |
performAction:aSelector |
125 | 368 |
"configure the adaptor to send an aSelector-message to the model |
369 |
whenever a new value is stored via #value:" |
|
370 |
||
371 |
getBlock := [:model | nil]. |
|
372 |
putBlock := [:model :newValue | model perform:aSelector]. |
|
373 |
updateBlock := [:model :aspect :parameter | false] |
|
374 |
! |
|
375 |
||
2619 | 376 |
putBlock:newPutBlock |
377 |
"configure the adaptor to translate#value:-messages into |
|
378 |
evaluation of the corresponding block2. |
|
379 |
The putBlock argument, block2 is called with 2 arguments, the model |
|
380 |
and the new value, and is supposed to store the new value." |
|
381 |
||
382 |
putBlock := newPutBlock. |
|
383 |
! |
|
384 |
||
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
385 |
selectValue:something |
125 | 386 |
"configure the adaptor to behave like a boolean value, returning |
387 |
true whenever the models value equals something" |
|
388 |
||
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
389 |
"/ getBlock := [:model | model value = something]. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
390 |
"/ putBlock := [:model :newValue | newValue ifTrue:[model value:something]]. |
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
391 |
"/ updateBlock := [:model :aspect :parameter | |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
392 |
"/ aspect isNil or:[aspect == #value] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
393 |
"/ ] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
394 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
395 |
"/ changed for vw compatibility |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
396 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
397 |
|lastValue| |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
398 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
399 |
lastValue := nil. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
400 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
401 |
getBlock := [:model | lastValue := (model value = something)]. |
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
402 |
putBlock := [:model :newValue | newValue |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
403 |
ifTrue:[model value:something] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
404 |
ifFalse:[model value = something |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
405 |
ifTrue:[model value:nil] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
406 |
] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
407 |
]. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
408 |
updateBlock := [:model :aspect :parameter | |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
409 |
((model value = something) = lastValue) not |
352
ba7970fbcde2
Fix #selectValue: (Used by T-gen).
Stefan Vogel <sv@exept.de>
parents:
268
diff
changeset
|
410 |
] |
ba7970fbcde2
Fix #selectValue: (Used by T-gen).
Stefan Vogel <sv@exept.de>
parents:
268
diff
changeset
|
411 |
|
ba7970fbcde2
Fix #selectValue: (Used by T-gen).
Stefan Vogel <sv@exept.de>
parents:
268
diff
changeset
|
412 |
"Modified: 31.12.1996 / 13:58:09 / stefan" |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
413 |
"Modified: 21.2.1997 / 18:27:26 / cg" |
125 | 414 |
! |
415 |
||
416 |
subjectChannel:aValueHolder |
|
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
417 |
"setup to use aValueHolder as model" |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
418 |
|
125 | 419 |
self model:aValueHolder |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
420 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
421 |
"Modified: 21.2.1997 / 18:19:46 / cg" |
75 | 422 |
! ! |
423 |
||
2743 | 424 |
!PluggableAdaptor methodsFor:'utilities'! |
425 |
||
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
426 |
getter:getterBlock |
2743 | 427 |
self |
428 |
getter:getterBlock |
|
429 |
setter:[:value|self shouldNeverBeReached] |
|
430 |
||
431 |
"Created: / 08-08-2004 / 21:53:02 / janfrog" |
|
432 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
433 |
! |
|
434 |
||
3310
b0eef4f85fc9
Be more tolerant in PluggableAdaptor>>#getter:setter:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2881
diff
changeset
|
435 |
getter:getter setter:setter |
b0eef4f85fc9
Be more tolerant in PluggableAdaptor>>#getter:setter:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2881
diff
changeset
|
436 |
| getterBlock setterBlock | |
b0eef4f85fc9
Be more tolerant in PluggableAdaptor>>#getter:setter:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2881
diff
changeset
|
437 |
|
b0eef4f85fc9
Be more tolerant in PluggableAdaptor>>#getter:setter:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2881
diff
changeset
|
438 |
getterBlock := getter. |
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
439 |
setter numArgs == 1 ifTrue:[ |
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
440 |
setterBlock := [:model :value| model value:(setter value:value)] |
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
441 |
] ifFalse:[ |
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
442 |
setterBlock := setter |
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
443 |
]. |
3310
b0eef4f85fc9
Be more tolerant in PluggableAdaptor>>#getter:setter:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2881
diff
changeset
|
444 |
|
2743 | 445 |
self |
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
446 |
getBlock:getterBlock |
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
447 |
putBlock:setterBlock |
2743 | 448 |
updateBlock:[:model :aspect :value|true] |
449 |
||
450 |
"Created: / 08-08-2004 / 21:52:20 / janfrog" |
|
451 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
3310
b0eef4f85fc9
Be more tolerant in PluggableAdaptor>>#getter:setter:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2881
diff
changeset
|
452 |
"Modified: / 14-03-2014 / 23:21:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2743 | 453 |
! |
454 |
||
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
455 |
setter:setterBlock |
2743 | 456 |
self |
457 |
getter:[:value|self shouldNeverBeReached] |
|
458 |
setter:setterBlock |
|
459 |
||
460 |
"Created: / 08-08-2004 / 21:53:19 / janfrog" |
|
461 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
462 |
! ! |
|
463 |
||
129 | 464 |
!PluggableAdaptor class methodsFor:'documentation'! |
465 |
||
466 |
version |
|
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
467 |
^ '$Header: /cvs/stx/stx/libview2/PluggableAdaptor.st,v 1.26 2014-03-15 13:58:13 vrany Exp $' |
2881 | 468 |
! |
469 |
||
470 |
version_CVS |
|
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
471 |
^ '$Header: /cvs/stx/stx/libview2/PluggableAdaptor.st,v 1.26 2014-03-15 13:58:13 vrany Exp $' |
129 | 472 |
! ! |
3310
b0eef4f85fc9
Be more tolerant in PluggableAdaptor>>#getter:setter:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2881
diff
changeset
|
473 |