1 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 debugListenersKey; 27 private String debugListeners2Key; 28 29 public PartService(String debugListenersKey, String debugListeners2Key) { 30 this.debugListeners2Key = debugListeners2Key; 31 this.debugListenersKey = debugListenersKey; 32 } 33 34 38 public void addPartListener(IPartListener l) { 39 listeners.addPartListener(l); 40 } 41 42 46 public void addPartListener(IPartListener2 l) { 47 listeners2.addPartListener(l); 48 } 49 50 54 public void removePartListener(IPartListener l) { 55 listeners.removePartListener(l); 56 } 57 58 62 public void removePartListener(IPartListener2 l) { 63 listeners2.removePartListener(l); 64 } 65 66 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 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 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 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 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 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 |