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