]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/ui/org/eclipse/jdt/ui/actions/OpenJavaPerspectiveAction.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / ui / actions / OpenJavaPerspectiveAction.java
CommitLineData
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 *******************************************************************************/
11package org.eclipse.jdt.ui.actions;
12
13import org.eclipse.core.runtime.IAdaptable;
14
15import org.eclipse.core.resources.ResourcesPlugin;
16
17import org.eclipse.jface.action.Action;
18
19import org.eclipse.ui.IWorkbench;
20import org.eclipse.ui.IWorkbenchPage;
21import org.eclipse.ui.IWorkbenchWindow;
22import org.eclipse.ui.PlatformUI;
23import org.eclipse.ui.WorkbenchException;
24
25import org.eclipse.jdt.ui.JavaUI;
26
27import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
28import org.eclipse.jdt.internal.ui.JavaPlugin;
29import org.eclipse.jdt.internal.ui.actions.ActionMessages;
30import 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 */
43public 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}