71
|
1 |
ValueHolder subclass:#BufferedValueHolder
|
|
2 |
instanceVariableNames:'subject triggerChannel bufferedValue'
|
|
3 |
classVariableNames:'NotYetAssigned'
|
|
4 |
poolDictionaries:''
|
|
5 |
category:'Interface-Support-Models'
|
|
6 |
!
|
|
7 |
|
|
8 |
!BufferedValueHolder class methodsFor:'documentation'!
|
|
9 |
|
|
10 |
copyright
|
|
11 |
"
|
|
12 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
13 |
All Rights Reserved
|
|
14 |
|
|
15 |
This software is furnished under a license and may be used
|
|
16 |
only in accordance with the terms of that license and with the
|
|
17 |
inclusion of the above copyright notice. This software may not
|
|
18 |
be provided or otherwise made available to, or used by, any
|
|
19 |
other person. No title to or ownership of the software is
|
|
20 |
hereby transferred.
|
|
21 |
"
|
|
22 |
!
|
|
23 |
|
|
24 |
version
|
|
25 |
"
|
|
26 |
$Header: /cvs/stx/stx/libview2/BufferedValueHolder.st,v 1.1 1995-05-10 02:24:45 claus Exp $
|
|
27 |
"
|
|
28 |
!
|
|
29 |
|
|
30 |
documentation
|
|
31 |
"
|
|
32 |
a bufferedValueHolder keeps atemporary copy of the realHolders value,
|
|
33 |
and only does a real store of the value when triggered.
|
|
34 |
Triggering is done by depending on a trigger objects value, which is
|
|
35 |
typically a ValueHolder for a boolean, which is set by an ok-button.
|
|
36 |
|
|
37 |
Notice: this class was implemented using protocol information
|
|
38 |
from alpha testers - it may not be complete or compatible to
|
|
39 |
the corresponding ST-80 class. If you encounter any incompatibilities,
|
|
40 |
please forward a note to the ST/X team.
|
|
41 |
"
|
|
42 |
!
|
|
43 |
|
|
44 |
examples
|
|
45 |
"
|
|
46 |
unbuffered (even if not accepted, are the values updated if
|
|
47 |
a field is left with Return or accept is done in a field):
|
|
48 |
|
|
49 |
|firstName lastName dialog|
|
|
50 |
|
|
51 |
firstName := 'foo' asString.
|
|
52 |
lastName := 'bar' asString.
|
|
53 |
|
|
54 |
dialog := Dialog new.
|
|
55 |
(dialog addTextLabel:'Name:') layout:#left.
|
|
56 |
dialog addInputFieldOn:firstName.
|
|
57 |
dialog addVerticalSpace.
|
|
58 |
(dialog addTextLabel:'Address:') layout:#left.
|
|
59 |
dialog addInputFieldOn:lastName.
|
|
60 |
|
|
61 |
dialog addAbortButton; addOkButton.
|
|
62 |
|
|
63 |
dialog open.
|
|
64 |
|
|
65 |
Transcript show:firstName value; show:' '; showCr:lastName value
|
|
66 |
|
|
67 |
buffered (even if not accepted, are the values updated if
|
|
68 |
a field is left with Return or accept is done in a field):
|
|
69 |
|
|
70 |
|firstName lastName trigger dialog|
|
|
71 |
|
|
72 |
firstName := 'foo' asString.
|
|
73 |
lastName := 'bar' asString.
|
|
74 |
trigger := ValueHolder new.
|
|
75 |
|
|
76 |
dialog := Dialog new.
|
|
77 |
(dialog addTextLabel:'Name:') layout:#left.
|
|
78 |
dialog addInputFieldOn:(BufferedValueHolder
|
|
79 |
subject:firstName
|
|
80 |
triggerChannel:trigger).
|
|
81 |
dialog addVerticalSpace.
|
|
82 |
(dialog addTextLabel:'Address:') layout:#left.
|
|
83 |
dialog addInputFieldOn:(BufferedValueHolder
|
|
84 |
subject:lastName
|
|
85 |
triggerChannel:trigger).
|
|
86 |
|
|
87 |
dialog addAbortButton;
|
|
88 |
addButton:(Button new
|
|
89 |
label:'undo';
|
|
90 |
action:[trigger value:false]);
|
|
91 |
addOkButton.
|
|
92 |
|
|
93 |
dialog open.
|
|
94 |
|
|
95 |
Transcript show:firstName value; show:' '; showCr:lastName value
|
|
96 |
"
|
|
97 |
! !
|
|
98 |
|
|
99 |
!BufferedValueHolder class methodsFor:'initialization'!
|
|
100 |
|
|
101 |
intialize
|
|
102 |
NotYetAssigned := Object new
|
|
103 |
! !
|
|
104 |
|
|
105 |
!BufferedValueHolder class methodsFor:'instance creation'!
|
|
106 |
|
|
107 |
subject:someModel triggerChannel:aTrigger
|
|
108 |
"return a new BufferedValueHolder offering a buffered copy of someModels
|
|
109 |
value - only updating this value, when aTrigger changes to true."
|
|
110 |
|
|
111 |
^ self new subject:someModel; triggerChannel:aTrigger
|
|
112 |
! !
|
|
113 |
|
|
114 |
!BufferedValueHolder methodsFor:'initialization'!
|
|
115 |
|
|
116 |
initialize
|
|
117 |
super initialize.
|
|
118 |
bufferedValue := NotYetAssigned
|
|
119 |
! !
|
|
120 |
|
|
121 |
!BufferedValueHolder methodsFor:'change & update'!
|
|
122 |
|
|
123 |
update:something with:aParameter from:changedObject
|
|
124 |
changedObject == triggerChannel ifTrue:[
|
|
125 |
triggerChannel value == true ifTrue:[
|
|
126 |
"
|
|
127 |
now, store the buffered value into the subject
|
|
128 |
"
|
|
129 |
subject value:bufferedValue.
|
|
130 |
^ self
|
|
131 |
].
|
|
132 |
triggerChannel value == false ifTrue:[
|
|
133 |
"
|
|
134 |
cancel: flush my buffered value
|
|
135 |
"
|
|
136 |
bufferedValue := NotYetAssigned.
|
|
137 |
].
|
|
138 |
self notifyChange:#value.
|
|
139 |
^ self
|
|
140 |
].
|
|
141 |
changedObject == subject ifTrue:[
|
|
142 |
bufferedValue := NotYetAssigned.
|
|
143 |
self notifyChange:#value.
|
|
144 |
^ self
|
|
145 |
].
|
|
146 |
! !
|
|
147 |
|
|
148 |
!BufferedValueHolder methodsFor:'accessing'!
|
|
149 |
|
|
150 |
subject:someModel
|
|
151 |
subject notNil ifTrue:[
|
|
152 |
subject removeDependent:self
|
|
153 |
].
|
|
154 |
subject := someModel.
|
|
155 |
subject notNil ifTrue:[
|
|
156 |
subject addDependent:self
|
|
157 |
]
|
|
158 |
!
|
|
159 |
|
|
160 |
triggerChannel:aTrigger
|
|
161 |
triggerChannel notNil ifTrue:[
|
|
162 |
triggerChannel removeDependent:self
|
|
163 |
].
|
|
164 |
triggerChannel := aTrigger.
|
|
165 |
triggerChannel notNil ifTrue:[
|
|
166 |
triggerChannel addDependent:self
|
|
167 |
]
|
|
168 |
!
|
|
169 |
|
|
170 |
setValue:anObject
|
|
171 |
"set my value without notification."
|
|
172 |
|
|
173 |
bufferedValue := anObject.
|
|
174 |
!
|
|
175 |
|
|
176 |
value
|
|
177 |
"return my value"
|
|
178 |
|
|
179 |
bufferedValue == NotYetAssigned ifTrue:[
|
|
180 |
bufferedValue := subject value
|
|
181 |
].
|
|
182 |
^ bufferedValue
|
|
183 |
! !
|