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