KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > PartListenerList


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 package org.eclipse.ui.internal;
12
13 import org.eclipse.core.commands.common.EventManager;
14 import org.eclipse.core.runtime.Platform;
15 import org.eclipse.jface.util.SafeRunnable;
16 import org.eclipse.ui.IPartListener;
17 import org.eclipse.ui.IWorkbenchPart;
18 import org.eclipse.ui.internal.misc.UIStats;
19
20 /**
21  * Part listener list.
22  */

23 /*
24  * This class should be deleted when IPartListener and IPartListener2
25  * renamed to IPartListener.
26  */

27 public class PartListenerList extends EventManager {
28
29     /**
30      * PartNotifier constructor comment.
31      */

32     public PartListenerList() {
33         super();
34     }
35
36     /**
37      * Adds an IPartListener to the part service.
38      */

39     public void addPartListener(IPartListener l) {
40         addListenerObject(l);
41     }
42
43     /**
44      * Calls a part listener with associated performance event instrumentation
45      *
46      * @param runnable
47      * @param listener
48      * @param part
49      * @param description
50      */

51     private void fireEvent(SafeRunnable runnable, IPartListener listener, IWorkbenchPart part, String JavaDoc description) {
52         String JavaDoc label = null;//for debugging
53
if (UIStats.isDebugging(UIStats.NOTIFY_PART_LISTENERS)) {
54             label = description + part.getTitle();
55             UIStats.start(UIStats.NOTIFY_PART_LISTENERS, label);
56         }
57         Platform.run(runnable);
58         if (UIStats.isDebugging(UIStats.NOTIFY_PART_LISTENERS)) {
59             UIStats.end(UIStats.NOTIFY_PART_LISTENERS, listener, label);
60         }
61     }
62
63     /**
64      * Notifies the listener that a part has been activated.
65      */

66     public void firePartActivated(final IWorkbenchPart part) {
67         Object JavaDoc[] array = getListeners();
68         for (int i = 0; i < array.length; i++) {
69             final IPartListener l = (IPartListener) array[i];
70             fireEvent(new SafeRunnable() {
71                 public void run() {
72                     l.partActivated(part);
73                 }
74             }, l, part, "activated::"); //$NON-NLS-1$
75
}
76     }
77
78     /**
79      * Notifies the listener that a part has been brought to top.
80      */

81     public void firePartBroughtToTop(final IWorkbenchPart part) {
82         Object JavaDoc[] array = getListeners();
83         for (int i = 0; i < array.length; i++) {
84             final IPartListener l = (IPartListener) array[i];
85             fireEvent(new SafeRunnable() {
86                 public void run() {
87                     l.partBroughtToTop(part);
88                 }
89             }, l, part, "broughtToTop::"); //$NON-NLS-1$
90
}
91     }
92
93     /**
94      * Notifies the listener that a part has been closed
95      */

96     public void firePartClosed(final IWorkbenchPart part) {
97         Object JavaDoc[] array = getListeners();
98         for (int i = 0; i < array.length; i++) {
99             final IPartListener l = (IPartListener) array[i];
100             fireEvent(new SafeRunnable() {
101                 public void run() {
102                     l.partClosed(part);
103                 }
104             }, l, part, "closed::"); //$NON-NLS-1$
105
}
106     }
107
108     /**
109      * Notifies the listener that a part has been deactivated.
110      */

111     public void firePartDeactivated(final IWorkbenchPart part) {
112         Object JavaDoc[] array = getListeners();
113         for (int i = 0; i < array.length; i++) {
114             final IPartListener l = (IPartListener) array[i];
115             fireEvent(new SafeRunnable() {
116                 public void run() {
117                     l.partDeactivated(part);
118                 }
119             }, l, part, "deactivated::"); //$NON-NLS-1$
120
}
121     }
122
123     /**
124      * Notifies the listener that a part has been opened.
125      */

126     public void firePartOpened(final IWorkbenchPart part) {
127         Object JavaDoc[] array = getListeners();
128         for (int i = 0; i < array.length; i++) {
129             final IPartListener l = (IPartListener) array[i];
130             fireEvent(new SafeRunnable() {
131                 public void run() {
132                     l.partOpened(part);
133                 }
134             }, l, part, "opened::"); //$NON-NLS-1$
135
}
136     }
137
138     /**
139      * Removes an IPartListener from the part service.
140      */

141     public void removePartListener(IPartListener l) {
142         removeListenerObject(l);
143     }
144 }
145
Popular Tags