1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.jface.action.Action; 14 import org.eclipse.ui.IPageListener; 15 import org.eclipse.ui.IPartListener; 16 import org.eclipse.ui.IWorkbenchPage; 17 import org.eclipse.ui.IWorkbenchPart; 18 import org.eclipse.ui.IWorkbenchWindow; 19 import org.eclipse.ui.actions.ActionFactory; 20 21 27 public class WorkbookEditorsAction extends Action implements 28 ActionFactory.IWorkbenchAction, IPageListener, IPartListener { 29 30 34 private IWorkbenchWindow workbenchWindow; 35 36 39 public WorkbookEditorsAction(IWorkbenchWindow window) { 40 super(WorkbenchMessages.WorkbookEditorsAction_label); 41 if (window == null) { 42 throw new IllegalArgumentException (); 43 } 44 this.workbenchWindow = window; 45 setActionDefinitionId("org.eclipse.ui.window.openEditorDropDown"); workbenchWindow.addPageListener(this); 49 workbenchWindow.getPartService().addPartListener(this); 50 updateState(); 51 } 52 53 56 public void run() { 57 if (workbenchWindow == null) { 58 return; 60 } 61 IWorkbenchPage page = workbenchWindow.getActivePage(); 62 if (page != null) { 63 WorkbenchPage wbp = (WorkbenchPage) page; 64 EditorAreaHelper eah = wbp.getEditorPresentation(); 65 if (eah != null) { 66 eah.displayEditorList(); 67 } 68 } 69 } 70 71 74 public void dispose() { 75 workbenchWindow.removePageListener(this); 76 workbenchWindow.getPartService().removePartListener(this); 77 workbenchWindow = null; 78 } 79 80 83 public void updateState() { 84 IWorkbenchPage page = null; 85 if (workbenchWindow != null) { 86 page = workbenchWindow.getActivePage(); 87 } 88 if (page == null) { 89 setEnabled(false); 90 return; 91 } 92 setEnabled(page.getEditorReferences().length >= 1); 94 } 95 96 99 public void pageActivated(IWorkbenchPage page) { 100 } 101 102 105 public void pageClosed(IWorkbenchPage page) { 106 updateState(); 107 } 108 109 public void pageOpened(IWorkbenchPage page) { 110 updateState(); 111 } 112 113 116 public void partActivated(IWorkbenchPart part) { 117 } 119 120 123 public void partBroughtToTop(IWorkbenchPart part) { 124 } 126 127 130 public void partClosed(IWorkbenchPart part) { 131 updateState(); 132 } 133 134 137 public void partDeactivated(IWorkbenchPart part) { 138 } 140 141 144 public void partOpened(IWorkbenchPart part) { 145 updateState(); 146 } 147 } 148 | Popular Tags |