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.IPerspectiveDescriptor; 17 import org.eclipse.ui.IPerspectiveListener; 18 import org.eclipse.ui.IPerspectiveListener2; 19 import org.eclipse.ui.IPerspectiveListener3; 20 import org.eclipse.ui.IPerspectiveListener4; 21 import org.eclipse.ui.IWorkbenchPage; 22 import org.eclipse.ui.IWorkbenchPartReference; 23 import org.eclipse.ui.internal.misc.UIStats; 24 25 28 public class PerspectiveListenerList extends EventManager { 29 30 33 public PerspectiveListenerList() { 34 super(); 35 } 36 37 40 public void addPerspectiveListener(IPerspectiveListener l) { 41 addListenerObject(l); 42 } 43 44 52 private void fireEvent(SafeRunnable runnable, IPerspectiveListener listener, IPerspectiveDescriptor perspective, String description) { 53 String label = null; if (UIStats.isDebugging(UIStats.NOTIFY_PERSPECTIVE_LISTENERS)) { 55 label = description + perspective.getId(); 56 UIStats.start(UIStats.NOTIFY_PERSPECTIVE_LISTENERS, label); 57 } 58 Platform.run(runnable); 59 if (UIStats.isDebugging(UIStats.NOTIFY_PERSPECTIVE_LISTENERS)) { 60 UIStats.end(UIStats.NOTIFY_PERSPECTIVE_LISTENERS, listener, label); 61 } 62 } 63 64 67 public void firePerspectiveActivated(final IWorkbenchPage page, 68 final IPerspectiveDescriptor perspective) { 69 Object [] array = getListeners(); 70 for (int nX = 0; nX < array.length; nX++) { 71 final IPerspectiveListener l = (IPerspectiveListener) array[nX]; 72 fireEvent(new SafeRunnable() { 73 public void run() { 74 l.perspectiveActivated(page, perspective); 75 } 76 }, l, perspective, "activated::"); } 78 } 79 80 85 public void firePerspectivePreDeactivate(final IWorkbenchPage page, 86 final IPerspectiveDescriptor perspective) { 87 Object [] array = getListeners(); 88 for (int nX = 0; nX < array.length; nX++) { 89 if (array[nX] instanceof IPerspectiveListener4) { 90 final IPerspectiveListener4 l4 = (IPerspectiveListener4) array[nX]; 91 fireEvent(new SafeRunnable() { 92 public void run() { 93 l4.perspectivePreDeactivate(page, perspective); 94 } 95 }, l4, perspective, "pre-deactivate::"); } 97 } 98 } 99 100 105 public void firePerspectiveDeactivated(final IWorkbenchPage page, 106 final IPerspectiveDescriptor perspective) { 107 Object [] array = getListeners(); 108 for (int nX = 0; nX < array.length; nX++) { 109 if (array[nX] instanceof IPerspectiveListener3) { 110 final IPerspectiveListener3 l3 = (IPerspectiveListener3) array[nX]; 111 fireEvent(new SafeRunnable() { 112 public void run() { 113 l3.perspectiveDeactivated(page, perspective); 114 } 115 }, l3, perspective, "deactivated::"); } 117 } 118 } 119 120 123 public void firePerspectiveChanged(final IWorkbenchPage page, 124 final IPerspectiveDescriptor perspective, final String changeId) { 125 Object [] array = getListeners(); 126 for (int nX = 0; nX < array.length; nX++) { 127 final IPerspectiveListener l = (IPerspectiveListener) array[nX]; 128 fireEvent(new SafeRunnable() { 129 public void run() { 130 l.perspectiveChanged(page, perspective, changeId); 131 } 132 }, l, perspective, "changed::"); } 134 } 135 136 142 public void firePerspectiveChanged(final IWorkbenchPage page, 143 final IPerspectiveDescriptor perspective, 144 final IWorkbenchPartReference partRef, final String changeId) { 145 Object [] array = getListeners(); 146 for (int nX = 0; nX < array.length; nX++) { 147 if (array[nX] instanceof IPerspectiveListener2) { 148 final IPerspectiveListener2 l2 = (IPerspectiveListener2) array[nX]; 149 fireEvent(new SafeRunnable() { 150 public void run() { 151 l2.perspectiveChanged(page, perspective, partRef, 152 changeId); 153 } 154 }, l2, perspective, "changed::"); } 156 } 157 } 158 159 164 public void firePerspectiveClosed(final IWorkbenchPage page, 165 final IPerspectiveDescriptor perspective) { 166 Object [] array = getListeners(); 167 for (int nX = 0; nX < array.length; nX++) { 168 if (array[nX] instanceof IPerspectiveListener3) { 169 final IPerspectiveListener3 l3 = (IPerspectiveListener3) array[nX]; 170 fireEvent(new SafeRunnable() { 171 public void run() { 172 l3.perspectiveClosed(page, perspective); 173 } 174 }, l3, perspective, "closed::"); } 176 } 177 } 178 179 184 public void firePerspectiveOpened(final IWorkbenchPage page, 185 final IPerspectiveDescriptor perspective) { 186 Object [] array = getListeners(); 187 for (int nX = 0; nX < array.length; nX++) { 188 if (array[nX] instanceof IPerspectiveListener3) { 189 final IPerspectiveListener3 l3 = (IPerspectiveListener3) array[nX]; 190 fireEvent(new SafeRunnable() { 191 public void run() { 192 l3.perspectiveOpened(page, perspective); 193 } 194 }, l3, perspective, "opened::"); } 196 } 197 } 198 199 204 public void firePerspectiveSavedAs(final IWorkbenchPage page, 205 final IPerspectiveDescriptor oldPerspective, 206 final IPerspectiveDescriptor newPerspective) { 207 Object [] array = getListeners(); 208 for (int nX = 0; nX < array.length; nX++) { 209 if (array[nX] instanceof IPerspectiveListener3) { 210 final IPerspectiveListener3 l3 = (IPerspectiveListener3) array[nX]; 211 fireEvent(new SafeRunnable() { 212 public void run() { 213 l3.perspectiveSavedAs(page, oldPerspective, newPerspective); 214 } 215 }, l3, newPerspective, "saveAs::"); } 217 } 218 } 219 220 223 public void removePerspectiveListener(IPerspectiveListener l) { 224 removeListenerObject(l); 225 } 226 } 227 | Popular Tags |