001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal;
011:
012: import org.eclipse.ui.IPartListener;
013: import org.eclipse.ui.IPartListener2;
014: import org.eclipse.ui.IPartService;
015: import org.eclipse.ui.IWorkbenchPart;
016: import org.eclipse.ui.IWorkbenchPartReference;
017: import org.eclipse.ui.internal.misc.UIListenerLogging;
018:
019: public class PartService implements IPartService {
020: private PartListenerList listeners = new PartListenerList();
021:
022: private PartListenerList2 listeners2 = new PartListenerList2();
023: private IWorkbenchPartReference activePart = null;
024:
025: private String debugListenersKey;
026: private String debugListeners2Key;
027:
028: public PartService(String debugListenersKey,
029: String debugListeners2Key) {
030: this .debugListeners2Key = debugListeners2Key;
031: this .debugListenersKey = debugListenersKey;
032: }
033:
034: /*
035: * (non-Javadoc)
036: * Method declared on IPartService
037: */
038: public void addPartListener(IPartListener l) {
039: listeners.addPartListener(l);
040: }
041:
042: /*
043: * (non-Javadoc)
044: * Method declared on IPartService
045: */
046: public void addPartListener(IPartListener2 l) {
047: listeners2.addPartListener(l);
048: }
049:
050: /*
051: * (non-Javadoc)
052: * Method declared on IPartService
053: */
054: public void removePartListener(IPartListener l) {
055: listeners.removePartListener(l);
056: }
057:
058: /*
059: * (non-Javadoc)
060: * Method declared on IPartService
061: */
062: public void removePartListener(IPartListener2 l) {
063: listeners2.removePartListener(l);
064: }
065:
066: /**
067: * @param ref
068: */
069: private void firePartActivated(IWorkbenchPartReference ref) {
070: IWorkbenchPart part = ref.getPart(false);
071: if (part != null) {
072: UIListenerLogging.logPartListenerEvent(debugListenersKey,
073: this , part, UIListenerLogging.PE_ACTIVATED);
074: listeners.firePartActivated(part);
075: }
076:
077: UIListenerLogging.logPartListener2Event(debugListeners2Key,
078: this , ref, UIListenerLogging.PE2_ACTIVATED);
079: listeners2.firePartActivated(ref);
080: }
081:
082: /**
083: * @param ref
084: */
085: public void firePartBroughtToTop(IWorkbenchPartReference ref) {
086: IWorkbenchPart part = ref.getPart(false);
087: if (part != null) {
088: UIListenerLogging.logPartListenerEvent(debugListenersKey,
089: this , part,
090: UIListenerLogging.PE_PART_BROUGHT_TO_TOP);
091: listeners.firePartBroughtToTop(part);
092: }
093: UIListenerLogging.logPartListener2Event(debugListeners2Key,
094: this , ref, UIListenerLogging.PE2_PART_BROUGHT_TO_TOP);
095: listeners2.firePartBroughtToTop(ref);
096: }
097:
098: /**
099: * @param ref
100: */
101: public void firePartClosed(IWorkbenchPartReference ref) {
102: IWorkbenchPart part = ref.getPart(false);
103: if (part != null) {
104: UIListenerLogging.logPartListenerEvent(debugListenersKey,
105: this , part, UIListenerLogging.PE_PART_CLOSED);
106: listeners.firePartClosed(part);
107: }
108: UIListenerLogging.logPartListener2Event(debugListeners2Key,
109: this , ref, UIListenerLogging.PE2_PART_CLOSED);
110: listeners2.firePartClosed(ref);
111: }
112:
113: /**
114: * @param ref
115: */
116: private void firePartDeactivated(IWorkbenchPartReference ref) {
117: IWorkbenchPart part = ref.getPart(false);
118: if (part != null) {
119: UIListenerLogging.logPartListenerEvent(debugListenersKey,
120: this , part, UIListenerLogging.PE_PART_DEACTIVATED);
121: listeners.firePartDeactivated(part);
122: }
123: UIListenerLogging.logPartListener2Event(debugListeners2Key,
124: this , ref, UIListenerLogging.PE2_PART_DEACTIVATED);
125: listeners2.firePartDeactivated(ref);
126: }
127:
128: public void firePartVisible(IWorkbenchPartReference ref) {
129: UIListenerLogging.logPartListener2Event(debugListeners2Key,
130: this , ref, UIListenerLogging.PE2_PART_VISIBLE);
131: listeners2.firePartVisible(ref);
132: }
133:
134: public void firePartHidden(IWorkbenchPartReference ref) {
135: UIListenerLogging.logPartListener2Event(debugListeners2Key,
136: this , ref, UIListenerLogging.PE2_PART_HIDDEN);
137: listeners2.firePartHidden(ref);
138: }
139:
140: public void firePartInputChanged(IWorkbenchPartReference ref) {
141: UIListenerLogging.logPartListener2Event(debugListeners2Key,
142: this , ref, UIListenerLogging.PE2_PART_INPUT_CHANGED);
143: listeners2.firePartInputChanged(ref);
144: }
145:
146: /**
147: * @param ref
148: */
149: public void firePartOpened(IWorkbenchPartReference ref) {
150: IWorkbenchPart part = ref.getPart(false);
151: if (part != null) {
152: UIListenerLogging.logPartListenerEvent(debugListenersKey,
153: this , part, UIListenerLogging.PE_PART_OPENED);
154: listeners.firePartOpened(part);
155: }
156: UIListenerLogging.logPartListener2Event(debugListeners2Key,
157: this , ref, UIListenerLogging.PE2_PART_OPENED);
158: listeners2.firePartOpened(ref);
159: }
160:
161: public IWorkbenchPart getActivePart() {
162: return activePart == null ? null : activePart.getPart(false);
163: }
164:
165: public IWorkbenchPartReference getActivePartReference() {
166: return activePart;
167: }
168:
169: public void setActivePart(IWorkbenchPartReference ref) {
170: IWorkbenchPartReference oldRef = activePart;
171:
172: // Filter out redundant activation events
173: if (oldRef == ref) {
174: return;
175: }
176:
177: if (oldRef != null) {
178: firePartDeactivated(oldRef);
179: }
180:
181: activePart = ref;
182:
183: if (ref != null) {
184: firePartActivated(ref);
185: }
186: }
187:
188: }
|