KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > navigator > wizards > WizardShortcutAction


1 /*******************************************************************************
2  * Copyright (c) 2003, 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.navigator.wizards;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.jface.action.Action;
15 import org.eclipse.jface.dialogs.ErrorDialog;
16 import org.eclipse.jface.viewers.ISelection;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.jface.viewers.StructuredSelection;
19 import org.eclipse.jface.wizard.WizardDialog;
20 import org.eclipse.swt.widgets.Shell;
21 import org.eclipse.ui.IPluginContribution;
22 import org.eclipse.ui.IWorkbenchWindow;
23 import org.eclipse.ui.IWorkbenchWizard;
24 import org.eclipse.ui.actions.ActionFactory;
25 import org.eclipse.ui.internal.navigator.CommonNavigatorMessages;
26 import org.eclipse.ui.wizards.IWizardDescriptor;
27
28 /**
29  * <p>
30  * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
31  * part of a work in progress. There is a guarantee neither that this API will
32  * work nor that it will remain the same. Please do not use this API without
33  * consulting with the Platform/UI team.
34  * </p>
35  *
36  * @since 3.2
37  *
38  */

39 public class WizardShortcutAction extends Action implements IPluginContribution {
40     private IWizardDescriptor descriptor;
41
42     private IWorkbenchWindow window;
43
44     /**
45      *
46      * @param aWindow
47      * The window to use for the shell and selection service.
48      * @param aDescriptor
49      * The descriptor with information for triggering the desired
50      * wizard.
51      */

52     public WizardShortcutAction(IWorkbenchWindow aWindow,
53             IWizardDescriptor aDescriptor) {
54         super(aDescriptor.getLabel());
55         descriptor = aDescriptor;
56         setToolTipText(descriptor.getDescription());
57         setImageDescriptor(descriptor.getImageDescriptor());
58         setId(ActionFactory.NEW.getId());
59         this.window = aWindow;
60     }
61
62     /**
63      * This action has been invoked by the user
64      */

65     public void run() {
66         // create instance of target wizard
67

68         IWorkbenchWizard wizard;
69         try {
70             wizard = descriptor.createWizard();
71         } catch (CoreException e) {
72             ErrorDialog.openError(window.getShell(),
73                     CommonNavigatorMessages.NewProjectWizard_errorTitle,
74                     CommonNavigatorMessages.NewProjectAction_text, e
75                             .getStatus());
76             return;
77         }
78
79         ISelection selection = window.getSelectionService().getSelection();
80
81         if (selection instanceof IStructuredSelection) {
82             wizard
83                     .init(window.getWorkbench(),
84                             (IStructuredSelection) selection);
85         } else {
86             wizard.init(window.getWorkbench(), StructuredSelection.EMPTY);
87         }
88
89         Shell parent = window.getShell();
90         WizardDialog dialog = new WizardDialog(parent, wizard);
91         dialog.create();
92         // WorkbenchHelp.setHelp(dialog.getShell(),
93
// IWorkbenchHelpContextIds.NEW_WIZARD_SHORTCUT);
94
dialog.open();
95     }
96
97     /*
98      * (non-Javadoc)
99      *
100      * @see org.eclipse.ui.activities.support.IPluginContribution#getLocalId()
101      */

102     public String JavaDoc getLocalId() {
103         return descriptor.getId();
104     }
105
106     /*
107      * (non-Javadoc)
108      *
109      * @see org.eclipse.ui.activities.support.IPluginContribution#getPluginId()
110      */

111     public String JavaDoc getPluginId() {
112         return descriptor.getId();
113     }
114
115 }
116
Popular Tags