KickJava   Java API By Example, From Geeks To Geeks.

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


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.IPerspectiveDescriptor;
17 import org.eclipse.ui.IPerspectiveListener;
18 import org.eclipse.ui.IPerspectiveListener2;
19 import org.eclipse.ui.IPerspectiveListener3;
20 import org.eclipse.ui.IPerspectiveListener4;
21 import org.eclipse.ui.IWorkbenchPage;
22 import org.eclipse.ui.IWorkbenchPartReference;
23 import org.eclipse.ui.internal.misc.UIStats;
24
25 /**
26  * Perspective listener list.
27  */

28 public class PerspectiveListenerList extends EventManager {
29
30     /**
31      * PerspectiveListenerList constructor comment.
32      */

33     public PerspectiveListenerList() {
34         super();
35     }
36
37     /**
38      * Adds an IPerspectiveListener to the perspective service.
39      */

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

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

67     public void firePerspectiveActivated(final IWorkbenchPage page,
68             final IPerspectiveDescriptor perspective) {
69         Object JavaDoc[] array = getListeners();
70         for (int nX = 0; nX < array.length; nX++) {
71             final IPerspectiveListener l = (IPerspectiveListener) array[nX];
72             fireEvent(new SafeRunnable() {
73                 public void run() {
74                     l.perspectiveActivated(page, perspective);
75                 }
76             }, l, perspective, "activated::"); //$NON-NLS-1$
77
}
78     }
79
80     /**
81      * Notifies the listener that a perspective has been deactivated.
82      *
83      * @since 3.2
84      */

85     public void firePerspectivePreDeactivate(final IWorkbenchPage page,
86             final IPerspectiveDescriptor perspective) {
87         Object JavaDoc[] array = getListeners();
88         for (int nX = 0; nX < array.length; nX++) {
89             if (array[nX] instanceof IPerspectiveListener4) {
90                 final IPerspectiveListener4 l4 = (IPerspectiveListener4) array[nX];
91                 fireEvent(new SafeRunnable() {
92                     public void run() {
93                         l4.perspectivePreDeactivate(page, perspective);
94                     }
95                 }, l4, perspective, "pre-deactivate::"); //$NON-NLS-1$
96
}
97         }
98     }
99
100     /**
101      * Notifies the listener that a perspective has been deactivated.
102      *
103      * @since 3.1
104      */

105     public void firePerspectiveDeactivated(final IWorkbenchPage page,
106             final IPerspectiveDescriptor perspective) {
107         Object JavaDoc[] array = getListeners();
108         for (int nX = 0; nX < array.length; nX++) {
109             if (array[nX] instanceof IPerspectiveListener3) {
110                 final IPerspectiveListener3 l3 = (IPerspectiveListener3) array[nX];
111                 fireEvent(new SafeRunnable() {
112                     public void run() {
113                         l3.perspectiveDeactivated(page, perspective);
114                     }
115                 }, l3, perspective, "deactivated::"); //$NON-NLS-1$
116
}
117         }
118     }
119
120     /**
121      * Notifies the listener that a perspective has been changed.
122      */

123     public void firePerspectiveChanged(final IWorkbenchPage page,
124             final IPerspectiveDescriptor perspective, final String JavaDoc changeId) {
125         Object JavaDoc[] array = getListeners();
126         for (int nX = 0; nX < array.length; nX++) {
127             final IPerspectiveListener l = (IPerspectiveListener) array[nX];
128             fireEvent(new SafeRunnable() {
129                 public void run() {
130                     l.perspectiveChanged(page, perspective, changeId);
131                 }
132             }, l, perspective, "changed::"); //$NON-NLS-1$
133
}
134     }
135
136     /**
137      * Notifies the listener that a part has been affected
138      * in the given perspective.
139      *
140      * @since 3.0
141      */

142     public void firePerspectiveChanged(final IWorkbenchPage page,
143             final IPerspectiveDescriptor perspective,
144             final IWorkbenchPartReference partRef, final String JavaDoc changeId) {
145         Object JavaDoc[] array = getListeners();
146         for (int nX = 0; nX < array.length; nX++) {
147             if (array[nX] instanceof IPerspectiveListener2) {
148                 final IPerspectiveListener2 l2 = (IPerspectiveListener2) array[nX];
149                 fireEvent(new SafeRunnable() {
150                     public void run() {
151                         l2.perspectiveChanged(page, perspective, partRef,
152                                 changeId);
153                     }
154                 }, l2, perspective, "changed::"); //$NON-NLS-1$
155
}
156         }
157     }
158
159     /**
160      * Notifies the listener that a perspective has been closed.
161      *
162      * @since 3.1
163      */

164     public void firePerspectiveClosed(final IWorkbenchPage page,
165             final IPerspectiveDescriptor perspective) {
166         Object JavaDoc[] array = getListeners();
167         for (int nX = 0; nX < array.length; nX++) {
168             if (array[nX] instanceof IPerspectiveListener3) {
169                 final IPerspectiveListener3 l3 = (IPerspectiveListener3) array[nX];
170                 fireEvent(new SafeRunnable() {
171                     public void run() {
172                         l3.perspectiveClosed(page, perspective);
173                     }
174                 }, l3, perspective, "closed::"); //$NON-NLS-1$
175
}
176         }
177     }
178
179     /**
180      * Notifies the listener that a perspective has been opened.
181      *
182      * @since 3.1
183      */

184     public void firePerspectiveOpened(final IWorkbenchPage page,
185             final IPerspectiveDescriptor perspective) {
186         Object JavaDoc[] array = getListeners();
187         for (int nX = 0; nX < array.length; nX++) {
188             if (array[nX] instanceof IPerspectiveListener3) {
189                 final IPerspectiveListener3 l3 = (IPerspectiveListener3) array[nX];
190                 fireEvent(new SafeRunnable() {
191                     public void run() {
192                         l3.perspectiveOpened(page, perspective);
193                     }
194                 }, l3, perspective, "opened::"); //$NON-NLS-1$
195
}
196         }
197     }
198     
199     /**
200      * Notifies the listener that a perspective has been deactivated.
201      *
202      * @since 3.1
203      */

204     public void firePerspectiveSavedAs(final IWorkbenchPage page,
205             final IPerspectiveDescriptor oldPerspective,
206             final IPerspectiveDescriptor newPerspective) {
207         Object JavaDoc[] array = getListeners();
208         for (int nX = 0; nX < array.length; nX++) {
209             if (array[nX] instanceof IPerspectiveListener3) {
210                 final IPerspectiveListener3 l3 = (IPerspectiveListener3) array[nX];
211                 fireEvent(new SafeRunnable() {
212                     public void run() {
213                         l3.perspectiveSavedAs(page, oldPerspective, newPerspective);
214                     }
215                 }, l3, newPerspective, "saveAs::"); //$NON-NLS-1$
216
}
217         }
218     }
219
220     /**
221      * Removes an IPerspectiveListener from the perspective service.
222      */

223     public void removePerspectiveListener(IPerspectiveListener l) {
224         removeListenerObject(l);
225     }
226 }
227
Popular Tags