KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ClosePerspectiveAction


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.IPerspectiveDescriptor;
14 import org.eclipse.ui.IWorkbenchPage;
15 import org.eclipse.ui.IWorkbenchWindow;
16
17 /**
18  * The <code>ClosePerspectiveAction</code> is used to close the
19  * active perspective in the workbench window's active page.
20  */

21 public class ClosePerspectiveAction extends PerspectiveAction {
22
23     /**
24      * Create a new instance of <code>ClosePerspectiveAction</code>
25      *
26      * @param window the workbench window this action applies to
27      */

28     public ClosePerspectiveAction(IWorkbenchWindow window) {
29         super(window);
30         setText(WorkbenchMessages.ClosePerspectiveAction_text);
31         setActionDefinitionId("org.eclipse.ui.window.closePerspective"); //$NON-NLS-1$
32
// @issue missing action id
33
setToolTipText(WorkbenchMessages.ClosePerspectiveAction_toolTip);
34         window.getWorkbench().getHelpSystem().setHelp(this,
35                 IWorkbenchHelpContextIds.CLOSE_PAGE_ACTION);
36     }
37
38     /* (non-Javadoc)
39      * Method declared on PerspectiveAction.
40      */

41     protected void run(IWorkbenchPage page, IPerspectiveDescriptor perspDesc) {
42         Perspective persp = ((WorkbenchPage) page).getActivePerspective();
43         if (persp != null) {
44             closePerspective((WorkbenchPage) page, persp);
45         }
46     }
47
48     /**
49      * Close the argument perspective in the argument page. Do nothing if the page or
50      * perspective are null.
51      *
52      * @param page the page
53      * @param persp the perspective
54      * @since 3.1
55      */

56     public static void closePerspective(WorkbenchPage page, Perspective persp) {
57         if (page != null && persp != null) {
58             page.closePerspective(persp, true, true);
59         }
60     }
61 }
62
Popular Tags