PluggableAdaptor.st
author fm
Wed, 25 Apr 2007 14:17:13 +0200
changeset 2329 f5a1833995a1
parent 2119 c7f9c288469c
child 2378 d2cfc503d936
permissions -rw-r--r--
to do #displayDeviceForm:aForm x:x y:y
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
75
claus
parents:
diff changeset
     1
"
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
claus
parents:
diff changeset
     3
	      All Rights Reserved
claus
parents:
diff changeset
     4
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents:
diff changeset
    10
 hereby transferred.
claus
parents:
diff changeset
    11
"
claus
parents:
diff changeset
    12
1397
47ac1d3e1df1 category changes
Claus Gittinger <cg@exept.de>
parents: 1127
diff changeset
    13
"{ Package: 'stx:libview2' }"
47ac1d3e1df1 category changes
Claus Gittinger <cg@exept.de>
parents: 1127
diff changeset
    14
75
claus
parents:
diff changeset
    15
ValueModel subclass:#PluggableAdaptor
223
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 129
diff changeset
    16
	instanceVariableNames:'model getBlock putBlock updateBlock'
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 129
diff changeset
    17
	classVariableNames:''
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 129
diff changeset
    18
	poolDictionaries:''
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 129
diff changeset
    19
	category:'Interface-Support-Models'
75
claus
parents:
diff changeset
    20
!
claus
parents:
diff changeset
    21
claus
parents:
diff changeset
    22
!PluggableAdaptor class methodsFor:'documentation'!
claus
parents:
diff changeset
    23
claus
parents:
diff changeset
    24
copyright
claus
parents:
diff changeset
    25
"
claus
parents:
diff changeset
    26
 COPYRIGHT (c) 1995 by Claus Gittinger
claus
parents:
diff changeset
    27
	      All Rights Reserved
claus
parents:
diff changeset
    28
claus
parents:
diff changeset
    29
 This software is furnished under a license and may be used
claus
parents:
diff changeset
    30
 only in accordance with the terms of that license and with the
claus
parents:
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
claus
parents:
diff changeset
    32
 be provided or otherwise made available to, or used by, any
claus
parents:
diff changeset
    33
 other person.  No title to or ownership of the software is
claus
parents:
diff changeset
    34
 hereby transferred.
claus
parents:
diff changeset
    35
"
claus
parents:
diff changeset
    36
!
claus
parents:
diff changeset
    37
claus
parents:
diff changeset
    38
documentation
claus
parents:
diff changeset
    39
"
claus
parents:
diff changeset
    40
    Allows forwarding of value/value:/change messages via blocks.
claus
parents:
diff changeset
    41
    Kind of what ST/X always did ....
claus
parents:
diff changeset
    42
claus
parents:
diff changeset
    43
    PluggableAdaptor is the most general of the adaptor models -
claus
parents:
diff changeset
    44
    any other adapter can be simulated. However, they incur certain
82
claus
parents: 79
diff changeset
    45
    overhead and complexity. 
claus
parents: 79
diff changeset
    46
    Therefore, in many situations, an AspectAdaptor is the better choice.
223
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 129
diff changeset
    47
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    48
    Notice: 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    49
        this class was implemented using protocol information
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    50
        from alpha testers - it may not be complete or compatible to
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    51
        the corresponding ST-80 class. 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    52
        If you encounter any incompatibilities, please forward a note 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    53
        describing the incompatibility verbal (i.e. no code) to the ST/X team.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    54
223
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 129
diff changeset
    55
    [author:]
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 129
diff changeset
    56
        Claus Gittinger
76
claus
parents: 75
diff changeset
    57
"
claus
parents: 75
diff changeset
    58
!
75
claus
parents:
diff changeset
    59
76
claus
parents: 75
diff changeset
    60
examples 
claus
parents: 75
diff changeset
    61
"
claus
parents: 75
diff changeset
    62
    an adaptor for the variable x:
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    63
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    64
        |m x t|
75
claus
parents:
diff changeset
    65
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    66
        m := (PluggableAdaptor new)
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    67
                getBlock:[:m | x]
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
    68
                putBlock:[:m :newValue | x := newValue. Transcript showCR:x]
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
    69
                updateBlock:[:m :aspect :param | Transcript showCR:'changed'].
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    70
        t := Toggle new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    71
        t model:m.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    72
        t label:'toggle me'.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    73
        t open.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    74
                                                                        [exEnd]
75
claus
parents:
diff changeset
    75
claus
parents:
diff changeset
    76
76
claus
parents: 75
diff changeset
    77
    an adaptor to send #destroy:
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    78
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    79
        |m t|
75
claus
parents:
diff changeset
    80
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    81
        m := (PluggableAdaptor new)
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    82
                getBlock:[:m | false]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    83
                putBlock:[:m :newValue | t destroy]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    84
                updateBlock:[:m :aspect :param | ].
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    85
        t := Button new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    86
        t model:m.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    87
        t label:'close me'.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    88
        t open.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    89
                                                                        [exEnd]
75
claus
parents:
diff changeset
    90
claus
parents:
diff changeset
    91
claus
parents:
diff changeset
    92
    as above, more convenient setup:
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    93
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    94
        |m t|
75
claus
parents:
diff changeset
    95
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    96
        t := Button new.
75
claus
parents:
diff changeset
    97
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    98
        m := (PluggableAdaptor on:t) performAction:#destroy.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    99
        t model:m.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   100
        t label:'close me'.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   101
        t open.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   102
                                                                        [exEnd]
75
claus
parents:
diff changeset
   103
claus
parents:
diff changeset
   104
    extract values from a complex model:
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   105
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   106
        |model dialog  name pId|
75
claus
parents:
diff changeset
   107
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   108
        model := Plug new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   109
        model respondTo:#name with:[name].
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   110
        model respondTo:#name: with:[:newValue | name := newValue].
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   111
        model respondTo:#passportId with:[pId].
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   112
        model respondTo:#passportId: with:[:newValue | pId := newValue].
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   113
        name := 'John Smith'.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   114
        pId := 56785432.
75
claus
parents:
diff changeset
   115
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   116
        dialog := Dialog new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   117
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   118
        dialog addInputFieldOn:((PluggableAdaptor on:model)
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   119
                                    getBlock:[:m | m name]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   120
                                    putBlock:[:m :v | m name:v]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   121
                                    updateBlock:[:m :a :p | false]).
75
claus
parents:
diff changeset
   122
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   123
        dialog addVerticalSpace.
75
claus
parents:
diff changeset
   124
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   125
        dialog addInputFieldOn:((PluggableAdaptor on:model)
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   126
                                    getBlock:[:m | m passportId printString]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   127
                                    putBlock:[:m :v | m passportId:v asNumber]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   128
                                    updateBlock:[:m :a :p | false]).
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   129
        dialog addAbortButton; addOkButton.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   130
        dialog width:200; sizeFixed:true.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   131
        dialog open.
75
claus
parents:
diff changeset
   132
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   133
        dialog accept value ifTrue:[
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   134
            Transcript showCR:'accepted.'.
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   135
        ].
268
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   136
        Transcript showCR:'  Name: ' , model name.
1998023f12dc showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   137
        Transcript showCR:'  ID  : ' , model passportId printString.
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   138
                                                                        [exEnd]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   139
75
claus
parents:
diff changeset
   140
claus
parents:
diff changeset
   141
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   142
    extract values from an association into different labels:
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   143
                                                                        [exBegin]
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   144
        |assoc t l|
82
claus
parents: 79
diff changeset
   145
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   146
        assoc := 'hello' -> 'world'.
82
claus
parents: 79
diff changeset
   147
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   148
        t := HorizontalPanelView new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   149
        t extent:200@50.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   150
        t horizontalLayout:#fitSpace.
82
claus
parents: 79
diff changeset
   151
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   152
        l := Label in:t.
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   153
        l model:((PluggableAdaptor on:assoc) getSelector:#key putSelector:#key:);
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   154
          labelMessage:#value; aspect:#value;
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   155
          level:-1.
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   156
        l := Label in:t.
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   157
        l model:((PluggableAdaptor on:assoc) getSelector:#value putSelector:#value:);
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   158
          labelMessage:#value; aspect:#value;
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   159
          level:-1.
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   160
        t open.
82
claus
parents: 79
diff changeset
   161
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   162
        (Delay forSeconds:3) wait.
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   163
        assoc key:'goodbye'.
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   164
        assoc changed.
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   165
                                                                        [exEnd]
82
claus
parents: 79
diff changeset
   166
claus
parents: 79
diff changeset
   167
    extract values from an array into different labels:
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   168
                                                                        [exBegin]
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   169
        |a t l|
75
claus
parents:
diff changeset
   170
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   171
        a := #('one' 'two' 'three').
75
claus
parents:
diff changeset
   172
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   173
        t := HorizontalPanelView new.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   174
        t extent:200@50.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   175
        t horizontalLayout:#fitSpace.
75
claus
parents:
diff changeset
   176
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   177
        l := Label in:t.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   178
        l model:((PluggableAdaptor on:a) collectionIndex:1);
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   179
          labelMessage:#value; aspect:#value;
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   180
          level:-1;
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   181
          sizeFixed:true.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   182
        l := Label in:t.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   183
        l model:((PluggableAdaptor on:a) collectionIndex:2);
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   184
          labelMessage:#value; aspect:#value;
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   185
          level:-1;
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   186
          sizeFixed:true.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   187
        l := Label in:t.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   188
        l model:((PluggableAdaptor on:a) collectionIndex:3);
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   189
          labelMessage:#value; aspect:#value;
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   190
          level:-1;
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   191
          sizeFixed:true.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   192
        t open.
75
claus
parents:
diff changeset
   193
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   194
        (Delay forSeconds:3) wait.
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   195
        a at:1 put:'1'.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   196
        a changed.
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
   197
                                                                        [exEnd]
75
claus
parents:
diff changeset
   198
"
claus
parents:
diff changeset
   199
! !
claus
parents:
diff changeset
   200
claus
parents:
diff changeset
   201
!PluggableAdaptor class methodsFor:'instance creation'!
claus
parents:
diff changeset
   202
claus
parents:
diff changeset
   203
on:anObject
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   204
    "create & return a new protocolAdaptor.
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   205
     Any get/put and updateBlocks are still to be defined"
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   206
75
claus
parents:
diff changeset
   207
    ^ self new model:anObject
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   208
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   209
    "Modified: 21.2.1997 / 18:31:22 / cg"
75
claus
parents:
diff changeset
   210
! !
claus
parents:
diff changeset
   211
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   212
!PluggableAdaptor methodsFor:'accessing'!
75
claus
parents:
diff changeset
   213
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   214
setValue:newValue 
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   215
    putBlock notNil ifTrue:[
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   216
	^ putBlock value:model value:newValue 
75
claus
parents:
diff changeset
   217
    ].
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   218
    model value:newValue "/ stupid default
75
claus
parents:
diff changeset
   219
!
claus
parents:
diff changeset
   220
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   221
value
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   222
    getBlock notNil ifTrue:[
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   223
	^ getBlock value:model 
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   224
    ].
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   225
    ^ model value "/ stupid default
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
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   228
valueUsingSubject:someObject
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   229
    someObject isNil ifTrue:[^ nil].
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   230
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   231
    ^ getBlock value:someObject
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   232
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   233
    "Created: 21.2.1997 / 18:28:35 / cg"
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   234
! !
75
claus
parents:
diff changeset
   235
1397
47ac1d3e1df1 category changes
Claus Gittinger <cg@exept.de>
parents: 1127
diff changeset
   236
!PluggableAdaptor methodsFor:'change & update'!
75
claus
parents:
diff changeset
   237
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   238
update:something with:aParameter from:changedObject
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   239
    changedObject == model ifTrue:[
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   240
        updateBlock notNil ifTrue:[
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   241
            (updateBlock value:model value:something value:aParameter)
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   242
            ifTrue:[
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   243
                self changed:#value
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   244
            ]
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   245
        ]
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   246
    ].
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   247
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   248
    "Modified: 21.2.1997 / 18:28:52 / cg"
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   249
! !
75
claus
parents:
diff changeset
   250
1769
c6db6b7bd59a method category rename
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
   251
!PluggableAdaptor methodsFor:'initialization & release'!
75
claus
parents:
diff changeset
   252
claus
parents:
diff changeset
   253
collectionIndex:idx
claus
parents:
diff changeset
   254
    "configure the adaptor to translate #value/#value:-messages into
claus
parents:
diff changeset
   255
     indexed accesses via #at:/#at:put:, using the supplied index"
claus
parents:
diff changeset
   256
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   257
    getBlock := [:model | model value at:idx].
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   258
    putBlock := [:model :newValue | model value at:idx put:newValue].
75
claus
parents:
diff changeset
   259
    updateBlock := [:model :aspect :parameter | 
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   260
                        aspect isNil or:[aspect == #value]
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
    "Modified: 21.2.1997 / 18:20:24 / cg"
75
claus
parents:
diff changeset
   264
!
claus
parents:
diff changeset
   265
2119
c7f9c288469c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1769
diff changeset
   266
getBlock:newGetBlock putBlock:newPutBlock
c7f9c288469c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1769
diff changeset
   267
    "configure the adaptor to translate #value/#value:-messages into
c7f9c288469c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1769
diff changeset
   268
     evaluation of the corresponding block1/block2.
c7f9c288469c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1769
diff changeset
   269
     The getBlock argument block1 is called with one argument, the model, and is
c7f9c288469c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1769
diff changeset
   270
     supposed to extract & return a value from that model.
c7f9c288469c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1769
diff changeset
   271
     The putBlock argument, block2 is called with 2 arguments, the model
c7f9c288469c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1769
diff changeset
   272
     and the new value, and is supposed to store the new value."
c7f9c288469c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1769
diff changeset
   273
c7f9c288469c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1769
diff changeset
   274
    getBlock := newGetBlock.
c7f9c288469c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1769
diff changeset
   275
    putBlock := newPutBlock.
c7f9c288469c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1769
diff changeset
   276
!
c7f9c288469c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1769
diff changeset
   277
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   278
getBlock:newGetBlock putBlock:newPutBlock updateBlock:newUpdateBlock
75
claus
parents:
diff changeset
   279
    "configure the adaptor to translate #value/#value:-messages into
claus
parents:
diff changeset
   280
     evaluation of the corresponding block1/block2.
claus
parents:
diff changeset
   281
     The getBlock argument block1 is called with one argument, the model, and is
claus
parents:
diff changeset
   282
     supposed to extract & return a value from that model.
claus
parents:
diff changeset
   283
     The putBlock argument, block2 is called with 2 arguments, the model
claus
parents:
diff changeset
   284
     and the new value, and is supposed to store the new value.
claus
parents:
diff changeset
   285
     The updateBlock argument, block3 is called with 3 arguments, the model,
claus
parents:
diff changeset
   286
     the aspect as changed in the model and the change parameter. It
claus
parents:
diff changeset
   287
     is called when the adaptor receives an update message from the model, 
claus
parents:
diff changeset
   288
     and should return true if a new value should be fetched from the model."
claus
parents:
diff changeset
   289
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   290
    getBlock := newGetBlock.
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   291
    putBlock := newPutBlock.
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   292
    updateBlock := newUpdateBlock.
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   293
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   294
    "Modified: 21.2.1997 / 18:18:38 / cg"
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   295
!
75
claus
parents:
diff changeset
   296
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   297
getSelector:getSelector putSelector:putSelector 
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   298
    "configure the adaptor to translate #value-messages into a send of
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   299
     getSelector and #value:-messages into sends of putSelector."
75
claus
parents:
diff changeset
   300
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   301
    getBlock := [:model | model perform:getSelector].
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   302
    putBlock := [:model :newValue | model perform:putSelector with:newValue].
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   303
    updateBlock := [:model :aspect :parameter | 
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   304
                        aspect isNil
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   305
                        or:[aspect == getSelector 
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   306
                        or:[aspect == #value]]
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   307
                   ]
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   308
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   309
    "Modified: 21.2.1997 / 18:21:27 / cg"
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   310
!
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   311
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   312
model:anObject
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   313
    model notNil ifTrue:[
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   314
       model removeDependent:self
75
claus
parents:
diff changeset
   315
    ].
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   316
    model := anObject.
1127
4565ab2ad23c dont get confused with a nil model.
Claus Gittinger <cg@exept.de>
parents: 443
diff changeset
   317
    model notNil ifTrue:[
4565ab2ad23c dont get confused with a nil model.
Claus Gittinger <cg@exept.de>
parents: 443
diff changeset
   318
        model addDependent:self
4565ab2ad23c dont get confused with a nil model.
Claus Gittinger <cg@exept.de>
parents: 443
diff changeset
   319
    ]
75
claus
parents:
diff changeset
   320
!
claus
parents:
diff changeset
   321
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   322
performAction:aSelector 
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   323
    "configure the adaptor to send an aSelector-message to the model
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   324
     whenever a new value is stored via #value:"
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   325
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   326
    getBlock := [:model | nil].
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   327
    putBlock := [:model :newValue | model perform:aSelector].
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   328
    updateBlock := [:model :aspect :parameter | false]
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   329
!
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   330
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   331
selectValue:something 
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   332
    "configure the adaptor to behave like a boolean value, returning
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   333
     true whenever the models value equals something"
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   334
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   335
"/    getBlock := [:model | model value = something].
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   336
"/    putBlock := [:model :newValue | newValue ifTrue:[model value:something]].
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   337
"/    updateBlock := [:model :aspect :parameter | 
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   338
"/                        aspect isNil or:[aspect == #value]
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   339
"/                   ]
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
    "/ changed for vw compatibility
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
    |lastValue|
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   344
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   345
    lastValue := nil.
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   346
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   347
    getBlock := [:model | lastValue := (model value = something)].
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   348
    putBlock := [:model :newValue | newValue 
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   349
                                        ifTrue:[model value:something]
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   350
                                        ifFalse:[model value = something
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   351
                                                     ifTrue:[model value:nil]
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
    updateBlock := [:model :aspect :parameter |
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   355
                        ((model value = something) = lastValue) not
352
ba7970fbcde2 Fix #selectValue: (Used by T-gen).
Stefan Vogel <sv@exept.de>
parents: 268
diff changeset
   356
                   ]
ba7970fbcde2 Fix #selectValue: (Used by T-gen).
Stefan Vogel <sv@exept.de>
parents: 268
diff changeset
   357
ba7970fbcde2 Fix #selectValue: (Used by T-gen).
Stefan Vogel <sv@exept.de>
parents: 268
diff changeset
   358
    "Modified: 31.12.1996 / 13:58:09 / stefan"
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   359
    "Modified: 21.2.1997 / 18:27:26 / cg"
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   360
!
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   361
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   362
subjectChannel:aValueHolder
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   363
    "setup to use aValueHolder as model"
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   364
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   365
    self model:aValueHolder
443
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   366
5c57a8861677 st-80 compatible selectValue:
Claus Gittinger <cg@exept.de>
parents: 352
diff changeset
   367
    "Modified: 21.2.1997 / 18:19:46 / cg"
75
claus
parents:
diff changeset
   368
! !
claus
parents:
diff changeset
   369
129
f890eaabc487 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 125
diff changeset
   370
!PluggableAdaptor class methodsFor:'documentation'!
f890eaabc487 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 125
diff changeset
   371
f890eaabc487 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 125
diff changeset
   372
version
2119
c7f9c288469c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1769
diff changeset
   373
    ^ '$Header: /cvs/stx/stx/libview2/PluggableAdaptor.st,v 1.18 2006-03-06 08:45:55 cg Exp $'
129
f890eaabc487 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 125
diff changeset
   374
! !