KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > databinding > observable > AbstractObservable


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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  *******************************************************************************/

12
13 package org.eclipse.core.databinding.observable;
14
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.core.runtime.AssertionFailedException;
17
18 /**
19  * @since 1.0
20  */

21 public abstract class AbstractObservable extends ChangeManager implements IObservable {
22     
23     /**
24      * @param realm
25      */

26     public AbstractObservable(Realm realm) {
27         super(realm);
28     }
29
30     public synchronized void addChangeListener(IChangeListener listener) {
31         addListener(ChangeEvent.TYPE, listener);
32     }
33
34     public synchronized void removeChangeListener(IChangeListener listener) {
35         removeListener(ChangeEvent.TYPE, listener);
36     }
37
38     public synchronized void addStaleListener(IStaleListener listener) {
39         addListener(StaleEvent.TYPE, listener);
40     }
41
42     public synchronized void removeStaleListener(IStaleListener listener) {
43         removeListener(StaleEvent.TYPE, listener);
44     }
45
46     protected void fireChange() {
47         checkRealm();
48         fireEvent(new ChangeEvent(this));
49     }
50
51     protected void fireStale() {
52         checkRealm();
53         fireEvent(new StaleEvent(this));
54     }
55
56     /**
57      *
58      */

59     public synchronized void dispose() {
60         super.dispose();
61     }
62
63     /**
64      * Asserts that the realm is the current realm.
65      *
66      * @see Realm#isCurrent()
67      * @throws AssertionFailedException if the realm is not the current realm
68      */

69     protected void checkRealm() {
70         Assert.isTrue(getRealm().isCurrent());
71     }
72 }
73
Popular Tags