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.ui.ISharedImages; 20 import org.eclipse.ui.IWorkbench; 21 import org.eclipse.ui.IWorkbenchWindow; 22 import org.eclipse.ui.PlatformUI; 23 import org.eclipse.ui.internal.dialogs.NewWizard; 24 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 25 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 26 import org.eclipse.ui.internal.ide.IIDEHelpContextIds; 27 28 35 public class NewProjectAction extends Action { 36 37 40 private static final int SIZING_WIZARD_WIDTH = 500; 41 42 45 private static final int SIZING_WIZARD_HEIGHT = 500; 46 47 50 private IWorkbenchWindow window; 51 52 55 public NewProjectAction() { 56 this(PlatformUI.getWorkbench().getActiveWorkbenchWindow()); 57 } 58 59 66 public NewProjectAction(IWorkbenchWindow window) { 67 super(IDEWorkbenchMessages.NewProjectAction_text); 68 if (window == null) { 69 throw new IllegalArgumentException (); 70 } 71 this.window = window; 72 ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); 73 setImageDescriptor(images 74 .getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD)); 75 setDisabledImageDescriptor(images 76 .getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD_DISABLED)); 77 setToolTipText(IDEWorkbenchMessages.NewProjectAction_toolTip); 78 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 79 org.eclipse.ui.internal.IWorkbenchHelpContextIds.NEW_ACTION); 80 } 81 82 85 public void run() { 86 IWorkbench workbench = PlatformUI.getWorkbench(); 88 NewWizard wizard = new NewWizard(); 89 wizard.setProjectsOnly(true); 90 ISelection selection = window.getSelectionService().getSelection(); 91 IStructuredSelection selectionToPass = StructuredSelection.EMPTY; 92 if (selection instanceof IStructuredSelection) { 93 selectionToPass = (IStructuredSelection) selection; 94 } 95 wizard.init(workbench, selectionToPass); 96 IDialogSettings workbenchSettings = IDEWorkbenchPlugin.getDefault() 97 .getDialogSettings(); 98 IDialogSettings wizardSettings = workbenchSettings 99 .getSection("NewWizardAction"); if (wizardSettings == null) { 101 wizardSettings = workbenchSettings.addNewSection("NewWizardAction"); } 103 wizard.setDialogSettings(wizardSettings); 104 wizard.setForcePreviousAndNextButtons(true); 105 106 WizardDialog dialog = new WizardDialog(null, wizard); 108 dialog.create(); 109 dialog.getShell().setSize( 110 Math.max(SIZING_WIZARD_WIDTH, dialog.getShell().getSize().x), 111 SIZING_WIZARD_HEIGHT); 112 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), 113 IIDEHelpContextIds.NEW_PROJECT_WIZARD); 114 115 dialog.open(); 117 } 118 } 119 | Popular Tags |