01: /*******************************************************************************
02: * Copyright (c) 2006, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.handlers;
11:
12: import org.eclipse.core.commands.AbstractHandler;
13: import org.eclipse.core.commands.ExecutionEvent;
14: import org.eclipse.core.commands.ExecutionException;
15: import org.eclipse.ui.IEditorPart;
16: import org.eclipse.ui.IViewPart;
17: import org.eclipse.ui.IWorkbenchPart;
18: import org.eclipse.ui.IWorkbenchWindow;
19: import org.eclipse.ui.handlers.HandlerUtil;
20:
21: /**
22: * Provide a Handler for the Close Part command. This can then be bound to
23: * whatever keybinding the user prefers.
24: *
25: * @since 3.3
26: */
27: public class ClosePartHandler extends AbstractHandler {
28:
29: /*
30: * (non-Javadoc)
31: *
32: * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
33: */
34: public Object execute(ExecutionEvent event)
35: throws ExecutionException {
36: IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
37: IWorkbenchWindow window = HandlerUtil
38: .getActiveWorkbenchWindowChecked(event);
39:
40: if (part instanceof IEditorPart) {
41: window.getActivePage()
42: .closeEditor((IEditorPart) part, true);
43: } else if (part instanceof IViewPart) {
44: window.getActivePage().hideView((IViewPart) part);
45: }
46:
47: return null;
48: }
49: }
|