ValueModel.st
author Stefan Vogel <sv@exept.de>
Tue, 14 Mar 2000 18:20:26 +0100
changeset 1363 3f2ec69eece6
parent 1189 d1df42602935
child 1438 739c0e3e3993
permissions -rw-r--r--
Define #triggerValue
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
1189
d1df42602935 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1156
diff changeset
    61
    ^ self basicNew initialize
62
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
1363
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    72
triggerValue:newValue
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    73
    "set my value & send change notifications to my dependents.
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    74
     Send the change message even if the value didn't change."
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    75
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    76
    self setValue:newValue.
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    77
    self changed:#value
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    78
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    79
    "Modified: 27.3.1997 / 15:14:04 / cg"
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    80
!
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    81
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    82
value 
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    83
    "return my value"
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    84
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    85
    ^ self subclassResponsibility
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    86
!
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    87
504
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    88
value:newValue
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    89
    "set my value & send change notifications to my dependents
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    90
     if it changed."
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    91
1156
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    92
"/    "/ mhmh - that seems to be what VW does ...
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    93
"/    "/ (i.e. always send a change message)
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    94
"/    self setValue:newValue.
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    95
"/    self changed:#value
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    96
504
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    97
    |oldValue|
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    98
504
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    99
    oldValue := self value.
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
   100
    oldValue ~~ newValue ifTrue:[
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
   101
        self setValue:newValue.
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
   102
        self changed:#value
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
   103
    ]
326
ab4e3df5c5d5 only ignore new value if identical to previous value.
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   104
504
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
   105
    "Modified: 27.3.1997 / 15:14:04 / cg"
796
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   106
!
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
value:newValue withoutNotifying:someOne
1095
ffd2aaae1a45 Fix typo (interrest -> interest)
Stefan Vogel <sv@exept.de>
parents: 796
diff changeset
   109
    "like #value, but temporarily retract all interests for someOne
796
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   110
     (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
   111
      to someOne; we cannot guarantee indirect notifications, though.)
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   112
     Useful if someone is itself depending on the receiver,
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   113
     and wants to avoid recursive update notifications."
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
    |oldInterests wasDependent|
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   116
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   117
    [
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   118
        oldInterests := self interestsFor:someOne.
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   119
        self retractInterestsFor:someOne.
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   120
        wasDependent := (self dependents includes:someOne).
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   121
        self removeDependent:someOne.
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   122
        
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   123
        self value:newValue.
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   124
    ] valueNowOrOnUnwindDo:[
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   125
        wasDependent ifTrue:[self addDependent:someOne].
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   126
        oldInterests do:[:i |
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   127
            self addInterest:i
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   128
        ].
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   129
    ].
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   130
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   131
    "Modified: / 30.1.1998 / 14:14:01 / cg"
62
194eb0590b1e Initial revision
claus
parents:
diff changeset
   132
! !
194eb0590b1e Initial revision
claus
parents:
diff changeset
   133
492
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   134
!ValueModel methodsFor:'converting'!
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   135
1156
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
   136
asValue
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
   137
    "return the receiver - it is already a valueHolder"
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
   138
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
   139
    ^ self
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
   140
!
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
   141
492
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   142
compute:aBlock
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   143
    "return a BlockValue on the receiver, which computes aBlock"
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   144
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   145
    ^ BlockValue with:aBlock arguments:(Array with:self)
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   146
! !
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   147
69
claus
parents: 68
diff changeset
   148
!ValueModel methodsFor:'initialization'!
claus
parents: 68
diff changeset
   149
claus
parents: 68
diff changeset
   150
initialize
441
b0d486981a62 unconditionally send a change notification;
Claus Gittinger <cg@exept.de>
parents: 326
diff changeset
   151
b0d486981a62 unconditionally send a change notification;
Claus Gittinger <cg@exept.de>
parents: 326
diff changeset
   152
    "Modified: 21.2.1997 / 16:29:38 / cg"
69
claus
parents: 68
diff changeset
   153
! !
claus
parents: 68
diff changeset
   154
773
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   155
!ValueModel methodsFor:'queries'!
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   156
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   157
isBuffering
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   158
    "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
   159
     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
   160
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   161
    ^ false
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   162
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   163
    "Created: / 27.1.1998 / 12:12:08 / cg"
1114
7b15d659f57e added #isValueModel
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   164
!
7b15d659f57e added #isValueModel
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   165
7b15d659f57e added #isValueModel
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   166
isValueModel
7b15d659f57e added #isValueModel
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   167
    "return true, if the receiver is some kind of valueModel;
7b15d659f57e added #isValueModel
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   168
     true returned here - redefined from Object"
7b15d659f57e added #isValueModel
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   169
7b15d659f57e added #isValueModel
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   170
    ^ true
773
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   171
! !
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   172
441
b0d486981a62 unconditionally send a change notification;
Claus Gittinger <cg@exept.de>
parents: 326
diff changeset
   173
!ValueModel class methodsFor:'documentation'!
129
f890eaabc487 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 125
diff changeset
   174
f890eaabc487 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 125
diff changeset
   175
version
1363
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
   176
    ^ '$Header: /cvs/stx/stx/libview2/ValueModel.st,v 1.28 2000-03-14 17:20:26 stefan Exp $'
129
f890eaabc487 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 125
diff changeset
   177
! !