1 11 package org.eclipse.ui.actions; 12 13 import org.eclipse.jface.action.Action; 14 import org.eclipse.jface.dialogs.IDialogSettings; 15 import org.eclipse.jface.viewers.ISelection; 16 import org.eclipse.jface.viewers.IStructuredSelection; 17 import org.eclipse.jface.viewers.StructuredSelection; 18 import org.eclipse.jface.wizard.WizardDialog; 19 import org.eclipse.swt.widgets.Shell; 20 import org.eclipse.ui.ISharedImages; 21 import org.eclipse.ui.IWorkbench; 22 import org.eclipse.ui.IWorkbenchWindow; 23 import org.eclipse.ui.PlatformUI; 24 import org.eclipse.ui.internal.dialogs.NewWizard; 25 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 26 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 27 import org.eclipse.ui.internal.ide.IIDEHelpContextIds; 28 import org.eclipse.ui.internal.registry.WizardsRegistryReader; 29 30 37 public class NewExampleAction extends Action { 38 39 42 private static final int SIZING_WIZARD_WIDTH = 500; 43 44 47 private static final int SIZING_WIZARD_HEIGHT = 500; 48 49 52 private IWorkbenchWindow window; 53 54 57 public NewExampleAction() { 58 this(PlatformUI.getWorkbench().getActiveWorkbenchWindow()); 59 } 60 61 68 public NewExampleAction(IWorkbenchWindow window) { 69 super(IDEWorkbenchMessages.NewExampleAction_text); 70 if (window == null) { 71 throw new IllegalArgumentException (); 72 } 73 this.window = window; 74 ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); 75 setImageDescriptor(images 76 .getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD)); 77 setDisabledImageDescriptor(images 78 .getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD_DISABLED)); 79 setToolTipText(IDEWorkbenchMessages.NewExampleAction_toolTip); 80 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 81 org.eclipse.ui.internal.IWorkbenchHelpContextIds.NEW_ACTION); 82 } 83 84 87 public void run() { 88 IWorkbench workbench = PlatformUI.getWorkbench(); 90 NewWizard wizard = new NewWizard(); 91 wizard 92 .setCategoryId(WizardsRegistryReader.FULL_EXAMPLES_WIZARD_CATEGORY); 93 94 ISelection selection = window.getSelectionService().getSelection(); 95 IStructuredSelection selectionToPass = StructuredSelection.EMPTY; 96 if (selection instanceof IStructuredSelection) { 97 selectionToPass = (IStructuredSelection) selection; 98 } 99 wizard.init(workbench, selectionToPass); 100 IDialogSettings workbenchSettings = IDEWorkbenchPlugin.getDefault() 101 .getDialogSettings(); 102 IDialogSettings wizardSettings = workbenchSettings 103 .getSection("NewWizardAction"); if (wizardSettings == null) { 105 wizardSettings = workbenchSettings.addNewSection("NewWizardAction"); } 107 wizard.setDialogSettings(wizardSettings); 108 wizard.setForcePreviousAndNextButtons(true); 109 110 Shell parent = window.getShell(); 112 WizardDialog dialog = new WizardDialog(parent, wizard); 113 dialog.create(); 114 wizard.setWindowTitle(IDEWorkbenchMessages.NewExample_title); 115 dialog.getShell().setSize( 116 Math.max(SIZING_WIZARD_WIDTH, dialog.getShell().getSize().x), 117 SIZING_WIZARD_HEIGHT); 118 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), 119 IIDEHelpContextIds.NEW_PROJECT_WIZARD); 120 121 dialog.open(); 123 } 124 } 125 | Popular Tags |