|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2006 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 |
package org.eclipse.ui.internal; |
| 12 |
|
| 13 |
import org.eclipse.ui.*; |
| 14 |
|
| 15 |
/** |
| 16 |
* Closes the active editor. |
| 17 |
*/ |
| 18 |
public class ClosePartAction extends PageEventAction { |
| 19 |
/** |
| 20 |
* Create an instance of this class. |
| 21 |
* |
| 22 |
* @param window the window |
| 23 |
*/ |
| 24 |
public ClosePartAction(IWorkbenchWindow window) { |
| 25 |
super(WorkbenchMessages.CloseEditorAction_text, window); |
| 26 |
setToolTipText(WorkbenchMessages.CloseEditorAction_toolTip); |
| 27 |
setId("closePart"); //$NON-NLS-1$ |
| 28 |
window.getWorkbench().getHelpSystem().setHelp(this, IWorkbenchHelpContextIds.CLOSE_PART_ACTION); |
| 29 |
setActionDefinitionId("org.eclipse.ui.part.close"); //$NON-NLS-1$ |
| 30 |
} |
| 31 |
|
| 32 |
/* (non-Javadoc) |
| 33 |
* Method declared on IAction. |
| 34 |
*/ |
| 35 |
public void run() { |
| 36 |
IWorkbenchPage page = getActivePage(); |
| 37 |
if (!(page instanceof WorkbenchPage)) |
| 38 |
return; |
| 39 |
IWorkbenchPartReference partRef = page.getActivePartReference(); |
| 40 |
if (partRef == null) |
| 41 |
return; |
| 42 |
if (partRef instanceof IViewReference) { |
| 43 |
page.hideView((IViewReference) partRef); |
| 44 |
} else if (partRef instanceof IEditorReference) { |
| 45 |
page.closeEditors(new IEditorReference[] {(IEditorReference) partRef}, true); |
| 46 |
} |
| 47 |
} |
| 48 |
} |