author | Claus Gittinger <cg@exept.de> |
Thu, 23 Jan 2020 17:47:56 +0100 | |
changeset 4431 | 732c2cd831b8 |
parent 4339 | f98b7fa24c7a |
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 |
|
4327 | 107 |
choose one from alternatives (radioButton-like behavior): |
108 |
||
109 |
[exBegin] |
|
110 |
|m v| |
|
111 |
||
112 |
m := #foo asValue. |
|
113 |
v := HorizontalPanelView new. |
|
114 |
v add:(Toggle on:((PluggableAdaptor on:m) selectValue:#foo) label:'foo' ). |
|
115 |
v add:(Toggle on:((PluggableAdaptor on:m) selectValue:#bar) label:'bar' ). |
|
116 |
v add:(Toggle on:((PluggableAdaptor on:m) selectValue:#baz) label:'baz' ). |
|
117 |
v add:(Label label:'Current:' ). |
|
118 |
v add:(Label new labelChannel:m ). |
|
119 |
v open. |
|
120 |
[exEnd] |
|
121 |
||
75 | 122 |
extract values from a complex model: |
231 | 123 |
[exBegin] |
124 |
|model dialog name pId| |
|
75 | 125 |
|
231 | 126 |
model := Plug new. |
127 |
model respondTo:#name with:[name]. |
|
128 |
model respondTo:#name: with:[:newValue | name := newValue]. |
|
129 |
model respondTo:#passportId with:[pId]. |
|
130 |
model respondTo:#passportId: with:[:newValue | pId := newValue]. |
|
131 |
name := 'John Smith'. |
|
132 |
pId := 56785432. |
|
75 | 133 |
|
231 | 134 |
dialog := Dialog new. |
135 |
||
136 |
dialog addInputFieldOn:((PluggableAdaptor on:model) |
|
137 |
getBlock:[:m | m name] |
|
138 |
putBlock:[:m :v | m name:v] |
|
139 |
updateBlock:[:m :a :p | false]). |
|
75 | 140 |
|
231 | 141 |
dialog addVerticalSpace. |
75 | 142 |
|
231 | 143 |
dialog addInputFieldOn:((PluggableAdaptor on:model) |
144 |
getBlock:[:m | m passportId printString] |
|
145 |
putBlock:[:m :v | m passportId:v asNumber] |
|
146 |
updateBlock:[:m :a :p | false]). |
|
147 |
dialog addAbortButton; addOkButton. |
|
148 |
dialog width:200; sizeFixed:true. |
|
149 |
dialog open. |
|
75 | 150 |
|
231 | 151 |
dialog accept value ifTrue:[ |
268 | 152 |
Transcript showCR:'accepted.'. |
231 | 153 |
]. |
268 | 154 |
Transcript showCR:' Name: ' , model name. |
155 |
Transcript showCR:' ID : ' , model passportId printString. |
|
231 | 156 |
[exEnd] |
157 |
||
75 | 158 |
|
159 |
||
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
160 |
extract values from an association into different labels: |
231 | 161 |
[exBegin] |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
162 |
|assoc t l| |
82 | 163 |
|
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
164 |
assoc := 'hello' -> 'world'. |
82 | 165 |
|
231 | 166 |
t := HorizontalPanelView new. |
167 |
t extent:200@50. |
|
168 |
t horizontalLayout:#fitSpace. |
|
82 | 169 |
|
231 | 170 |
l := Label in:t. |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
171 |
l model:((PluggableAdaptor on:assoc) getSelector:#key putSelector:#key:); |
231 | 172 |
labelMessage:#value; aspect:#value; |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
173 |
level:-1. |
231 | 174 |
l := Label in:t. |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
175 |
l model:((PluggableAdaptor on:assoc) getSelector:#value putSelector:#value:); |
231 | 176 |
labelMessage:#value; aspect:#value; |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
177 |
level:-1. |
231 | 178 |
t open. |
82 | 179 |
|
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
180 |
(Delay forSeconds:3) wait. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
181 |
assoc key:'goodbye'. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
182 |
assoc changed. |
231 | 183 |
[exEnd] |
82 | 184 |
|
185 |
extract values from an array into different labels: |
|
231 | 186 |
[exBegin] |
187 |
|a t l| |
|
75 | 188 |
|
231 | 189 |
a := #('one' 'two' 'three'). |
75 | 190 |
|
231 | 191 |
t := HorizontalPanelView new. |
192 |
t extent:200@50. |
|
193 |
t horizontalLayout:#fitSpace. |
|
75 | 194 |
|
231 | 195 |
l := Label in:t. |
196 |
l model:((PluggableAdaptor on:a) collectionIndex:1); |
|
197 |
labelMessage:#value; aspect:#value; |
|
198 |
level:-1; |
|
199 |
sizeFixed:true. |
|
200 |
l := Label in:t. |
|
201 |
l model:((PluggableAdaptor on:a) collectionIndex:2); |
|
202 |
labelMessage:#value; aspect:#value; |
|
203 |
level:-1; |
|
204 |
sizeFixed:true. |
|
205 |
l := Label in:t. |
|
206 |
l model:((PluggableAdaptor on:a) collectionIndex:3); |
|
207 |
labelMessage:#value; aspect:#value; |
|
208 |
level:-1; |
|
209 |
sizeFixed:true. |
|
210 |
t open. |
|
75 | 211 |
|
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
212 |
(Delay forSeconds:3) wait. |
231 | 213 |
a at:1 put:'1'. |
214 |
a changed. |
|
215 |
[exEnd] |
|
75 | 216 |
" |
217 |
! ! |
|
218 |
||
219 |
!PluggableAdaptor class methodsFor:'instance creation'! |
|
220 |
||
221 |
on:anObject |
|
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
222 |
"create & return a new protocolAdaptor. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
223 |
Any get/put and updateBlocks are still to be defined" |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
224 |
|
75 | 225 |
^ self new model:anObject |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
226 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
227 |
"Modified: 21.2.1997 / 18:31:22 / cg" |
2743 | 228 |
! |
229 |
||
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
230 |
on:anObject getter:getterBlock |
2881 | 231 |
^ (self on:anObject) getter:getterBlock |
2743 | 232 |
|
233 |
"Created: / 08-08-2004 / 21:54:04 / janfrog" |
|
234 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
2881 | 235 |
"Modified: / 22-12-2010 / 11:29:14 / cg" |
2743 | 236 |
! |
237 |
||
238 |
on:anObject getter:getterBlock setter:setterBlock |
|
2881 | 239 |
^ (self on:anObject) getter:getterBlock setter:setterBlock |
2743 | 240 |
|
241 |
"Created: / 08-08-2004 / 21:53:58 / janfrog" |
|
242 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
2881 | 243 |
"Modified: / 22-12-2010 / 11:29:18 / cg" |
2743 | 244 |
! |
245 |
||
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
246 |
on:anObject setter:setterBlock |
2743 | 247 |
^ (self on:anObject) |
248 |
setter:setterBlock |
|
249 |
||
250 |
"Created: / 08-08-2004 / 21:54:12 / janfrog" |
|
251 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
75 | 252 |
! ! |
253 |
||
125 | 254 |
!PluggableAdaptor methodsFor:'accessing'! |
75 | 255 |
|
2622 | 256 |
getBlock |
257 |
^ getBlock |
|
258 |
! |
|
259 |
||
260 |
putBlock |
|
261 |
^ putBlock |
|
262 |
! |
|
263 |
||
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
264 |
setValue:newValue |
125 | 265 |
putBlock notNil ifTrue:[ |
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
266 |
^ putBlock value:model value:newValue |
75 | 267 |
]. |
125 | 268 |
model value:newValue "/ stupid default |
75 | 269 |
! |
270 |
||
2622 | 271 |
updateBlock |
272 |
^ updateBlock |
|
273 |
! |
|
274 |
||
125 | 275 |
value |
276 |
getBlock notNil ifTrue:[ |
|
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
277 |
^ getBlock value:model |
125 | 278 |
]. |
279 |
^ model value "/ stupid default |
|
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
280 |
! |
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 |
valueUsingSubject:someObject |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
283 |
someObject isNil ifTrue:[^ nil]. |
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 |
^ getBlock value:someObject |
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 |
"Created: 21.2.1997 / 18:28:35 / cg" |
125 | 288 |
! ! |
75 | 289 |
|
1397 | 290 |
!PluggableAdaptor methodsFor:'change & update'! |
75 | 291 |
|
125 | 292 |
update:something with:aParameter from:changedObject |
293 |
changedObject == model ifTrue:[ |
|
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
294 |
updateBlock notNil ifTrue:[ |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
295 |
(updateBlock value:model value:something value:aParameter) |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
296 |
ifTrue:[ |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
297 |
self changed:#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 |
] |
125 | 300 |
]. |
443
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:28:52 / cg" |
125 | 303 |
! ! |
75 | 304 |
|
1769 | 305 |
!PluggableAdaptor methodsFor:'initialization & release'! |
75 | 306 |
|
307 |
collectionIndex:idx |
|
308 |
"configure the adaptor to translate #value/#value:-messages into |
|
309 |
indexed accesses via #at:/#at:put:, using the supplied index" |
|
310 |
||
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
311 |
getBlock := [:model | model value at:idx]. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
312 |
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
|
313 |
updateBlock := [:model :aspect :parameter | |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
314 |
aspect isNil or:[aspect == #value] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
315 |
] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
316 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
317 |
"Modified: 21.2.1997 / 18:20:24 / cg" |
75 | 318 |
! |
319 |
||
2619 | 320 |
getBlock:newGetBlock |
321 |
"configure the adaptor to translate #value-messages into |
|
322 |
evaluation of the corresponding block. |
|
323 |
The getBlock argument block1 is called with one argument, the model, and is |
|
324 |
supposed to extract & return a value from that model." |
|
325 |
||
326 |
getBlock := newGetBlock. |
|
327 |
! |
|
328 |
||
2119 | 329 |
getBlock:newGetBlock putBlock:newPutBlock |
330 |
"configure the adaptor to translate #value/#value:-messages into |
|
331 |
evaluation of the corresponding block1/block2. |
|
332 |
The getBlock argument block1 is called with one argument, the model, and is |
|
333 |
supposed to extract & return a value from that model. |
|
334 |
The putBlock argument, block2 is called with 2 arguments, the model |
|
335 |
and the new value, and is supposed to store the new value." |
|
336 |
||
337 |
getBlock := newGetBlock. |
|
338 |
putBlock := newPutBlock. |
|
339 |
! |
|
340 |
||
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
341 |
getBlock:newGetBlock putBlock:newPutBlock updateBlock:newUpdateBlock |
75 | 342 |
"configure the adaptor to translate #value/#value:-messages into |
343 |
evaluation of the corresponding block1/block2. |
|
344 |
The getBlock argument block1 is called with one argument, the model, and is |
|
345 |
supposed to extract & return a value from that model. |
|
346 |
The putBlock argument, block2 is called with 2 arguments, the model |
|
347 |
and the new value, and is supposed to store the new value. |
|
348 |
The updateBlock argument, block3 is called with 3 arguments, the model, |
|
349 |
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
|
350 |
is called when the adaptor receives an update message from the model, |
75 | 351 |
and should return true if a new value should be fetched from the model." |
352 |
||
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
353 |
getBlock := newGetBlock. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
354 |
putBlock := newPutBlock. |
4339 | 355 |
self assert:(newUpdateBlock isNil or:[newUpdateBlock argumentCount == 3]). |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
356 |
updateBlock := newUpdateBlock. |
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:18:38 / cg" |
125 | 359 |
! |
75 | 360 |
|
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
361 |
getSelector:getSelector putSelector:putSelector |
125 | 362 |
"configure the adaptor to translate #value-messages into a send of |
363 |
getSelector and #value:-messages into sends of putSelector." |
|
75 | 364 |
|
125 | 365 |
getBlock := [:model | model perform:getSelector]. |
366 |
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
|
367 |
updateBlock := [:model :aspect :parameter | |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
368 |
aspect isNil |
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
369 |
or:[aspect == getSelector |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
370 |
or:[aspect == #value]] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
371 |
] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
372 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
373 |
"Modified: 21.2.1997 / 18:21:27 / cg" |
125 | 374 |
! |
375 |
||
3735 | 376 |
model |
377 |
"get the real model, into which / from which the |
|
378 |
real model value is converted" |
|
379 |
||
380 |
^ model |
|
381 |
! |
|
382 |
||
125 | 383 |
model:anObject |
3735 | 384 |
"set the real model, into which / from which the |
385 |
real model value is converted" |
|
386 |
||
125 | 387 |
model notNil ifTrue:[ |
388 |
model removeDependent:self |
|
75 | 389 |
]. |
125 | 390 |
model := anObject. |
1127
4565ab2ad23c
dont get confused with a nil model.
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
391 |
model notNil ifTrue:[ |
4565ab2ad23c
dont get confused with a nil model.
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
392 |
model addDependent:self |
4565ab2ad23c
dont get confused with a nil model.
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
393 |
] |
75 | 394 |
! |
395 |
||
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
396 |
performAction:aSelector |
125 | 397 |
"configure the adaptor to send an aSelector-message to the model |
398 |
whenever a new value is stored via #value:" |
|
399 |
||
400 |
getBlock := [:model | nil]. |
|
401 |
putBlock := [:model :newValue | model perform:aSelector]. |
|
402 |
updateBlock := [:model :aspect :parameter | false] |
|
403 |
! |
|
404 |
||
2619 | 405 |
putBlock:newPutBlock |
406 |
"configure the adaptor to translate#value:-messages into |
|
407 |
evaluation of the corresponding block2. |
|
408 |
The putBlock argument, block2 is called with 2 arguments, the model |
|
409 |
and the new value, and is supposed to store the new value." |
|
410 |
||
411 |
putBlock := newPutBlock. |
|
412 |
! |
|
413 |
||
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
414 |
selectValue:something |
125 | 415 |
"configure the adaptor to behave like a boolean value, returning |
4327 | 416 |
true whenever the model's value equals something" |
125 | 417 |
|
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
418 |
"/ getBlock := [:model | model value = something]. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
419 |
"/ 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
|
420 |
"/ updateBlock := [:model :aspect :parameter | |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
421 |
"/ aspect isNil or:[aspect == #value] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
422 |
"/ ] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
423 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
424 |
"/ changed for vw compatibility |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
425 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
426 |
|lastValue| |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
427 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
428 |
lastValue := nil. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
429 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
430 |
getBlock := [:model | lastValue := (model value = something)]. |
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
431 |
putBlock := [:model :newValue | newValue |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
432 |
ifTrue:[model value:something] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
433 |
ifFalse:[model value = something |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
434 |
ifTrue:[model value:nil] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
435 |
] |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
436 |
]. |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
437 |
updateBlock := [:model :aspect :parameter | |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
438 |
((model value = something) = lastValue) not |
352
ba7970fbcde2
Fix #selectValue: (Used by T-gen).
Stefan Vogel <sv@exept.de>
parents:
268
diff
changeset
|
439 |
] |
ba7970fbcde2
Fix #selectValue: (Used by T-gen).
Stefan Vogel <sv@exept.de>
parents:
268
diff
changeset
|
440 |
|
ba7970fbcde2
Fix #selectValue: (Used by T-gen).
Stefan Vogel <sv@exept.de>
parents:
268
diff
changeset
|
441 |
"Modified: 31.12.1996 / 13:58:09 / stefan" |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
442 |
"Modified: 21.2.1997 / 18:27:26 / cg" |
125 | 443 |
! |
444 |
||
445 |
subjectChannel:aValueHolder |
|
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
446 |
"setup to use aValueHolder as model" |
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
447 |
|
125 | 448 |
self model:aValueHolder |
443
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
449 |
|
5c57a8861677
st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
450 |
"Modified: 21.2.1997 / 18:19:46 / cg" |
75 | 451 |
! ! |
452 |
||
2743 | 453 |
!PluggableAdaptor methodsFor:'utilities'! |
454 |
||
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
455 |
getter:getterBlock |
2743 | 456 |
self |
457 |
getter:getterBlock |
|
458 |
setter:[:value|self shouldNeverBeReached] |
|
459 |
||
460 |
"Created: / 08-08-2004 / 21:53:02 / janfrog" |
|
461 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
462 |
! |
|
463 |
||
3310
b0eef4f85fc9
Be more tolerant in PluggableAdaptor>>#getter:setter:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2881
diff
changeset
|
464 |
getter:getter setter:setter |
b0eef4f85fc9
Be more tolerant in PluggableAdaptor>>#getter:setter:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2881
diff
changeset
|
465 |
| getterBlock setterBlock | |
b0eef4f85fc9
Be more tolerant in PluggableAdaptor>>#getter:setter:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2881
diff
changeset
|
466 |
|
b0eef4f85fc9
Be more tolerant in PluggableAdaptor>>#getter:setter:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2881
diff
changeset
|
467 |
getterBlock := getter. |
4339 | 468 |
setter argumentCount == 1 ifTrue:[ |
469 |
setterBlock := [:model :value| model value:(setter value:value)] |
|
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
470 |
] ifFalse:[ |
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
471 |
setterBlock := setter |
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
472 |
]. |
3310
b0eef4f85fc9
Be more tolerant in PluggableAdaptor>>#getter:setter:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2881
diff
changeset
|
473 |
|
2743 | 474 |
self |
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
475 |
getBlock:getterBlock |
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
476 |
putBlock:setterBlock |
2743 | 477 |
updateBlock:[:model :aspect :value|true] |
478 |
||
479 |
"Created: / 08-08-2004 / 21:52:20 / janfrog" |
|
480 |
"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
|
481 |
"Modified: / 14-03-2014 / 23:21:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2743 | 482 |
! |
483 |
||
3311
514c65e7f366
Workaround for stc bug, sigh.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3310
diff
changeset
|
484 |
setter:setterBlock |
2743 | 485 |
self |
486 |
getter:[:value|self shouldNeverBeReached] |
|
487 |
setter:setterBlock |
|
488 |
||
489 |
"Created: / 08-08-2004 / 21:53:19 / janfrog" |
|
490 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
491 |
! ! |
|
492 |
||
129 | 493 |
!PluggableAdaptor class methodsFor:'documentation'! |
494 |
||
495 |
version |
|
3735 | 496 |
^ '$Header$' |
2881 | 497 |
! |
498 |
||
499 |
version_CVS |
|
3735 | 500 |
^ '$Header$' |
129 | 501 |
! ! |
3310
b0eef4f85fc9
Be more tolerant in PluggableAdaptor>>#getter:setter:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2881
diff
changeset
|
502 |