KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > databinding > Binding


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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  * Brad Reynolds - bug 159768
11  *******************************************************************************/

12
13 package org.eclipse.core.databinding;
14
15 import org.eclipse.core.databinding.observable.IObservable;
16 import org.eclipse.core.databinding.observable.value.IObservableValue;
17
18 /**
19  * This abstract class represents a binding between a model and a target. Newly
20  * created instances need to be added to a data binding context using
21  * {@link #init(DataBindingContext)}.
22  *
23  * @since 1.0
24  */

25 public abstract class Binding {
26
27     protected DataBindingContext context;
28     private IObservable target;
29     private IObservable model;
30     
31     /**
32      * Creates a new binding.
33      *
34      * @param target target observable
35      * @param model model observable
36      */

37     public Binding(IObservable target, IObservable model) {
38         this.target = target;
39         this.model = model;
40     }
41     
42     /**
43      * Initializes this binding with the given context and adds it to the list
44      * of bindings of the context.
45      * <p>
46      * Subclasses may extend, but must call the super implementation.
47      * </p>
48      *
49      * @param context
50      */

51     public final void init(DataBindingContext context) {
52         this.context = context;
53         preInit();
54         context.addBinding(this);
55         postInit();
56     }
57     
58     /**
59      * Called by {@link #init(DataBindingContext)} after setting
60      * {@link #context} but before adding this binding to the context.
61      * Subclasses may use this method to perform initialization that could not
62      * be done in the constructor. Care should be taken not to cause any events
63      * while running this method.
64      */

65     protected abstract void preInit();
66     
67     /**
68      * Called by {@link #init(DataBindingContext)} after adding this binding to
69      * the context. Subclasses may use this method to perform initialization
70      * that may cause events to be fired, including BindingEvents that are
71      * forwarded to the data binding context.
72      */

73     protected abstract void postInit();
74
75     /**
76      * @return an observable value containing the current validation status
77      */

78     public abstract IObservableValue getValidationStatus();
79
80     /**
81      * Updates the model's state from the target's state at the next reasonable
82      * opportunity. There is no guarantee that the state will have been updated
83      * by the time this call returns.
84      */

85     public abstract void updateTargetToModel();
86
87     /**
88      * Updates the target's state from the model's state at the next reasonable
89      * opportunity. There is no guarantee that the state will have been updated
90      * by the time this call returns.
91      */

92     public abstract void updateModelToTarget();
93     
94     /**
95      * Validates the target's state at the next reasonable
96      * opportunity. There is no guarantee that the validation status will have been updated
97      * by the time this call returns.
98      */

99     public abstract void validateTargetToModel();
100     
101     /**
102      * Validates the model's state at the next reasonable
103      * opportunity. There is no guarantee that the validation status will have been updated
104      * by the time this call returns.
105      */

106     public abstract void validateModelToTarget();
107     
108     /**
109      * Disposes of this Binding. Subclasses may extend, but must call super.dispose().
110      */

111     public void dispose() {
112         if (context != null) {
113             context.removeBinding(this);
114         }
115         context = null;
116         target = null;
117         model = null;
118         disposed = true;
119     }
120
121     protected boolean disposed = false;
122     
123     /**
124      * @return true if the binding has been disposed. false otherwise.
125      */

126     public boolean isDisposed() {
127         return disposed;
128     }
129
130     /**
131      * @param context
132      */

133     /* package */ void setDataBindingContext(DataBindingContext context) {
134         this.context = context;
135     }
136
137     /**
138      * @return target observable
139      */

140     public IObservable getTarget() {
141         return target;
142     }
143     
144     /**
145      * @return model observable
146      */

147     public IObservable getModel() {
148         return model;
149     }
150 }
151
Popular Tags