Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 134224f8546d6bdaeeea6be9f53ad15d9a48625b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*******************************************************************************
 * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Soyatec & hceylan - initial API and implementation
 *******************************************************************************/
package org.eclipse.papyrus.xwt.databinding;

import org.eclipse.core.databinding.AggregateValidationStatus;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.UpdateListStrategy;
import org.eclipse.core.databinding.UpdateSetStrategy;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.ValidationStatusProvider;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.map.IObservableMap;
import org.eclipse.core.databinding.observable.set.IObservableSet;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.papyrus.xwt.XWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Widget;

/**
 * @author hceylan
 */
public class BindingContext implements IBindingContext {

	private org.eclipse.core.databinding.DataBindingContext context;

	private Realm realm;

	private AggregateValidationStatus status;

	private int statusType = MAX_SEVERITY;

	private final Widget parent;

	public BindingContext(Widget parent) {
		super();
		this.parent = parent;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#getContext()
	 */
	public org.eclipse.core.databinding.DataBindingContext getContext() {
		if (this.context == null) {
			if (this.realm != null) {
				this.context = new org.eclipse.core.databinding.DataBindingContext(this.realm);
			} else {
				this.context = new org.eclipse.core.databinding.DataBindingContext(XWT.getRealm());
			}

			if (this.parent != null) {
				this.parent.addDisposeListener(new DisposeListener() {

					public void widgetDisposed(DisposeEvent e) {
						context.dispose();
					}
				});
			}
		}
		return this.context;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#getRealm()
	 */
	public Realm getRealm() {
		return this.realm;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#getStatus()
	 */
	public AggregateValidationStatus getStatus() {
		if (this.status == null) {
			this.status = new AggregateValidationStatus(getContext(), this.statusType);
			if (this.parent != null) {
				this.parent.addDisposeListener(new DisposeListener() {

					public void widgetDisposed(DisposeEvent e) {
						status.dispose();
					}
				});
			}
		}
		return this.status;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#getStatusType()
	 */
	public int getStatusType() {
		return statusType;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#bindValue(org.eclipse.core.databinding.observable.value.IObservableValue,
	 * org.eclipse.core.databinding.observable.value.IObservableValue)
	 */
	public final Binding bindValue(IObservableValue targetObservableValue, IObservableValue modelObservableValue) {
		return getContext().bindValue(targetObservableValue, modelObservableValue);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof BindingContext)) {
			return false;
		}
		org.eclipse.core.databinding.DataBindingContext context = getContext();
		if (context != null) {
			return context.equals(((BindingContext) obj).getContext());
		}
		if (((BindingContext) obj).getContext() != null) {
			return false;
		}
		return super.equals(obj);
	}

	@Override
	public int hashCode() {
		return getContext().hashCode();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#bindValue(org.eclipse.core.databinding.observable.value.IObservableValue,
	 * org.eclipse.core.databinding.observable.value.IObservableValue, org.eclipse.core.databinding.UpdateValueStrategy,
	 * org.eclipse.core.databinding.UpdateValueStrategy)
	 */
	public final Binding bindValue(IObservableValue targetObservableValue, IObservableValue modelObservableValue, UpdateValueStrategy targetToModel, UpdateValueStrategy modelToTarget) {
		return getContext().bindValue(targetObservableValue, modelObservableValue, targetToModel, modelToTarget);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#bindList(org.eclipse.core.databinding.observable.list.IObservableList,
	 * org.eclipse.core.databinding.observable.list.IObservableList)
	 */
	public final Binding bindList(IObservableList targetObservableList, IObservableList modelObservableList) {
		return getContext().bindList(targetObservableList, modelObservableList);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#bindList(org.eclipse.core.databinding.observable.list.IObservableList,
	 * org.eclipse.core.databinding.observable.list.IObservableList, org.eclipse.core.databinding.UpdateListStrategy,
	 * org.eclipse.core.databinding.UpdateListStrategy)
	 */
	public final Binding bindList(IObservableList targetObservableList, IObservableList modelObservableList, UpdateListStrategy targetToModel, UpdateListStrategy modelToTarget) {
		return getContext().bindList(targetObservableList, modelObservableList, targetToModel, modelToTarget);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#bindSet(org.eclipse.core.databinding.observable.set.IObservableSet,
	 * org.eclipse.core.databinding.observable.set.IObservableSet)
	 */
	public final Binding bindSet(IObservableSet targetObservableSet, IObservableSet modelObservableSet) {
		return getContext().bindSet(targetObservableSet, modelObservableSet);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#bindSet(org.eclipse.core.databinding.observable.set.IObservableSet,
	 * org.eclipse.core.databinding.observable.set.IObservableSet, org.eclipse.core.databinding.UpdateSetStrategy,
	 * org.eclipse.core.databinding.UpdateSetStrategy)
	 */
	public final Binding bindSet(IObservableSet targetObservableSet, IObservableSet modelObservableSet, UpdateSetStrategy targetToModel, UpdateSetStrategy modelToTarget) {
		return getContext().bindSet(targetObservableSet, modelObservableSet, targetToModel, modelToTarget);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#dispose()
	 */
	public final void dispose() {
		getContext().dispose();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#getBindings()
	 */
	public final IObservableList getBindings() {
		return getContext().getBindings();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#getValidationStatusProviders()
	 */
	public final IObservableList getValidationStatusProviders() {
		return getContext().getValidationStatusProviders();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#getValidationStatusMap()
	 */
	public final IObservableMap getValidationStatusMap() {
		return getContext().getValidationStatusMap();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#addBinding(org.eclipse.core.databinding.Binding)
	 */
	public void addBinding(Binding binding) {
		getContext().addBinding(binding);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#addValidationStatusProvider(org.eclipse.core.databinding.ValidationStatusProvider)
	 */
	public void addValidationStatusProvider(ValidationStatusProvider validationStatusProvider) {
		getContext().addValidationStatusProvider(validationStatusProvider);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#updateModels()
	 */
	public final void updateModels() {
		getContext().updateModels();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#updateTargets()
	 */
	public final void updateTargets() {
		getContext().updateTargets();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#removeBinding(org.eclipse.core.databinding.Binding)
	 */
	public boolean removeBinding(Binding binding) {
		return getContext().removeBinding(binding);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * org.eclipse.papyrus.xwt.databinding.IDataBindingContext#removeValidationStatusProvider(org.eclipse.core.databinding.ValidationStatusProvider)
	 */
	public boolean removeValidationStatusProvider(ValidationStatusProvider validationStatusProvider) {
		return getContext().removeValidationStatusProvider(validationStatusProvider);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#getValidationRealm()
	 */
	public final Realm getValidationRealm() {
		return getContext().getValidationRealm();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#setRealm(org.eclipse.core.databinding.observable.Realm)
	 */
	public void setRealm(Realm realm) {
		this.realm = realm;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#setStatusType(int)
	 */
	public void setStatusType(int statusType) {
		this.statusType = statusType;
	}

}

Back to the top