75
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
69
|
13 |
Model subclass:#ValueModel
|
|
14 |
instanceVariableNames:'accepted interrest'
|
62
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
71
|
17 |
category:'Interface-Support-Models'
|
62
|
18 |
!
|
|
19 |
|
68
|
20 |
!ValueModel class methodsFor:'documentation'!
|
|
21 |
|
69
|
22 |
copyright
|
|
23 |
"
|
|
24 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
71
|
25 |
All Rights Reserved
|
69
|
26 |
|
|
27 |
This software is furnished under a license and may be used
|
|
28 |
only in accordance with the terms of that license and with the
|
|
29 |
inclusion of the above copyright notice. This software may not
|
|
30 |
be provided or otherwise made available to, or used by, any
|
|
31 |
other person. No title to or ownership of the software is
|
|
32 |
hereby transferred.
|
|
33 |
"
|
|
34 |
!
|
|
35 |
|
68
|
36 |
documentation
|
|
37 |
"
|
|
38 |
abstract superclass for ValueHolders and Adaptors.
|
69
|
39 |
It does not itself know how and where the value is stored,
|
|
40 |
but knows about interrested objects (which get informed, whenever
|
|
41 |
the value changes) and keeps track if the value was ever accepted.
|
68
|
42 |
|
|
43 |
Notice: this class was implemented using protocol information
|
|
44 |
from alpha testers - it may not be complete or compatible to
|
|
45 |
the corresponding ST-80 class. If you encounter any incompatibilities,
|
|
46 |
please forward a note to the ST/X team.
|
69
|
47 |
|
|
48 |
subclasses must redefine: #setValue: and #value
|
|
49 |
(and optionally redefine #value:)
|
68
|
50 |
"
|
125
|
51 |
!
|
|
52 |
|
|
53 |
version
|
|
54 |
^ '$Header: /cvs/stx/stx/libview2/ValueModel.st,v 1.12 1995-11-23 10:43:15 cg Exp $'
|
68
|
55 |
! !
|
|
56 |
|
62
|
57 |
!ValueModel class methodsFor:'instance creation'!
|
|
58 |
|
|
59 |
new
|
|
60 |
^ (super new) initialize
|
|
61 |
! !
|
|
62 |
|
125
|
63 |
!ValueModel methodsFor:'accessing'!
|
|
64 |
|
|
65 |
accept
|
|
66 |
accepted := true
|
|
67 |
!
|
62
|
68 |
|
125
|
69 |
accepted
|
|
70 |
^ accepted
|
|
71 |
!
|
|
72 |
|
|
73 |
setValue:newValue
|
|
74 |
"physically set my value, without change notifications"
|
|
75 |
|
|
76 |
^ self subclassResponsibility
|
|
77 |
!
|
73
|
78 |
|
125
|
79 |
value
|
|
80 |
"return my value"
|
|
81 |
|
|
82 |
^ self subclassResponsibility
|
|
83 |
!
|
|
84 |
|
|
85 |
value:anObject
|
|
86 |
"set my value, if it changed, send change notifications to my dependents."
|
|
87 |
|
|
88 |
|oldValue|
|
|
89 |
|
|
90 |
oldValue := self value.
|
|
91 |
self setValue:anObject.
|
|
92 |
anObject ~= oldValue ifTrue:[
|
|
93 |
"/ self notifyChange:#value
|
|
94 |
self changed:#value
|
|
95 |
]
|
62
|
96 |
! !
|
|
97 |
|
86
|
98 |
!ValueModel methodsFor:'change notification'!
|
|
99 |
|
|
100 |
changed:aSymbol
|
|
101 |
"notify my dependents and those that are interrested"
|
|
102 |
|
|
103 |
interrest notNil ifTrue:[
|
|
104 |
interrest keysAndValuesDo:[:someone :selector |
|
|
105 |
someone perform:selector
|
|
106 |
].
|
|
107 |
].
|
|
108 |
super changed:aSymbol
|
|
109 |
! !
|
|
110 |
|
69
|
111 |
!ValueModel methodsFor:'initialization'!
|
|
112 |
|
|
113 |
initialize
|
|
114 |
accepted := false
|
|
115 |
! !
|
|
116 |
|
|
117 |
!ValueModel methodsFor:'interrest'!
|
|
118 |
|
125
|
119 |
onChangeSend:selector to:someone
|
|
120 |
"add an interrest, arranging that
|
|
121 |
a message with selector will be sent to someone
|
|
122 |
when my value changes."
|
|
123 |
|
|
124 |
interrest isNil ifTrue:[
|
|
125 |
interrest := IdentityDictionary new
|
|
126 |
].
|
|
127 |
interrest at:someone put:selector
|
|
128 |
!
|
|
129 |
|
69
|
130 |
retractInterrestFor:someone
|
|
131 |
"release interrest i.e. do no longer send changeMsg to changeReceiver
|
|
132 |
iff someone is the changeReceiver.
|
|
133 |
This can be used to (temporarily) turn off information sends,
|
|
134 |
to break endless cycles (if two values change each other)"
|
|
135 |
|
|
136 |
interrest notNil ifTrue:[
|
|
137 |
interrest removeKey:someone ifAbsent:nil
|
|
138 |
]
|
125
|
139 |
! !
|
62
|
140 |
|