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.IPartListener; 17 import org.eclipse.ui.IWorkbenchPart; 18 import org.eclipse.ui.internal.misc.UIStats; 19 20 23 27 public class PartListenerList extends EventManager { 28 29 32 public PartListenerList() { 33 super(); 34 } 35 36 39 public void addPartListener(IPartListener l) { 40 addListenerObject(l); 41 } 42 43 51 private void fireEvent(SafeRunnable runnable, IPartListener listener, IWorkbenchPart part, String description) { 52 String label = null; if (UIStats.isDebugging(UIStats.NOTIFY_PART_LISTENERS)) { 54 label = description + part.getTitle(); 55 UIStats.start(UIStats.NOTIFY_PART_LISTENERS, label); 56 } 57 Platform.run(runnable); 58 if (UIStats.isDebugging(UIStats.NOTIFY_PART_LISTENERS)) { 59 UIStats.end(UIStats.NOTIFY_PART_LISTENERS, listener, label); 60 } 61 } 62 63 66 public void firePartActivated(final IWorkbenchPart part) { 67 Object [] array = getListeners(); 68 for (int i = 0; i < array.length; i++) { 69 final IPartListener l = (IPartListener) array[i]; 70 fireEvent(new SafeRunnable() { 71 public void run() { 72 l.partActivated(part); 73 } 74 }, l, part, "activated::"); } 76 } 77 78 81 public void firePartBroughtToTop(final IWorkbenchPart part) { 82 Object [] array = getListeners(); 83 for (int i = 0; i < array.length; i++) { 84 final IPartListener l = (IPartListener) array[i]; 85 fireEvent(new SafeRunnable() { 86 public void run() { 87 l.partBroughtToTop(part); 88 } 89 }, l, part, "broughtToTop::"); } 91 } 92 93 96 public void firePartClosed(final IWorkbenchPart part) { 97 Object [] array = getListeners(); 98 for (int i = 0; i < array.length; i++) { 99 final IPartListener l = (IPartListener) array[i]; 100 fireEvent(new SafeRunnable() { 101 public void run() { 102 l.partClosed(part); 103 } 104 }, l, part, "closed::"); } 106 } 107 108 111 public void firePartDeactivated(final IWorkbenchPart part) { 112 Object [] array = getListeners(); 113 for (int i = 0; i < array.length; i++) { 114 final IPartListener l = (IPartListener) array[i]; 115 fireEvent(new SafeRunnable() { 116 public void run() { 117 l.partDeactivated(part); 118 } 119 }, l, part, "deactivated::"); } 121 } 122 123 126 public void firePartOpened(final IWorkbenchPart part) { 127 Object [] array = getListeners(); 128 for (int i = 0; i < array.length; i++) { 129 final IPartListener l = (IPartListener) array[i]; 130 fireEvent(new SafeRunnable() { 131 public void run() { 132 l.partOpened(part); 133 } 134 }, l, part, "opened::"); } 136 } 137 138 141 public void removePartListener(IPartListener l) { 142 removeListenerObject(l); 143 } 144 } 145 | Popular Tags |