01: /*******************************************************************************
02: * Copyright (c) 2002, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.cheatsheets.actions;
11:
12: import org.eclipse.core.runtime.*;
13: import org.eclipse.jface.action.Action;
14: import org.eclipse.ui.*;
15: import org.eclipse.ui.cheatsheets.*;
16: import org.eclipse.ui.internal.cheatsheets.*;
17:
18: /**
19: * Action to programmatically open a perspective from a cheat sheet.
20: * The perspective id must be passed to the action via param1.
21: *
22: * <p>
23: * This class may be instantiated; it is not intended to be subclassed.
24: * </p>
25: *
26: */
27: public class OpenPerspective extends Action implements
28: ICheatSheetAction {
29:
30: /**
31: * Create a new <code>OpenPerspective</code> action.
32: */
33: public OpenPerspective() {
34: }
35:
36: /**
37: * @see Action#run()
38: */
39: public void run(String[] params, ICheatSheetManager manager) {
40: try {
41: if (params == null || params[0] == null) {
42: return;
43: }
44:
45: IWorkbench workbench = PlatformUI.getWorkbench();
46: IWorkbenchWindow window = workbench
47: .getActiveWorkbenchWindow();
48: IWorkbenchPage page = window.getActivePage();
49:
50: IPerspectiveDescriptor perspective = workbench
51: .getPerspectiveRegistry().findPerspectiveWithId(
52: params[0]);
53: page.setPerspective(perspective);
54: } catch (Exception e) {
55: IStatus status = new Status(IStatus.ERROR,
56: ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID,
57: IStatus.OK, Messages.ERROR_OPENING_PERSPECTIVE,
58: null);
59: CheatSheetPlugin.getPlugin().getLog().log(status);
60: }
61: }
62: }
|