KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > actions > OpenPerspective


1 /*******************************************************************************
2  * Copyright (c) 2002, 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.cheatsheets.actions;
12
13 import org.eclipse.core.runtime.*;
14 import org.eclipse.jface.action.Action;
15 import org.eclipse.ui.*;
16 import org.eclipse.ui.cheatsheets.*;
17 import org.eclipse.ui.internal.cheatsheets.*;
18
19 /**
20  * Action to programmatically open a perspective from a cheat sheet.
21  * The perspective id must be passed to the action via param1.
22  *
23  * <p>
24  * This class may be instantiated; it is not intended to be subclassed.
25  * </p>
26  *
27  */

28 public class OpenPerspective extends Action implements ICheatSheetAction {
29
30     /**
31      * Create a new <code>OpenPerspective</code> action.
32      */

33     public OpenPerspective() {
34     }
35
36
37     /**
38      * @see Action#run()
39      */

40     public void run(String JavaDoc[] params, ICheatSheetManager manager) {
41         try {
42             if(params == null || params[0] == null) {
43                 return;
44             }
45
46             IWorkbench workbench = PlatformUI.getWorkbench();
47             IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
48             IWorkbenchPage page = window.getActivePage();
49
50             IPerspectiveDescriptor perspective = workbench.getPerspectiveRegistry().findPerspectiveWithId(params[0]);
51             page.setPerspective(perspective);
52         } catch(Exception JavaDoc e) {
53             IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, Messages.ERROR_OPENING_PERSPECTIVE, null);
54             CheatSheetPlugin.getPlugin().getLog().log(status);
55         }
56     }
57 }
58
Popular Tags