1 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 23 public class PartListenerList2 extends EventManager { 24 25 28 public PartListenerList2() { 29 super(); 30 } 31 32 35 public void addPartListener(IPartListener2 l) { 36 addListenerObject(l); 37 } 38 39 47 private void fireEvent(SafeRunnable runnable, IPartListener2 listener, IWorkbenchPartReference ref, String string) { 48 String label = null; 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 62 public void firePartActivated(final IWorkbenchPartReference ref) { 63 Object [] 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::"); } 72 } 73 74 77 public void firePartBroughtToTop(final IWorkbenchPartReference ref) { 78 Object [] 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::"); } 87 } 88 89 92 public void firePartClosed(final IWorkbenchPartReference ref) { 93 Object [] 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::"); } 102 } 103 104 107 public void firePartDeactivated(final IWorkbenchPartReference ref) { 108 Object [] 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::"); } 117 } 118 119 122 public void firePartOpened(final IWorkbenchPartReference ref) { 123 Object [] 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::"); } 132 } 133 134 137 public void firePartHidden(final IWorkbenchPartReference ref) { 138 Object [] 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::"); } 153 } 154 155 158 public void firePartVisible(final IWorkbenchPartReference ref) { 159 Object [] 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::"); } 174 } 175 176 179 public void firePartInputChanged(final IWorkbenchPartReference ref) { 180 Object [] 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::"); } 195 } 196 197 200 public void removePartListener(IPartListener2 l) { 201 removeListenerObject(l); 202 } 203 } 204 | Popular Tags |