KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > ui > actions > OpenJavaBrowsingPerspectiveAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.jdt.ui.actions;
12
13 import org.eclipse.jface.action.Action;
14
15 import org.eclipse.core.resources.ResourcesPlugin;
16 import org.eclipse.core.runtime.IAdaptable;
17
18 import org.eclipse.ui.IWorkbench;
19 import org.eclipse.ui.IWorkbenchPage;
20 import org.eclipse.ui.IWorkbenchWindow;
21 import org.eclipse.ui.WorkbenchException;
22 import org.eclipse.ui.PlatformUI;
23
24 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
25 import org.eclipse.jdt.internal.ui.JavaPlugin;
26 import org.eclipse.jdt.internal.ui.actions.ActionMessages;
27 import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
28
29 import org.eclipse.jdt.ui.JavaUI;
30
31 /**
32  * Action to programmatically open a Java perspective.
33  *
34  * <p>
35  * This class may be instantiated; it is not intended to be subclassed.
36  * </p>
37  *
38  * @since 2.0
39  */

40 public class OpenJavaBrowsingPerspectiveAction extends Action {
41
42     /**
43      * Create a new <code>OpenJavaBrowsingPerspectiveAction</code>.
44      */

45     public OpenJavaBrowsingPerspectiveAction() {
46         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_JAVA_BROWSING_PERSPECTIVE_ACTION);
47     }
48
49     public void run() {
50         IWorkbench workbench= JavaPlugin.getDefault().getWorkbench();
51         IWorkbenchWindow window= workbench.getActiveWorkbenchWindow();
52         IWorkbenchPage page= window.getActivePage();
53         IAdaptable input;
54         if (page != null)
55             input= page.getInput();
56         else
57             input= ResourcesPlugin.getWorkspace().getRoot();
58         try {
59             workbench.showPerspective(JavaUI.ID_BROWSING_PERSPECTIVE, window, input);
60         } catch (WorkbenchException e) {
61             ExceptionHandler.handle(e, window.getShell(),
62                 ActionMessages.OpenJavaBrowsingPerspectiveAction_dialog_title,
63                 ActionMessages.OpenJavaBrowsingPerspectiveAction_error_open_failed);
64         }
65     }
66 }
67
Popular Tags