ValueModel.st
author Claus Gittinger <cg@exept.de>
Thu, 29 Sep 2011 13:19:54 +0200
changeset 2951 1c0bd26a6683
parent 1588 34e2502e4891
child 3004 ea33c918e116
permissions -rw-r--r--
version_CVS
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
"
1438
739c0e3e3993 pass the newValue as parameter with change-notification
Claus Gittinger <cg@exept.de>
parents: 1363
diff changeset
    12
"{ Package: 'stx:libview2' }"
739c0e3e3993 pass the newValue as parameter with change-notification
Claus Gittinger <cg@exept.de>
parents: 1363
diff changeset
    13
69
claus
parents: 68
diff changeset
    14
Model subclass:#ValueModel
441
b0d486981a62 unconditionally send a change notification;
Claus Gittinger <cg@exept.de>
parents: 326
diff changeset
    15
	instanceVariableNames:''
175
df08e5b663d0 let objects interest implementation do things
Claus Gittinger <cg@exept.de>
parents: 143
diff changeset
    16
	classVariableNames:''
df08e5b663d0 let objects interest implementation do things
Claus Gittinger <cg@exept.de>
parents: 143
diff changeset
    17
	poolDictionaries:''
df08e5b663d0 let objects interest implementation do things
Claus Gittinger <cg@exept.de>
parents: 143
diff changeset
    18
	category:'Interface-Support-Models'
62
194eb0590b1e Initial revision
claus
parents:
diff changeset
    19
!
194eb0590b1e Initial revision
claus
parents:
diff changeset
    20
441
b0d486981a62 unconditionally send a change notification;
Claus Gittinger <cg@exept.de>
parents: 326
diff changeset
    21
!ValueModel class methodsFor:'documentation'!
68
claus
parents: 66
diff changeset
    22
69
claus
parents: 68
diff changeset
    23
copyright
claus
parents: 68
diff changeset
    24
"
claus
parents: 68
diff changeset
    25
 COPYRIGHT (c) 1995 by Claus Gittinger
71
claus
parents: 70
diff changeset
    26
	      All Rights Reserved
69
claus
parents: 68
diff changeset
    27
claus
parents: 68
diff changeset
    28
 This software is furnished under a license and may be used
claus
parents: 68
diff changeset
    29
 only in accordance with the terms of that license and with the
claus
parents: 68
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
claus
parents: 68
diff changeset
    31
 be provided or otherwise made available to, or used by, any
claus
parents: 68
diff changeset
    32
 other person.  No title to or ownership of the software is
claus
parents: 68
diff changeset
    33
 hereby transferred.
claus
parents: 68
diff changeset
    34
"
claus
parents: 68
diff changeset
    35
!
claus
parents: 68
diff changeset
    36
68
claus
parents: 66
diff changeset
    37
documentation
claus
parents: 66
diff changeset
    38
"
claus
parents: 66
diff changeset
    39
    abstract superclass for ValueHolders and Adaptors.
69
claus
parents: 68
diff changeset
    40
    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
    41
    but knows about interested objects (which get informed, whenever
69
claus
parents: 68
diff changeset
    42
    the value changes) and keeps track if the value was ever accepted.
68
claus
parents: 66
diff changeset
    43
231
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    44
    Notice: 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    45
        this class was implemented using protocol information
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    46
        from alpha testers - it may not be complete or compatible to
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    47
        the corresponding ST-80 class. 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    48
        If you encounter any incompatibilities, please forward a note 
2fec6188bd28 examples
Claus Gittinger <cg@exept.de>
parents: 223
diff changeset
    49
        describing the incompatibility verbal (i.e. no code) to the ST/X team.
69
claus
parents: 68
diff changeset
    50
claus
parents: 68
diff changeset
    51
    subclasses must redefine: #setValue: and #value
claus
parents: 68
diff changeset
    52
    (and optionally redefine #value:)
223
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 175
diff changeset
    53
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 175
diff changeset
    54
    [author:]
b65dc250db8d documentation
Claus Gittinger <cg@exept.de>
parents: 175
diff changeset
    55
        Claus Gittinger
68
claus
parents: 66
diff changeset
    56
"
claus
parents: 66
diff changeset
    57
! !
claus
parents: 66
diff changeset
    58
441
b0d486981a62 unconditionally send a change notification;
Claus Gittinger <cg@exept.de>
parents: 326
diff changeset
    59
!ValueModel class methodsFor:'instance creation'!
62
194eb0590b1e Initial revision
claus
parents:
diff changeset
    60
194eb0590b1e Initial revision
claus
parents:
diff changeset
    61
new
1189
d1df42602935 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1156
diff changeset
    62
    ^ self basicNew initialize
62
194eb0590b1e Initial revision
claus
parents:
diff changeset
    63
! !
194eb0590b1e Initial revision
claus
parents:
diff changeset
    64
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    65
!ValueModel methodsFor:'accessing'!
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    66
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    67
setValue:newValue 
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    68
    "physically set my value, without change notifications"
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    69
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    70
    ^ self subclassResponsibility
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    71
!
73
claus
parents: 71
diff changeset
    72
1363
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    73
triggerValue:newValue
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    74
    "set my value & send change notifications to my dependents.
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    75
     Send the change message even if the value didn't change."
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    76
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    77
    self setValue:newValue.
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    78
    self changed:#value
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    79
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    80
    "Modified: 27.3.1997 / 15:14:04 / cg"
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    81
!
3f2ec69eece6 Define #triggerValue
Stefan Vogel <sv@exept.de>
parents: 1189
diff changeset
    82
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    83
value 
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    84
    "return my value"
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    85
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    86
    ^ self subclassResponsibility
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    87
!
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    88
504
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    89
value:newValue
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    90
    "set my value & send change notifications to my dependents
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    91
     if it changed."
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    92
1156
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    93
"/    "/ mhmh - that seems to be what VW does ...
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    94
"/    "/ (i.e. always send a change message)
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    95
"/    self setValue:newValue.
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    96
"/    self changed:#value
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    97
504
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
    98
    |oldValue|
125
fa5b5e4336bf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
    99
504
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
   100
    oldValue := self value.
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
   101
    oldValue ~~ newValue ifTrue:[
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
   102
        self setValue:newValue.
1438
739c0e3e3993 pass the newValue as parameter with change-notification
Claus Gittinger <cg@exept.de>
parents: 1363
diff changeset
   103
        self changed:#value with:newValue
504
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
   104
    ]
326
ab4e3df5c5d5 only ignore new value if identical to previous value.
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   105
504
b77cdd860259 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 492
diff changeset
   106
    "Modified: 27.3.1997 / 15:14:04 / cg"
796
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
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   109
value:newValue withoutNotifying:someOne
1095
ffd2aaae1a45 Fix typo (interrest -> interest)
Stefan Vogel <sv@exept.de>
parents: 796
diff changeset
   110
    "like #value, but temporarily retract all interests for someOne
796
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   111
     (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
   112
      to someOne; we cannot guarantee indirect notifications, though.)
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   113
     Useful if someone is itself depending on the receiver,
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   114
     and wants to avoid recursive update notifications."
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
    |oldInterests wasDependent|
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
    [
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   119
        oldInterests := self interestsFor:someOne.
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   120
        self retractInterestsFor:someOne.
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   121
        wasDependent := (self dependents includes:someOne).
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   122
        self removeDependent:someOne.
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   123
        
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   124
        self value:newValue.
1557
e5e78ee63670 #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 1438
diff changeset
   125
    ] ensure:[
796
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   126
        wasDependent ifTrue:[self addDependent:someOne].
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   127
        oldInterests do:[:i |
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   128
            self addInterest:i
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
5aca7d7a8f30 added #value:withoutNotifying:
Claus Gittinger <cg@exept.de>
parents: 773
diff changeset
   132
    "Modified: / 30.1.1998 / 14:14:01 / cg"
62
194eb0590b1e Initial revision
claus
parents:
diff changeset
   133
! !
194eb0590b1e Initial revision
claus
parents:
diff changeset
   134
492
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   135
!ValueModel methodsFor:'converting'!
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   136
1156
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
   137
asValue
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
   138
    "return the receiver - it is already a valueHolder"
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
   139
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
   140
    ^ self
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
   141
!
abdd5a7dce49 added #asValue & comment
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
   142
492
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   143
compute:aBlock
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   144
    "return a BlockValue on the receiver, which computes aBlock"
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   145
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   146
    ^ BlockValue with:aBlock arguments:(Array with:self)
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   147
! !
4a308c56cb06 added #compute: - conversion
ca
parents: 441
diff changeset
   148
773
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   149
!ValueModel methodsFor:'queries'!
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   150
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   151
isBuffering
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   152
    "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
   153
     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
   154
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   155
    ^ false
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
    "Created: / 27.1.1998 / 12:12:08 / cg"
1114
7b15d659f57e added #isValueModel
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   158
!
7b15d659f57e added #isValueModel
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   159
7b15d659f57e added #isValueModel
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   160
isValueModel
7b15d659f57e added #isValueModel
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   161
    "return true, if the receiver is some kind of valueModel;
7b15d659f57e added #isValueModel
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   162
     true returned here - redefined from Object"
7b15d659f57e added #isValueModel
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   163
7b15d659f57e added #isValueModel
Claus Gittinger <cg@exept.de>
parents: 1095
diff changeset
   164
    ^ true
773
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   165
! !
b6337f784d05 added #isBuffering (read not from trevis griggs)
Claus Gittinger <cg@exept.de>
parents: 504
diff changeset
   166
441
b0d486981a62 unconditionally send a change notification;
Claus Gittinger <cg@exept.de>
parents: 326
diff changeset
   167
!ValueModel class methodsFor:'documentation'!
129
f890eaabc487 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 125
diff changeset
   168
f890eaabc487 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 125
diff changeset
   169
version
2951
1c0bd26a6683 version_CVS
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   170
    ^ '$Header: /cvs/stx/stx/libview2/ValueModel.st,v 1.32 2011-09-29 11:19:54 cg Exp $'
129
f890eaabc487 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 125
diff changeset
   171
! !