KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > action > AbstractAction


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

11
12 package org.eclipse.jface.action;
13
14 import org.eclipse.core.commands.common.EventManager;
15 import org.eclipse.jface.util.IPropertyChangeListener;
16 import org.eclipse.jface.util.PropertyChangeEvent;
17
18 /**
19  * <p>
20  * Some common functionality to share between implementations of
21  * <code>IAction</code>. This functionality deals with the property change
22  * event mechanism.
23  * </p>
24  * <p>
25  * Clients may neither instantiate nor extend this class.
26  * </p>
27  *
28  * @since 3.2
29  */

30 public abstract class AbstractAction extends EventManager implements IAction {
31
32     public void addPropertyChangeListener(final IPropertyChangeListener listener) {
33         addListenerObject(listener);
34     }
35
36     /**
37      * Notifies any property change listeners that a property has changed. Only
38      * listeners registered at the time this method is called are notified.
39      *
40      * @param event
41      * the property change event
42      *
43      * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(PropertyChangeEvent)
44      */

45     protected final void firePropertyChange(final PropertyChangeEvent event) {
46         final Object JavaDoc[] list = getListeners();
47         for (int i = 0; i < list.length; ++i) {
48             ((IPropertyChangeListener) list[i]).propertyChange(event);
49         }
50     }
51
52     /**
53      * Notifies any property change listeners that a property has changed. Only
54      * listeners registered at the time this method is called are notified. This
55      * method avoids creating an event object if there are no listeners
56      * registered, but calls
57      * <code>firePropertyChange(PropertyChangeEvent)</code> if there are.
58      *
59      * @param propertyName
60      * the name of the property that has changed
61      * @param oldValue
62      * the old value of the property, or <code>null</code> if none
63      * @param newValue
64      * the new value of the property, or <code>null</code> if none
65      *
66      * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(PropertyChangeEvent)
67      */

68     protected final void firePropertyChange(final String JavaDoc propertyName,
69             final Object JavaDoc oldValue, final Object JavaDoc newValue) {
70         if (isListenerAttached()) {
71             firePropertyChange(new PropertyChangeEvent(this, propertyName,
72                     oldValue, newValue));
73         }
74     }
75
76     public void removePropertyChangeListener(
77             final IPropertyChangeListener listener) {
78         removeListenerObject(listener);
79     }
80
81 }
82
Popular Tags