KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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
12 package org.eclipse.jface.internal.databinding.provisional;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.jface.internal.databinding.provisional.observable.IDiff;
18 import org.eclipse.jface.internal.databinding.provisional.observable.IObservable;
19 import org.eclipse.jface.internal.databinding.provisional.validation.ValidationError;
20
21 /**
22  * The event that is passed to a #bindingEvent method of an IBindingListener.
23  * This class is not intended to be subclassed by clients.
24  *
25  * @since 1.0
26  */

27 public class BindingEvent {
28     /**
29      * (Non-API Method) Construct a BindingEvent.
30      *
31      * @param model
32      * @param target
33      * @param diff
34      * @param copyType
35      * @param pipelinePosition
36      * The initial processing pipeline position.
37      */

38     public BindingEvent(IObservable model, IObservable target, IDiff diff, int copyType,
39             int pipelinePosition) {
40         this.model = model;
41         this.target = target;
42         this.diff = diff;
43         this.copyType = copyType;
44         this.pipelinePosition = pipelinePosition;
45         createSymbolTable();
46     }
47
48     /**
49      * The model observable for the change that is being processed.
50      */

51     public final IObservable model;
52
53     /**
54      * The target observable for the change that is being processed.
55      */

56     public final IObservable target;
57     
58     /**
59      * The diff describing the change, or <code>null</code> if no diff is
60      * available.
61      */

62     public final IDiff diff;
63
64     /**
65      * The direction in which data is copied, either EVENT_COPY_TO_TARGET
66      * or EVENT_COPY_TO_MODEL.
67      */

68     public final int copyType;
69
70     /**
71      * The position in the processing pipeline where this event is occuring. One
72      * of the PIPELINE_* constants. The order in which these events occur may be
73      * version or implementation dependent. The contract is that these events
74      * will accurately reflect the internal processing that the data binding
75      * framework is currently performing.
76      * <p>
77      * Although this value is not declared final, changing it does not have any
78      * effect.
79      */

80     public int pipelinePosition;
81     
82     /**
83      * The current ValidationError object (if there is one).
84      */

85     public ValidationError validationError;
86
87     /**
88      * Holds the value that was retrieved from the source updatable. Setting the
89      * value of this field changes the value that will be processed by all
90      * subsequent steps in the data flow pipeline.
91      */

92     public Object JavaDoc originalValue = null;
93
94     /**
95      * Holds the value that will be copied into the final updatable. This value
96      * is null if the original value has not been converted into the final
97      * updatable's data type or if no conversion will be performed. Setting the
98      * value of this field changes the value that will be processed by all
99      * subsequent steps in the data flow pipeline.
100      */

101     public Object JavaDoc convertedValue = null;
102
103     /**
104      * A constant indicating that this event is occuring during a copy from
105      * model to target.
106      */

107     public static final int EVENT_COPY_TO_TARGET = 0;
108
109     /**
110      * A constant indicating that this event is occuring during a copy from
111      * target to model.
112      */

113     public static final int EVENT_COPY_TO_MODEL = 1;
114
115     /**
116      * A constant indicating that this event is occuring during a partial
117      * validation event.
118      */

119     public static final int EVENT_PARTIAL_VALIDATE = 2;
120
121     /**
122      * A constant indicating that this event is occuring during an element
123      * remove operation.
124      */

125     public static final int EVENT_REMOVE = 3;
126
127     /**
128      * A constant indicating that this event is occuring immedately after the
129      * value to copy has been gotten from its IUpdatable.
130      */

131     public static final int PIPELINE_AFTER_GET = 0;
132
133     /**
134      * A constant indicating that this event is occuring immedately after the
135      * value has been validated as being possible to convert to the other
136      * updatable's data type.
137      */

138     public static final int PIPELINE_AFTER_VALIDATE = 1;
139
140     /**
141      * A constant indicating that this event is occuring immedately after the
142      * original value has been converted to the other updatable's data type.
143      */

144     public static final int PIPELINE_AFTER_CONVERT = 2;
145
146     /**
147      * A constant indicating that this event is occuring immedately after the
148      * business rule validation has occured.
149      */

150     public static final int PIPELINE_AFTER_BUSINESS_VALIDATE = 3;
151
152     /**
153      * A constant indicating that this event is occuring immedately after the
154      * converted value has been set/changed on the updatable.
155      */

156     public static final int PIPELINE_AFTER_CHANGE = 4;
157     
158     /**
159      * A constant indicating that this event is occuring due to either a validation
160      * error or warning occuring.
161      */

162     public static final int PIPELINE_VALIDATION_ERROR_OR_WARNING = 5;
163
164     /**
165      * A Map of Integer --> String mapping the integer constants for the
166      * pipeline events defined in this class to their String symbols.
167      */

168     public final Map JavaDoc pipelineConstants = new HashMap JavaDoc();
169     private HashMap JavaDoc eventConstants = new HashMap JavaDoc();
170
171     /**
172      * Creates a table of constants from this class.
173      */

174     private void createSymbolTable() {
175         eventConstants.put(new Integer JavaDoc(0), "EVENT_COPY_TO_TARGET"); //$NON-NLS-1$
176
eventConstants.put(new Integer JavaDoc(1), "EVENT_COPY_TO_MODEL"); //$NON-NLS-1$
177
eventConstants.put(new Integer JavaDoc(2), "EVENT_PARTIAL_VALIDATE"); //$NON-NLS-1$
178
eventConstants.put(new Integer JavaDoc(3), "EVENT_REMOVE"); //$NON-NLS-1$
179

180         pipelineConstants.put(new Integer JavaDoc(0), "PIPELINE_AFTER_GET"); //$NON-NLS-1$
181
pipelineConstants.put(new Integer JavaDoc(1), "PIPELINE_AFTER_VALIDATE"); //$NON-NLS-1$
182
pipelineConstants.put(new Integer JavaDoc(2), "PIPELINE_AFTER_CONVERT"); //$NON-NLS-1$
183
pipelineConstants.put(new Integer JavaDoc(3),
184                 "PIPELINE_AFTER_BUSINESS_VALIDATE"); //$NON-NLS-1$
185
pipelineConstants.put(new Integer JavaDoc(4), "PIPELINE_AFTER_CHANGE"); //$NON-NLS-1$
186
}
187
188     /*
189      * (non-Javadoc)
190      *
191      * @see java.lang.Object#toString()
192      */

193     public String JavaDoc toString() {
194         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
195         result.append("(" + eventConstants.get(new Integer JavaDoc(copyType)) + ", "); //$NON-NLS-1$ //$NON-NLS-2$
196
result.append(pipelineConstants.get(new Integer JavaDoc(pipelinePosition)));
197         result.append("): Diff(" + diff + ")"); //$NON-NLS-1$ //$NON-NLS-2$
198
return result.toString();
199     }
200
201 }
202
Popular Tags