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 {
|
85
|
32 public override Realm getRealm(){
|
|
33 return super.getRealm();
|
|
34 }
|
78
|
35
|
|
36 /**
|
|
37 * @param realm
|
|
38 */
|
|
39 public this(Realm realm) {
|
|
40 super(realm);
|
|
41 }
|
|
42
|
|
43 public synchronized void addChangeListener(IChangeListener listener) {
|
|
44 addListener(ChangeEvent.TYPE, listener);
|
|
45 }
|
|
46
|
|
47 public synchronized void removeChangeListener(IChangeListener listener) {
|
|
48 removeListener(ChangeEvent.TYPE, listener);
|
|
49 }
|
|
50
|
|
51 public synchronized void addStaleListener(IStaleListener listener) {
|
|
52 addListener(StaleEvent.TYPE, listener);
|
|
53 }
|
|
54
|
|
55 public synchronized void removeStaleListener(IStaleListener listener) {
|
|
56 removeListener(StaleEvent.TYPE, listener);
|
|
57 }
|
|
58
|
|
59 protected void fireChange() {
|
|
60 checkRealm();
|
|
61 fireEvent(new ChangeEvent(this));
|
|
62 }
|
|
63
|
|
64 protected void fireStale() {
|
|
65 checkRealm();
|
|
66 fireEvent(new StaleEvent(this));
|
|
67 }
|
|
68
|
|
69 /**
|
|
70 *
|
|
71 */
|
|
72 public synchronized void dispose() {
|
|
73 super.dispose();
|
|
74 }
|
|
75
|
|
76 /**
|
|
77 * Asserts that the realm is the current realm.
|
|
78 *
|
|
79 * @see Realm#isCurrent()
|
|
80 * @throws AssertionFailedException if the realm is not the current realm
|
|
81 */
|
|
82 protected void checkRealm() {
|
|
83 Assert.isTrue(getRealm().isCurrent(),
|
|
84 "This operation must be run within the observable's realm"); //$NON-NLS-1$
|
|
85 }
|
|
86 }
|