]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 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.core.runtime.IAdaptable; | |
14 | ||
15 | import org.eclipse.core.resources.ResourcesPlugin; | |
16 | ||
17 | import org.eclipse.jface.action.Action; | |
18 | ||
19 | import org.eclipse.ui.IWorkbench; | |
20 | import org.eclipse.ui.IWorkbenchPage; | |
21 | import org.eclipse.ui.IWorkbenchWindow; | |
22 | import org.eclipse.ui.PlatformUI; | |
23 | import org.eclipse.ui.WorkbenchException; | |
24 | ||
25 | import org.eclipse.jdt.ui.JavaUI; | |
26 | ||
27 | import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; | |
28 | import org.eclipse.jdt.internal.ui.JavaPlugin; | |
29 | import org.eclipse.jdt.internal.ui.actions.ActionMessages; | |
30 | import org.eclipse.jdt.internal.ui.util.ExceptionHandler; | |
31 | ||
32 | /** | |
33 | * Action to programmatically open a Java perspective. | |
34 | * | |
35 | * <p> | |
36 | * This class may be instantiated; it is not intended to be subclassed. | |
37 | * </p> | |
38 | * | |
39 | * @since 2.0 | |
40 | * | |
41 | * @noextend This class is not intended to be subclassed by clients. | |
42 | */ | |
43 | public class OpenJavaPerspectiveAction extends Action { | |
44 | ||
45 | /** | |
46 | * Create a new <code>OpenJavaPerspectiveAction</code>. | |
47 | */ | |
48 | public OpenJavaPerspectiveAction() { | |
49 | PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_JAVA_PERSPECTIVE_ACTION); | |
50 | } | |
51 | ||
52 | @Override | |
53 | public void run() { | |
54 | IWorkbench workbench= JavaPlugin.getDefault().getWorkbench(); | |
55 | IWorkbenchWindow window= workbench.getActiveWorkbenchWindow(); | |
56 | IWorkbenchPage page= window.getActivePage(); | |
57 | IAdaptable input; | |
58 | if (page != null) | |
59 | input= page.getInput(); | |
60 | else | |
61 | input= ResourcesPlugin.getWorkspace().getRoot(); | |
62 | try { | |
63 | workbench.showPerspective(JavaUI.ID_PERSPECTIVE, window, input); | |
64 | } catch (WorkbenchException e) { | |
65 | ExceptionHandler.handle(e, window.getShell(), | |
66 | ActionMessages.OpenJavaPerspectiveAction_dialog_title, | |
67 | ActionMessages.OpenJavaPerspectiveAction_error_open_failed); | |
68 | } | |
69 | } | |
70 | } |