* @see org.eclipse.jface.action.IAction#run()
*/
public void run() {
// create instance of target wizard
INewWizard wizard;
try {
wizard = (INewWizard) wizardElement.createWizard();
} catch (CoreException e) {
ErrorDialog.openError(window.getShell(), WorkbenchMessages.NewWizardShortcutAction_errorTitle,
WorkbenchMessages.NewWizardShortcutAction_errorMessage,
e.getStatus());
return;
}
ISelection selection = window.getSelectionService().getSelection();
IStructuredSelection selectionToPass = StructuredSelection.EMPTY;
if (selection instanceof IStructuredSelection) {
selectionToPass = wizardElement
.adaptedSelection((IStructuredSelection) selection);
} else {
// Build the selection from the IFile of the editor
IWorkbenchPart part = window.getPartService().getActivePart();
if (part instanceof IEditorPart) {
IEditorInput input = ((IEditorPart) part).getEditorInput();
Class fileClass = LegacyResourceSupport.getFileClass();
if (input != null && fileClass != null) {
Object file = Util.getAdapter(input, fileClass);
if (file != null) {
selectionToPass = new StructuredSelection(file);
}
}
}
}
// even tho we MAY finish early without showing a dialog, prep the
// wizard with a dialog and such in case it's logic requires it
// - yes, it wastes a dialog but they are plentiful...
wizard.init(window.getWorkbench(), selectionToPass);
Shell parent = window.getShell();
WizardDialog dialog = new WizardDialog(parent, wizard);
dialog.create();
Point defaultSize = dialog.getShell().getSize();
dialog.getShell().setSize(
Math.max(SIZING_WIZARD_WIDTH, defaultSize.x),
Math.max(SIZING_WIZARD_HEIGHT, defaultSize.y));
window.getWorkbench().getHelpSystem().setHelp(dialog.getShell(),
IWorkbenchHelpContextIds.NEW_WIZARD_SHORTCUT);
// if the wizard can finish early and doesn't have any pages, just finish it.
if (wizardElement.canFinishEarly() && !wizardElement.hasPages()) {
wizard.performFinish();
dialog.close();
} else {
dialog.open();
}
}