KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

35     public void addPartListener(IPartListener2 l) {
36         addListenerObject(l);
37     }
38
39     /**
40      * Calls a part listener with associated performance event instrumentation
41      *
42      * @param runnable
43      * @param listener
44      * @param ref
45      * @param string
46      */

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

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

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

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

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

122     public void firePartOpened(final IWorkbenchPartReference ref) {
123         Object JavaDoc[] array = getListeners();
124         for (int i = 0; i < array.length; i++) {
125             final IPartListener2 l = (IPartListener2) array[i];
126             fireEvent(new SafeRunnable() {
127                 public void run() {
128                     l.partOpened(ref);
129                 }
130             }, l, ref, "opened::"); //$NON-NLS-1$
131
}
132     }
133
134     /**
135      * Notifies the listener that a part has been opened.
136      */

137     public void firePartHidden(final IWorkbenchPartReference ref) {
138         Object JavaDoc[] array = getListeners();
139         for (int i = 0; i < array.length; i++) {
140             final IPartListener2 l;
141             if (array[i] instanceof IPartListener2) {
142                 l = (IPartListener2) array[i];
143             } else {
144                 continue;
145             }
146
147             fireEvent(new SafeRunnable() {
148                 public void run() {
149                     l.partHidden(ref);
150                 }
151             }, l, ref, "hidden::"); //$NON-NLS-1$
152
}
153     }
154
155     /**
156      * Notifies the listener that a part has been opened.
157      */

158     public void firePartVisible(final IWorkbenchPartReference ref) {
159         Object JavaDoc[] array = getListeners();
160         for (int i = 0; i < array.length; i++) {
161             final IPartListener2 l;
162             if (array[i] instanceof IPartListener2) {
163                 l = (IPartListener2) array[i];
164             } else {
165                 continue;
166             }
167
168             fireEvent(new SafeRunnable() {
169                 public void run() {
170                     l.partVisible(ref);
171                 }
172             }, l, ref, "visible::"); //$NON-NLS-1$
173
}
174     }
175
176     /**
177      * Notifies the listener that a part has been opened.
178      */

179     public void firePartInputChanged(final IWorkbenchPartReference ref) {
180         Object JavaDoc[] array = getListeners();
181         for (int i = 0; i < array.length; i++) {
182             final IPartListener2 l;
183             if (array[i] instanceof IPartListener2) {
184                 l = (IPartListener2) array[i];
185             } else {
186                 continue;
187             }
188
189             fireEvent(new SafeRunnable() {
190                 public void run() {
191                     l.partInputChanged(ref);
192                 }
193             }, l, ref, "inputChanged::"); //$NON-NLS-1$
194
}
195     }
196     
197     /**
198      * Removes an IPartListener from the part service.
199      */

200     public void removePartListener(IPartListener2 l) {
201         removeListenerObject(l);
202     }
203 }
204
Popular Tags