KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > handlers > ClosePartHandler


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
24  * Provide a Handler for the Close Part command. This can then be bound to
25  * whatever keybinding the user prefers.
26  *
27  * @since 3.3
28  */

29 public class ClosePartHandler extends AbstractHandler {
30
31     /*
32      * (non-Javadoc)
33      *
34      * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
35      */

36     public Object JavaDoc 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