KickJava   Java API By Example, From Geeks To Geeks.

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


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.IPageListener;
17 import org.eclipse.ui.IWorkbenchPage;
18 import org.eclipse.ui.internal.misc.UIStats;
19
20 /**
21  * Part listener list.
22  */

23 public class PageListenerList extends EventManager {
24
25     /**
26      * PartNotifier constructor comment.
27      */

28     public PageListenerList() {
29         super();
30     }
31
32     /**
33      * Adds an IPartListener to the part service.
34      */

35     public void addPageListener(IPageListener l) {
36         addListenerObject(l);
37     }
38
39     /**
40      * Calls a page listener with associated performance event instrumentation
41      *
42      * @param runnable
43      * @param listener
44      * @param page
45      * @param description
46      */

47     private void fireEvent(SafeRunnable runnable, IPageListener listener, IWorkbenchPage page, String JavaDoc description) {
48         String JavaDoc label = null;//for debugging
49
if (UIStats.isDebugging(UIStats.NOTIFY_PAGE_LISTENERS)) {
50             label = description + page.getLabel();
51             UIStats.start(UIStats.NOTIFY_PAGE_LISTENERS, label);
52         }
53         Platform.run(runnable);
54         if (UIStats.isDebugging(UIStats.NOTIFY_PAGE_LISTENERS)) {
55             UIStats.end(UIStats.NOTIFY_PAGE_LISTENERS, listener, label);
56         }
57     }
58
59     /**
60      * Notifies the listener that a part has been activated.
61      */

62     public void firePageActivated(final IWorkbenchPage page) {
63         Object JavaDoc[] array = getListeners();
64         for (int i = 0; i < array.length; i++) {
65             final IPageListener l = (IPageListener) array[i];
66             fireEvent(new SafeRunnable() {
67                 public void run() {
68                     l.pageActivated(page);
69                 }
70             }, l, page, "activated::"); //$NON-NLS-1$
71
}
72     }
73
74     /**
75      * Notifies the listener that a part has been closed
76      */

77     public void firePageClosed(final IWorkbenchPage page) {
78         Object JavaDoc[] array = getListeners();
79         for (int i = 0; i < array.length; i++) {
80             final IPageListener l = (IPageListener) array[i];
81             fireEvent(new SafeRunnable() {
82                 public void run() {
83                     l.pageClosed(page);
84                 }
85             }, l, page, "closed::"); //$NON-NLS-1$
86
}
87     }
88
89     /**
90      * Notifies the listener that a part has been opened.
91      */

92     public void firePageOpened(final IWorkbenchPage page) {
93         Object JavaDoc[] listeners = getListeners();
94         for (int i = 0; i < listeners.length; i++) {
95             final IPageListener l = (IPageListener) listeners[i];
96             fireEvent(new SafeRunnable() {
97                 public void run() {
98                     l.pageOpened(page);
99                 }
100             }, l, page, "opened::"); //$NON-NLS-1$
101
}
102     }
103
104     /**
105      * Removes an IPartListener from the part service.
106      */

107     public void removePageListener(IPageListener l) {
108         removeListenerObject(l);
109     }
110 }
111
Popular Tags