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