KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > actions > OpenPerspectiveAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.actions;
12
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.swt.events.SelectionEvent;
15 import org.eclipse.swt.widgets.Event;
16 import org.eclipse.ui.IPerspectiveDescriptor;
17 import org.eclipse.ui.IPluginContribution;
18 import org.eclipse.ui.IWorkbenchWindow;
19 import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
20 import org.eclipse.ui.internal.util.Util;
21
22 /**
23  * Opens a perspective.
24  *
25  * @since 3.1
26  */

27 public final class OpenPerspectiveAction extends Action implements
28         IPluginContribution {
29
30     /**
31      * The perspective menu that will handle the execution of this action. This
32      * allows subclasses of <code>PerspectiveMenu</code> to define custom
33      * behaviour for these actions. This value should not be <code>null</code>.
34      */

35     private final PerspectiveMenu callback;
36
37     /**
38      * The descriptor for the perspective that this action should open. This
39      * value is never <code>null</code>.
40      */

41     private final IPerspectiveDescriptor descriptor;
42
43     /**
44      * Constructs a new instance of <code>OpenPerspectiveAction</code>
45      *
46      * @param window
47      * The workbench window in which this action is created; should
48      * not be <code>null</code>.
49      * @param descriptor
50      * The descriptor for the perspective that this action should
51      * open; must not be <code>null</code>.
52      * @param callback
53      * The perspective menu who will handle the actual execution of
54      * this action; should not be <code>null</code>.
55      */

56     public OpenPerspectiveAction(final IWorkbenchWindow window,
57             final IPerspectiveDescriptor descriptor,
58             final PerspectiveMenu callback) {
59         super(Util.ZERO_LENGTH_STRING);
60
61         this.descriptor = descriptor;
62         this.callback = callback;
63
64         final String JavaDoc label = descriptor.getLabel();
65         setText(label);
66         setToolTipText(label);
67         setImageDescriptor(descriptor.getImageDescriptor());
68
69         window.getWorkbench().getHelpSystem().setHelp(this,
70                 IWorkbenchHelpContextIds.OPEN_PERSPECTIVE_ACTION);
71     }
72
73   
74     /* (non-Javadoc)
75      * @see org.eclipse.jface.action.IAction#runWithEvent(org.eclipse.swt.widgets.Event)
76      */

77     public final void runWithEvent(final Event event) {
78         callback.run(descriptor, new SelectionEvent(event));
79     }
80
81     /*
82      * (non-Javadoc)
83      *
84      * @see org.eclipse.ui.activities.support.IPluginContribution#getLocalId()
85      */

86     public String JavaDoc getLocalId() {
87         return descriptor.getId();
88     }
89
90     /*
91      * (non-Javadoc)
92      *
93      * @see org.eclipse.ui.activities.support.IPluginContribution#getPluginId()
94      */

95     public String JavaDoc getPluginId() {
96         return descriptor instanceof IPluginContribution ? ((IPluginContribution) descriptor)
97                 .getPluginId()
98                 : null;
99     }
100 }
101
Popular Tags