78
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2006, 2008 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 * Boris Bokowski - bug 218269
|
|
12 * Matthew Hall - bug 218269
|
|
13 *******************************************************************************/
|
|
14
|
|
15 module org.eclipse.core.databinding.Binding;
|
81
|
16 import org.eclipse.core.databinding.DataBindingContext;
|
|
17 import org.eclipse.core.databinding.ValidationStatusProvider;
|
78
|
18
|
|
19 import java.lang.all;
|
|
20
|
|
21 import java.util.Collections;
|
|
22
|
|
23 import org.eclipse.core.databinding.observable.IObservable;
|
|
24 import org.eclipse.core.databinding.observable.Observables;
|
|
25 import org.eclipse.core.databinding.observable.list.IObservableList;
|
|
26 import org.eclipse.core.databinding.observable.value.IObservableValue;
|
|
27
|
|
28 /**
|
|
29 * This abstract class represents a binding between a model and a target. Newly
|
|
30 * created instances need to be added to a data binding context using
|
|
31 * {@link #initcast(DataBindingContext)}.
|
|
32 *
|
|
33 * @since 1.0
|
|
34 */
|
|
35 public abstract class Binding : ValidationStatusProvider {
|
|
36
|
|
37 protected DataBindingContext context;
|
|
38 private IObservable target;
|
|
39 private IObservable model;
|
|
40
|
|
41 /**
|
|
42 * Creates a new binding.
|
|
43 *
|
|
44 * @param target target observable
|
|
45 * @param model model observable
|
|
46 */
|
|
47 public this(IObservable target, IObservable model) {
|
|
48 this.target = target;
|
|
49 this.model = model;
|
|
50 }
|
|
51
|
|
52 /**
|
|
53 * Initializes this binding with the given context and adds it to the list
|
|
54 * of bindings of the context.
|
|
55 * <p>
|
|
56 * Subclasses may extend, but must call the super implementation.
|
|
57 * </p>
|
|
58 *
|
|
59 * @param context
|
|
60 */
|
|
61 public final void init(DataBindingContext context) {
|
|
62 this.context = context;
|
|
63 preInit();
|
|
64 context.addBinding(this);
|
|
65 postInit();
|
|
66 }
|
|
67
|
|
68 /**
|
|
69 * Called by {@link #initcast(DataBindingContext)} after setting
|
|
70 * {@link #context} but before adding this binding to the context.
|
|
71 * Subclasses may use this method to perform initialization that could not
|
|
72 * be done in the constructor. Care should be taken not to cause any events
|
|
73 * while running this method.
|
|
74 */
|
|
75 protected abstract void preInit();
|
|
76
|
|
77 /**
|
|
78 * Called by {@link #initcast(DataBindingContext)} after adding this binding to
|
|
79 * the context. Subclasses may use this method to perform initialization
|
|
80 * that may cause events to be fired, including BindingEvents that are
|
|
81 * forwarded to the data binding context.
|
|
82 */
|
|
83 protected abstract void postInit();
|
|
84
|
|
85 /**
|
|
86 * @return an observable value containing the current validation status
|
|
87 */
|
|
88 public abstract IObservableValue getValidationStatus();
|
|
89
|
|
90 /**
|
|
91 * Updates the model's state from the target's state at the next reasonable
|
|
92 * opportunity. There is no guarantee that the state will have been updated
|
|
93 * by the time this call returns.
|
|
94 */
|
|
95 public abstract void updateTargetToModel();
|
|
96
|
|
97 /**
|
|
98 * Updates the target's state from the model's state at the next reasonable
|
|
99 * opportunity. There is no guarantee that the state will have been updated
|
|
100 * by the time this call returns.
|
|
101 */
|
|
102 public abstract void updateModelToTarget();
|
|
103
|
|
104 /**
|
|
105 * Validates the target's state at the next reasonable
|
|
106 * opportunity. There is no guarantee that the validation status will have been updated
|
|
107 * by the time this call returns.
|
|
108 */
|
|
109 public abstract void validateTargetToModel();
|
|
110
|
|
111 /**
|
|
112 * Validates the model's state at the next reasonable
|
|
113 * opportunity. There is no guarantee that the validation status will have been updated
|
|
114 * by the time this call returns.
|
|
115 */
|
|
116 public abstract void validateModelToTarget();
|
|
117
|
|
118 /**
|
|
119 * Disposes of this Binding. Subclasses may extend, but must call super.dispose().
|
|
120 */
|
|
121 public void dispose() {
|
|
122 if (context !is null) {
|
|
123 context.removeBinding(this);
|
|
124 }
|
|
125 context = null;
|
|
126 target = null;
|
|
127 model = null;
|
|
128 super.dispose();
|
|
129 }
|
|
130
|
|
131 /**
|
|
132 * @param context
|
|
133 */
|
|
134 /* package */ void setDataBindingContext(DataBindingContext context) {
|
|
135 this.context = context;
|
|
136 }
|
|
137
|
|
138 /**
|
|
139 * @return target observable
|
|
140 */
|
|
141 public IObservable getTarget() {
|
|
142 return target;
|
|
143 }
|
|
144
|
|
145 /**
|
|
146 * @since 1.1
|
|
147 */
|
|
148 public IObservableList getTargets() {
|
|
149 return Observables.staticObservableList(context.getValidationRealm(),
|
|
150 Collections.singletonList(target));
|
|
151 }
|
|
152
|
|
153 /**
|
|
154 * @return model observable
|
|
155 */
|
|
156 public IObservable getModel() {
|
|
157 return model;
|
|
158 }
|
|
159
|
|
160 /**
|
|
161 * @since 1.1
|
|
162 */
|
|
163 public IObservableList getModels() {
|
|
164 return Observables.staticObservableList(context.getValidationRealm(),
|
|
165 Collections.singletonList(model));
|
|
166 }
|
|
167 }
|