1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.ui.IPageListener; 14 import org.eclipse.ui.IWorkbenchPage; 15 import org.eclipse.ui.IWorkbenchWindow; 16 import org.eclipse.ui.actions.ActionFactory; 17 import org.eclipse.ui.actions.PartEventAction; 18 import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction; 19 20 62 public abstract class PageEventAction extends PartEventAction implements 63 IPageListener, ActionFactory.IWorkbenchAction { 64 67 private IWorkbenchPage activePage; 68 69 72 private IWorkbenchWindow workbenchWindow; 73 74 84 protected PageEventAction(String text, IWorkbenchWindow window) { 85 super(text); 86 if (window == null) { 87 throw new IllegalArgumentException (); 88 } 89 this.workbenchWindow = window; 90 this.activePage = window.getActivePage(); 91 this.workbenchWindow.addPageListener(this); 92 this.workbenchWindow.getPartService().addPartListener(this); 93 } 94 95 101 public final IWorkbenchPage getActivePage() { 102 return activePage; 103 } 104 105 111 public final IWorkbenchWindow getWorkbenchWindow() { 112 return workbenchWindow; 113 } 114 115 121 public void pageActivated(IWorkbenchPage page) { 122 this.activePage = page; 123 } 124 125 131 public void pageClosed(IWorkbenchPage page) { 132 if (page == activePage) { 133 activePage = null; 134 } 135 } 136 137 142 public void pageOpened(IWorkbenchPage page) { 143 } 145 146 155 public void dispose() { 156 if (workbenchWindow == null) { 157 return; 159 } 160 workbenchWindow.removePageListener(this); 161 workbenchWindow.getPartService().removePartListener(this); 162 workbenchWindow = null; 163 } 164 } 165 | Popular Tags |