KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.ui.IPartListener;
14 import org.eclipse.ui.IPartListener2;
15 import org.eclipse.ui.IPartService;
16 import org.eclipse.ui.IWorkbenchPart;
17 import org.eclipse.ui.IWorkbenchPartReference;
18 import org.eclipse.ui.internal.misc.UIListenerLogging;
19
20 public class PartService implements IPartService {
21     private PartListenerList listeners = new PartListenerList();
22
23     private PartListenerList2 listeners2 = new PartListenerList2();
24     private IWorkbenchPartReference activePart = null;
25     
26     private String JavaDoc debugListenersKey;
27     private String JavaDoc debugListeners2Key;
28     
29     public PartService(String JavaDoc debugListenersKey, String JavaDoc debugListeners2Key) {
30         this.debugListeners2Key = debugListeners2Key;
31         this.debugListenersKey = debugListenersKey;
32     }
33     
34     /*
35      * (non-Javadoc)
36      * Method declared on IPartService
37      */

38     public void addPartListener(IPartListener l) {
39         listeners.addPartListener(l);
40     }
41
42     /*
43      * (non-Javadoc)
44      * Method declared on IPartService
45      */

46     public void addPartListener(IPartListener2 l) {
47         listeners2.addPartListener(l);
48     }
49
50     /*
51      * (non-Javadoc)
52      * Method declared on IPartService
53      */

54     public void removePartListener(IPartListener l) {
55         listeners.removePartListener(l);
56     }
57
58     /*
59      * (non-Javadoc)
60      * Method declared on IPartService
61      */

62     public void removePartListener(IPartListener2 l) {
63         listeners2.removePartListener(l);
64     }
65
66     /**
67      * @param ref
68      */

69     private void firePartActivated(IWorkbenchPartReference ref) {
70         IWorkbenchPart part = ref.getPart(false);
71         if(part != null) {
72             UIListenerLogging.logPartListenerEvent(debugListenersKey, this, part, UIListenerLogging.PE_ACTIVATED);
73             listeners.firePartActivated(part);
74         }
75         
76         UIListenerLogging.logPartListener2Event(debugListeners2Key, this, ref, UIListenerLogging.PE2_ACTIVATED);
77         listeners2.firePartActivated(ref);
78     }
79     
80     /**
81      * @param ref
82      */

83     public void firePartBroughtToTop(IWorkbenchPartReference ref) {
84         IWorkbenchPart part = ref.getPart(false);
85         if(part != null) {
86             UIListenerLogging.logPartListenerEvent(debugListenersKey, this, part, UIListenerLogging.PE_PART_BROUGHT_TO_TOP);
87             listeners.firePartBroughtToTop(part);
88         }
89         UIListenerLogging.logPartListener2Event(debugListeners2Key, this, ref, UIListenerLogging.PE2_PART_BROUGHT_TO_TOP);
90         listeners2.firePartBroughtToTop(ref);
91     }
92     
93     /**
94      * @param ref
95      */

96     public void firePartClosed(IWorkbenchPartReference ref) {
97         IWorkbenchPart part = ref.getPart(false);
98         if(part != null) {
99             UIListenerLogging.logPartListenerEvent(debugListenersKey, this, part, UIListenerLogging.PE_PART_CLOSED);
100             listeners.firePartClosed(part);
101         }
102         UIListenerLogging.logPartListener2Event(debugListeners2Key, this, ref, UIListenerLogging.PE2_PART_CLOSED);
103         listeners2.firePartClosed(ref);
104     }
105     
106     /**
107      * @param ref
108      */

109     private void firePartDeactivated(IWorkbenchPartReference ref) {
110         IWorkbenchPart part = ref.getPart(false);
111         if(part != null) {
112             UIListenerLogging.logPartListenerEvent(debugListenersKey, this, part, UIListenerLogging.PE_PART_DEACTIVATED);
113             listeners.firePartDeactivated(part);
114         }
115         UIListenerLogging.logPartListener2Event(debugListeners2Key, this, ref, UIListenerLogging.PE2_PART_DEACTIVATED);
116         listeners2.firePartDeactivated(ref);
117     }
118     
119     public void firePartVisible(IWorkbenchPartReference ref) {
120         UIListenerLogging.logPartListener2Event(debugListeners2Key, this, ref, UIListenerLogging.PE2_PART_VISIBLE);
121         listeners2.firePartVisible(ref);
122     }
123
124     public void firePartHidden(IWorkbenchPartReference ref) {
125         UIListenerLogging.logPartListener2Event(debugListeners2Key, this, ref, UIListenerLogging.PE2_PART_HIDDEN);
126         listeners2.firePartHidden(ref);
127     }
128     
129     public void firePartInputChanged(IWorkbenchPartReference ref) {
130         UIListenerLogging.logPartListener2Event(debugListeners2Key, this, ref, UIListenerLogging.PE2_PART_INPUT_CHANGED);
131         listeners2.firePartInputChanged(ref);
132     }
133     
134     /**
135      * @param ref
136      */

137     public void firePartOpened(IWorkbenchPartReference ref) {
138         IWorkbenchPart part = ref.getPart(false);
139         if(part != null) {
140             UIListenerLogging.logPartListenerEvent(debugListenersKey, this, part, UIListenerLogging.PE_PART_OPENED);
141             listeners.firePartOpened(part);
142         }
143         UIListenerLogging.logPartListener2Event(debugListeners2Key, this, ref, UIListenerLogging.PE2_PART_OPENED);
144         listeners2.firePartOpened(ref);
145      }
146     
147     
148     public IWorkbenchPart getActivePart() {
149         return activePart == null ? null : activePart.getPart(false);
150     }
151
152     public IWorkbenchPartReference getActivePartReference() {
153         return activePart;
154     }
155
156     public void setActivePart(IWorkbenchPartReference ref) {
157         IWorkbenchPartReference oldRef = activePart;
158         
159         // Filter out redundant activation events
160
if (oldRef == ref) {
161             return;
162         }
163         
164         if (oldRef != null) {
165             firePartDeactivated(oldRef);
166         }
167         
168         activePart = ref;
169         
170         if (ref != null) {
171             firePartActivated(ref);
172         }
173     }
174
175 }
176
Popular Tags