comparison org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/AbstractObservable.d @ 78:0a55d2d5a946

Added file for databinding
author Frank Benoit <benoit@tionex.de>
date Tue, 14 Apr 2009 11:35:29 +0200
parents
children 383ce7bd736b
comparison
equal deleted inserted replaced
76:f05e6e8b2f2d 78:0a55d2d5a946
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 164653
11 * Matthew Hall - bug 118516
12 *******************************************************************************/
13
14 module org.eclipse.core.databinding.observable.AbstractObservable;
15
16 import java.lang.all;
17
18 import org.eclipse.core.runtime.Assert;
19 import org.eclipse.core.runtime.AssertionFailedException;
20
21 /**
22 * @since 1.0
23 */
24 public abstract class AbstractObservable : ChangeManager , IObservable {
25
26 /**
27 * @param realm
28 */
29 public this(Realm realm) {
30 super(realm);
31 }
32
33 public synchronized void addChangeListener(IChangeListener listener) {
34 addListener(ChangeEvent.TYPE, listener);
35 }
36
37 public synchronized void removeChangeListener(IChangeListener listener) {
38 removeListener(ChangeEvent.TYPE, listener);
39 }
40
41 public synchronized void addStaleListener(IStaleListener listener) {
42 addListener(StaleEvent.TYPE, listener);
43 }
44
45 public synchronized void removeStaleListener(IStaleListener listener) {
46 removeListener(StaleEvent.TYPE, listener);
47 }
48
49 protected void fireChange() {
50 checkRealm();
51 fireEvent(new ChangeEvent(this));
52 }
53
54 protected void fireStale() {
55 checkRealm();
56 fireEvent(new StaleEvent(this));
57 }
58
59 /**
60 *
61 */
62 public synchronized void dispose() {
63 super.dispose();
64 }
65
66 /**
67 * Asserts that the realm is the current realm.
68 *
69 * @see Realm#isCurrent()
70 * @throws AssertionFailedException if the realm is not the current realm
71 */
72 protected void checkRealm() {
73 Assert.isTrue(getRealm().isCurrent(),
74 "This operation must be run within the observable's realm"); //$NON-NLS-1$
75 }
76 }