1 11 12 package org.eclipse.ui.internal.handlers; 13 14 import org.eclipse.core.commands.AbstractHandler; 15 import org.eclipse.core.commands.ExecutionEvent; 16 import org.eclipse.core.commands.ExecutionException; 17 import org.eclipse.ui.IEditorPart; 18 import org.eclipse.ui.IViewPart; 19 import org.eclipse.ui.IWorkbenchPart; 20 import org.eclipse.ui.IWorkbenchWindow; 21 import org.eclipse.ui.handlers.HandlerUtil; 22 23 29 public class ClosePartHandler extends AbstractHandler { 30 31 36 public Object execute(ExecutionEvent event) throws ExecutionException { 37 IWorkbenchPart part = HandlerUtil.getActivePartChecked(event); 38 IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); 39 40 if (part instanceof IEditorPart) { 41 window.getActivePage().closeEditor((IEditorPart) part, true); 42 } else if (part instanceof IViewPart) { 43 window.getActivePage().hideView((IViewPart) part); 44 } 45 46 return null; 47 } 48 } 49 | Popular Tags |