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