1 11 12 package org.eclipse.ui.internal; 13 14 import org.eclipse.core.runtime.Assert; 15 import org.eclipse.jface.action.Action; 16 import org.eclipse.ui.IPerspectiveDescriptor; 17 import org.eclipse.ui.IWorkbenchPage; 18 import org.eclipse.ui.IWorkbenchWindow; 19 import org.eclipse.ui.actions.ActionFactory; 20 21 27 public abstract class PerspectiveAction extends Action implements ActionFactory.IWorkbenchAction { 28 29 32 private IWorkbenchWindow workbenchWindow; 33 34 38 private PerspectiveTracker tracker; 39 40 45 protected PerspectiveAction(IWorkbenchWindow window) { 46 Assert.isNotNull(window); 47 this.workbenchWindow = window; 48 tracker = new PerspectiveTracker(window, this); 49 } 50 51 56 protected IWorkbenchWindow getWindow() { 57 return workbenchWindow; 58 } 59 60 63 public void run() { 64 if (workbenchWindow == null) { 65 return; 67 } 68 IWorkbenchPage page = workbenchWindow.getActivePage(); 69 if (page != null && page.getPerspective() != null) { 70 run(page, page.getPerspective()); 71 } 72 } 73 74 80 protected abstract void run(IWorkbenchPage page, IPerspectiveDescriptor persp); 81 82 85 public void dispose() { 86 if (workbenchWindow == null) { 87 return; 89 } 90 tracker.dispose(); 91 workbenchWindow = null; 92 } 93 94 } 95 96 | Popular Tags |