01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 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;
11:
12: import org.eclipse.ui.IPerspectiveDescriptor;
13: import org.eclipse.ui.IWorkbenchPage;
14: import org.eclipse.ui.IWorkbenchWindow;
15:
16: /**
17: * The <code>ClosePerspectiveAction</code> is used to close the
18: * active perspective in the workbench window's active page.
19: */
20: public class ClosePerspectiveAction extends PerspectiveAction {
21:
22: /**
23: * Create a new instance of <code>ClosePerspectiveAction</code>
24: *
25: * @param window the workbench window this action applies to
26: */
27: public ClosePerspectiveAction(IWorkbenchWindow window) {
28: super (window);
29: setText(WorkbenchMessages.ClosePerspectiveAction_text);
30: setActionDefinitionId("org.eclipse.ui.window.closePerspective"); //$NON-NLS-1$
31: // @issue missing action id
32: setToolTipText(WorkbenchMessages.ClosePerspectiveAction_toolTip);
33: window.getWorkbench().getHelpSystem().setHelp(this ,
34: IWorkbenchHelpContextIds.CLOSE_PAGE_ACTION);
35: }
36:
37: /* (non-Javadoc)
38: * Method declared on PerspectiveAction.
39: */
40: protected void run(IWorkbenchPage page,
41: IPerspectiveDescriptor perspDesc) {
42: Perspective persp = ((WorkbenchPage) page)
43: .getActivePerspective();
44: if (persp != null) {
45: closePerspective((WorkbenchPage) page, persp);
46: }
47: }
48:
49: /**
50: * Close the argument perspective in the argument page. Do nothing if the page or
51: * perspective are null.
52: *
53: * @param page the page
54: * @param persp the perspective
55: * @since 3.1
56: */
57: public static void closePerspective(WorkbenchPage page,
58: Perspective persp) {
59: if (page != null && persp != null) {
60: page.closePerspective(persp, true, true);
61: }
62: }
63: }
|