1 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 39 public class WizardShortcutAction extends Action implements IPluginContribution { 40 private IWizardDescriptor descriptor; 41 42 private IWorkbenchWindow window; 43 44 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 65 public void run() { 66 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 dialog.open(); 95 } 96 97 102 public String getLocalId() { 103 return descriptor.getId(); 104 } 105 106 111 public String getPluginId() { 112 return descriptor.getId(); 113 } 114 115 } 116 | Popular Tags |