ValueModel.st
author Claus Gittinger <cg@exept.de>
Sat, 08 Aug 1998 13:42:06 +0200
changeset 1035 308004d24f3d
parent 796 5aca7d7a8f30
child 1095 ffd2aaae1a45
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
75
claus
parents: 73
diff changeset
     1
"
claus
parents: 73
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
claus
parents: 73
diff changeset
     3
	      All Rights Reserved
claus
parents: 73
diff changeset
     4
claus
parents: 73
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents: 73
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents: 73
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents: 73
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents: 73
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents: 73
diff changeset
    10
 hereby transferred.
claus
parents: 73
diff changeset
    11
"
claus
parents: 73
diff changeset
    12
69
claus
parents: 68
diff changeset
    13
Model subclass:#ValueModel
441
b0d486981a62 unconditionally send a change notification;
Claus Gittinger <cg@exept.de>
parents: 326
diff changeset
    14
	instanceVariableNames:''
175
df08e5b663d0 let objects interest implementation do things
Claus Gittinger <cg@exept.de>
parents: 143
diff changeset
    15
	classVariableNames:''
df08e5b663d0 let objects interest implementation do things
Claus Gittinger <cg@exept.de>
parents: 143
diff changeset
    16
	poolDictionaries:''
df08e5b663d0 let objects interest implementation do things
Claus Gittinger <cg@exept.de>
parents: 143
diff changeset
    17
	category:'Interface-Support-Models'
62
194eb0590b1e Initial revision
claus
parents:
diff changeset
    18
!
194eb0590b1e Initial revision
claus
parents:
diff changeset
    19
441
b0d486981a62 unconditionally send a change notification;
Claus Gittinger <cg@exept.de>
parents: 326
diff changeset
    20
!ValueModel class methodsFor:'documentation'!
68
claus
parents: 66
diff changeset
    21
69
claus
parents: 68
diff changeset
    22
copyright
claus
parents: 68
diff changeset
    23
"
claus
parents: 68
diff changeset
    24
 COPYRIGHT (c) 1995 by Claus Gittinger
71
claus
parents: 70
diff changeset
    25
	      All Rights Reserved
69
claus
parents: 68
diff changeset
    26
claus
parents: 68
diff changeset
    27
 This software is furnished under a license and may be used
claus
parents: 68
diff changeset
    28
 only in accordance with the terms of that license and with the
claus
parents: 68
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
claus
parents: 68
diff changeset
    30
 be provided or otherwise made available to, or used by, any
claus
parents: 68
diff changeset
    31
 other person.  No title to or ownership of the software is
claus
parents: 68
diff changeset
    32
 hereby transferred.
claus
parents: 68
diff changeset
    33
"
claus
parents: 68
diff changeset
    34
!
claus
parents: 68
diff changeset
    35
68
claus
parents: 66
diff changeset
    36
documentation
claus
parents: 66
diff changeset
    37
"
claus
parents: 66
diff changeset
    38
    abstract superclass for ValueHolders and Adaptors.
69
claus
parents: 68
diff changeset
    39
    It does not itself know how and where the value is stored,
143
ae38792bd85c interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 129
diff changeset
    40
    but knows about interested objects (which get informed, whenever
69
claus
parents: 68
diff changeset
    41
    the value changes) and keeps track if the value was ever accepted.
68
claus
parents: 66
diff changeset
    42
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    43
    Notice: 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    44
        this class was implemented using protocol information
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    45
        from alpha testers - it may not be complete or compatible to
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    46
        the corresponding ST-80 class. 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    47
        If you encounter any incompatibilities, please forward a note 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    48
        describing the incompatibility verbal (i.e. no code) to the ST/X team.
69
claus
parents: 68
diff changeset
    49
claus
parents: 68
diff changeset
    50
    subclasses must redefine: #setValue: and #value
claus
parents: 68
diff changeset
    51
    (and optionally redefine #value:)
223
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 175
diff changeset
    52
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 175
diff changeset
    53
    [author:]
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 175
diff changeset
    54
        Claus Gittinger
68
claus
parents: 66
diff changeset
    55
"
claus
parents: 66
diff changeset
    56
! !
claus
parents: 66
diff changeset
    57
441
b0d486981a62 unconditionally send a change notification;
Claus Gittinger <cg@exept.de>
parents: 326
diff changeset
    58
!ValueModel class methodsFor:'instance creation'!
62
194eb0590b1e Initial revision
claus
parents:
diff changeset
    59
194eb0590b1e Initial revision
claus
parents:
diff changeset
    60
new
194eb0590b1e Initial revision
claus
parents:
diff changeset
    61
    ^ (super new) initialize
194eb0590b1e Initial revision
claus
parents:
diff changeset
    62
! !
194eb0590b1e Initial revision
claus
parents:
diff changeset
    63
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    64
!ValueModel methodsFor:'accessing'!
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    65
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    66
setValue:newValue 
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    67
    "physically set my value, without change notifications"
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    68
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    69
    ^ self subclassResponsibility
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    70
!
73
claus
parents: 71
diff changeset
    71
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    72
value 
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    73
    "return my value"
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    74
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    75
    ^ self subclassResponsibility
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    76
!
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    77
504
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    78
value:newValue
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    79
    "set my value & send change notifications to my dependents
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    80
     if it changed."
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    81
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    82
    |oldValue|
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    83
504
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    84
    oldValue := self value.
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    85
    oldValue ~~ newValue ifTrue:[
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    86
        self setValue:newValue.
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    87
        self changed:#value
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    88
    ]
326
ab4e3df5c5d5 only ignore new value if identical to previous value.
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
    89
504
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    90
    "Modified: 27.3.1997 / 15:14:04 / cg"
796
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
    91
!
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
    92
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
    93
value:newValue withoutNotifying:someOne
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
    94
    "like #value, but temporarily retract all interrests for someOne
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
    95
     (i.e. the value-change will NOT directly send ANY change notification
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
    96
      to someOne; we cannot guarantee indirect notifications, though.)
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
    97
     Useful if someone is itself depending on the receiver,
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
    98
     and wants to avoid recursive update notifications."
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
    99
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   100
    |oldInterests wasDependent|
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   101
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   102
    [
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   103
        oldInterests := self interestsFor:someOne.
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   104
        self retractInterestsFor:someOne.
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   105
        wasDependent := (self dependents includes:someOne).
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   106
        self removeDependent:someOne.
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   107
        
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   108
        self value:newValue.
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   109
    ] valueNowOrOnUnwindDo:[
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   110
        wasDependent ifTrue:[self addDependent:someOne].
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   111
        oldInterests do:[:i |
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   112
            self addInterest:i
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   113
        ].
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   114
    ].
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   115
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   116
    "Modified: / 30.1.1998 / 14:14:01 / cg"
62
194eb0590b1e Initial revision
claus
parents:
diff changeset
   117
! !
194eb0590b1e Initial revision
claus
parents:
diff changeset
   118
492
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   119
!ValueModel methodsFor:'converting'!
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   120
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   121
compute:aBlock
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   122
    "return a BlockValue on the receiver, which computes aBlock"
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   123
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   124
    ^ BlockValue with:aBlock arguments:(Array with:self)
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   125
! !
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   126
69
claus
parents: 68
diff changeset
   127
!ValueModel methodsFor:'initialization'!
claus
parents: 68
diff changeset
   128
claus
parents: 68
diff changeset
   129
initialize
441
b0d486981a62 unconditionally send a change notification;
Claus Gittinger <cg@exept.de>
parents: 326
diff changeset
   130
b0d486981a62 unconditionally send a change notification;
Claus Gittinger <cg@exept.de>
parents: 326
diff changeset
   131
    "Modified: 21.2.1997 / 16:29:38 / cg"
69
claus
parents: 68
diff changeset
   132
! !
claus
parents: 68
diff changeset
   133
773
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   134
!ValueModel methodsFor:'queries'!
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   135
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   136
isBuffering
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   137
    "return true, if the receiver is buffering something.
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   138
     For compatibility with BufferedValueHolder, false is returned here"
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   139
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   140
    ^ false
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   141
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   142
    "Created: / 27.1.1998 / 12:12:08 / cg"
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   143
! !
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   144
441
b0d486981a62 unconditionally send a change notification;
Claus Gittinger <cg@exept.de>
parents: 326
diff changeset
   145
!ValueModel class methodsFor:'documentation'!
129
f890eaabc487 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 125
diff changeset
   146
f890eaabc487 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 125
diff changeset
   147
version
796
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   148
    ^ '$Header: /cvs/stx/stx/libview2/ValueModel.st,v 1.23 1998-01-30 13:24:39 cg Exp $'
129
f890eaabc487 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 125
diff changeset
   149
! !