KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > internal > databinding > provisional > BindSpec


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jface.internal.databinding.provisional;
12
13 import org.eclipse.jface.internal.databinding.provisional.conversion.IConverter;
14 import org.eclipse.jface.internal.databinding.provisional.validation.IDomainValidator;
15 import org.eclipse.jface.internal.databinding.provisional.validation.IValidator;
16
17 /**
18  * Data binding has three concerns, the target, the model, and the data flow
19  * between the target and model. BindSpec contains values and settings that
20  * influence how data binding manages this data flow between the target and
21  * the model.
22  *
23  * @since 3.2
24  */

25 public class BindSpec {
26
27     private IConverter[] modelToTargetConverters = new IConverter[1];;
28
29     private IConverter[] targetToModelConverters = new IConverter[1];;
30
31     private IValidator[] targetValidators = new IValidator[1];
32
33     private IDomainValidator domainValidator;
34
35     private Integer JavaDoc modelUpdatePolicy;
36
37     private Integer JavaDoc validatePolicy;
38
39     private Integer JavaDoc targetUpdatePolicy;
40
41     private boolean updateModel = true;
42
43     private boolean updateTarget = true;
44
45     /**
46      * Creates a bind spec with the given converters, validators, and update
47      * policies.
48      *
49      * @param modelToTargetConverter
50      * @param targetToModelConverter
51      * @param targetValidator
52      * @param domainValidator
53      * @param modelUpdatePolicy
54      * @param validatePolicy
55      * @param targetUpdatePolicy
56      *
57      */

58     public BindSpec(IConverter modelToTargetConverter,
59             IConverter targetToModelConverter, IValidator targetValidator,
60             IDomainValidator domainValidator, Integer JavaDoc modelUpdatePolicy,
61             Integer JavaDoc validatePolicy, Integer JavaDoc targetUpdatePolicy) {
62         
63         this.modelToTargetConverters[0] = modelToTargetConverter;
64         this.targetToModelConverters[0] = targetToModelConverter;
65         this.targetValidators[0] = targetValidator;
66         this.domainValidator = domainValidator;
67         this.modelUpdatePolicy = modelUpdatePolicy;
68         this.validatePolicy = validatePolicy;
69         this.targetUpdatePolicy = targetUpdatePolicy;
70     }
71
72     /**
73      * Creates a bind spec with the given converters, validators, and update
74      * policies.
75      *
76      * @param modelToTargetConverter
77      * @param targetToModelConverter
78      * @param targetValidator
79      * @param domainValidator
80      * @param modelUpdatePolicy
81      * @param validatePolicy
82      * @param targetUpdatePolicy
83      *
84      */

85     public BindSpec(IConverter[] modelToTargetConverter,
86             IConverter[] targetToModelConverter, IValidator[] targetValidator,
87             IDomainValidator domainValidator, Integer JavaDoc modelUpdatePolicy,
88             Integer JavaDoc validatePolicy, Integer JavaDoc targetUpdatePolicy) {
89         
90         this.modelToTargetConverters = modelToTargetConverter;
91         this.targetToModelConverters = targetToModelConverter;
92         this.targetValidators = targetValidator;
93         this.domainValidator = domainValidator;
94         this.modelUpdatePolicy = modelUpdatePolicy;
95         this.validatePolicy = validatePolicy;
96         this.targetUpdatePolicy = targetUpdatePolicy;
97     }
98
99     /**
100      * Creates a bind spec with the given converter and validator. The update
101      * policies are set to <code>IBindSpec.POLICY_CONTEXT</code>.
102      *
103      * @param modelToTargetConverter
104      * @param targetToModelConverter
105      * @param targetValidator
106      * @param domainValidator
107      *
108      */

109     public BindSpec(IConverter modelToTargetConverter,
110             IConverter targetToModelConverter, IValidator targetValidator,
111             IDomainValidator domainValidator) {
112         this(modelToTargetConverter, targetToModelConverter, targetValidator,
113                 domainValidator, null, null, null);
114     }
115
116     /**
117      *
118      */

119     public BindSpec() {
120         this((IConverter)null, null, null, null, null, null, null);
121     }
122
123     /**
124      * Returns the converter to be used, or <code>null</code> if a default
125      * converter should be used.
126      *
127      * @return the converter, or <code>null</code>
128      */

129     public IConverter getModelToTargetConverter() {
130         return modelToTargetConverters[0];
131     }
132
133     /**
134      * Returns the converters to be used
135      *
136      * @return the converters</code>
137      */

138     public IConverter[] getModelToTargetConverters() {
139         return modelToTargetConverters;
140     }
141
142     /**
143      * Returns the converter to be used, or <code>null</code> if a default
144      * converter should be used.
145      *
146      * @return the converter, or <code>null</code>
147      */

148     public IConverter getTargetToModelConverter() {
149         return targetToModelConverters[0];
150     }
151     
152     /**
153      * Returns the converters to be used
154      *
155      * @return the converters</code>
156      */

157     public IConverter[] getTargetToModelConverters() {
158         return targetToModelConverters;
159     }
160
161     /**
162      * Returns the validator to be used, or <code>null</code> if a default
163      * validator should be used.
164      *
165      * @return the validator, or <code>null</code>
166      */

167     public IValidator getTypeConversionValidator() {
168         return targetValidators[0];
169     }
170
171     /**
172      * Returns the validators to be used.
173      *
174      * @return the validators</code>
175      */

176     public IValidator[] getTypeConversionValidators() {
177         return targetValidators;
178     }
179     
180     /**
181      * Returns the validator to be used, or <code>null</code> if a default
182      * validator should be used.
183      *
184      * @return the validator, or <code>null</code>
185      */

186     public IDomainValidator getDomainValidator() {
187         return domainValidator;
188     }
189
190     /**
191      * Returns the update policy to be used for updating the model when the
192      * target has changed
193      *
194      * @return the update policy, or <code>null</code> if unspecified
195      *
196      * @see DataBindingContext#POLICY_AUTOMATIC
197      * @see DataBindingContext#POLICY_EXPLICIT
198      */

199     public Integer JavaDoc getModelUpdatePolicy() {
200         return modelUpdatePolicy;
201     }
202
203     /**
204      * Returns the validate policy to be used for validating changes to the
205      * target
206      *
207      * @return the update policy, or <code>null</code> if unspecified
208      *
209      * @see DataBindingContext#POLICY_AUTOMATIC
210      * @see DataBindingContext#POLICY_EXPLICIT
211      */

212     public Integer JavaDoc getValidatePolicy() {
213         return validatePolicy;
214     }
215
216     /**
217      * Returns the update policy to be used for updating the target when the
218      * model has changed
219      *
220      * @return the update policy, or <code>null</code> if unspecified
221      *
222      * @see DataBindingContext#POLICY_AUTOMATIC
223      * @see DataBindingContext#POLICY_EXPLICIT
224      */

225     public Integer JavaDoc getTargetUpdatePolicy() {
226         return targetUpdatePolicy;
227     }
228
229     /**
230      * @param converter
231      * @return this BindSpec, to enable chaining of method calls
232      */

233     public BindSpec setModelToTargetConverter(IConverter converter) {
234         this.modelToTargetConverters[0] = converter;
235         return this;
236     }
237
238     /**
239      * @param converters
240      * @return this BindSpec, to enable chaining of method calls
241      */

242     public BindSpec setModelToTargetConverters(IConverter[] converters) {
243         this.modelToTargetConverters = converters;
244         return this;
245     }
246
247     /**
248      * @param converter
249      * @return this BindSpec, to enable chaining of method calls
250      */

251     public BindSpec setTargetToModelConverter(IConverter converter) {
252         this.targetToModelConverters[0] = converter;
253         return this;
254     }
255
256     /**
257      * @param converters
258      * @return this BindSpec, to enable chaining of method calls
259      */

260     public BindSpec setTargetToModelConverters(IConverter[] converters) {
261         this.modelToTargetConverters = converters;
262         return this;
263     }
264
265     /**
266      * @param validator
267      * @return this BindSpec, to enable chaining of method calls
268      */

269     public BindSpec setValidator(IValidator validator) {
270         this.targetValidators[0] = validator;
271         return this;
272     }
273
274     /**
275      * @param validators
276      * @return this BindSpec, to enable chaining of method calls
277      */

278     public BindSpec setValidators(IValidator[] validators) {
279         this.targetValidators = validators;
280         return this;
281     }
282     
283     /**
284      * @param validator
285      * @return this BindSpec, to enable chaining of method calls
286      */

287     public BindSpec setDomainValidator(IDomainValidator validator) {
288         this.domainValidator = validator;
289         return this;
290     }
291
292     /**
293      * @return true if the model should be updated by the binding
294      */

295     public boolean updateModel() {
296         return updateModel;
297     }
298
299     /**
300      * @return true if the target should be updated by the binding
301      */

302     public boolean updateTarget() {
303         return updateTarget;
304     }
305
306     /**
307      * @param updateModel
308      * The updateModel to set.
309      * @return this BindSpec, to enable chaining of method calls
310      */

311     public BindSpec setUpdateModel(boolean updateModel) {
312         this.updateModel = updateModel;
313         return this;
314     }
315
316     /**
317      * @param updateTarget
318      * The updateTarget to set.
319      * @return this BindSpec, to enable chaining of method calls
320      */

321     public BindSpec setUpdateTarget(boolean updateTarget) {
322         this.updateTarget = updateTarget;
323         return this;
324     }
325
326     /**
327      * @param modelUpdatePolicy
328      * The modelUpdatePolicy to set.
329      * @return this BindSpec, to enable chaining of method calls
330      */

331     public BindSpec setModelUpdatePolicy(Integer JavaDoc modelUpdatePolicy) {
332         this.modelUpdatePolicy = modelUpdatePolicy;
333         return this;
334     }
335
336     /**
337      * @param targetUpdatePolicy
338      * The targetUpdatePolicy to set.
339      * @return this BindSpec, to enable chaining of method calls
340      */

341     public BindSpec setTargetUpdatePolicy(Integer JavaDoc targetUpdatePolicy) {
342         this.targetUpdatePolicy = targetUpdatePolicy;
343         return this;
344     }
345
346     /**
347      * @param validatePolicy
348      * The validatePolicy to set.
349      * @return this BindSpec, to enable chaining of method calls
350      */

351     public BindSpec setValidatePolicy(Integer JavaDoc validatePolicy) {
352         this.validatePolicy = validatePolicy;
353         return this;
354     }
355
356 }
357
Popular Tags