1 11 package org.eclipse.ui.actions; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.jface.action.Action; 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.ui.ISharedImages; 21 import org.eclipse.ui.IWorkbenchWindow; 22 import org.eclipse.ui.PlatformUI; 23 import org.eclipse.ui.internal.ide.Category; 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 import org.eclipse.ui.internal.ide.dialogs.MultiStepWizardDialog; 28 import org.eclipse.ui.internal.ide.dialogs.NewProjectWizard; 29 import org.eclipse.ui.internal.ide.registry.Capability; 30 import org.eclipse.ui.internal.ide.registry.CapabilityRegistry; 31 32 42 public class CreateProjectAction extends Action { 43 46 private static final int SIZING_WIZARD_WIDTH = 500; 47 48 51 private static final int SIZING_WIZARD_HEIGHT = 500; 52 53 56 private IWorkbenchWindow window; 57 58 61 private String initialProjectName; 62 63 66 private Capability[] initialProjectCapabilities; 67 68 71 private Category[] initialSelectedCategories; 72 73 80 public CreateProjectAction(IWorkbenchWindow window) { 81 super(IDEWorkbenchMessages.CreateProjectAction_text); 82 if (window == null) { 83 throw new IllegalArgumentException (); 84 } 85 this.window = window; 86 ISharedImages images = PlatformUI.getWorkbench().getSharedImages(); 87 setImageDescriptor(images 88 .getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD)); 89 setDisabledImageDescriptor(images 90 .getImageDescriptor(ISharedImages.IMG_TOOL_NEW_WIZARD_DISABLED)); 91 setToolTipText(IDEWorkbenchMessages.CreateProjectAction_toolTip); 92 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 93 org.eclipse.ui.internal.IWorkbenchHelpContextIds.NEW_ACTION); 94 } 95 96 99 protected IStructuredSelection getInitialSelection() { 100 ISelection selection = window.getSelectionService().getSelection(); 101 IStructuredSelection selectionToPass = StructuredSelection.EMPTY; 102 if (selection instanceof IStructuredSelection) 103 selectionToPass = (IStructuredSelection) selection; 104 return selectionToPass; 105 } 106 107 113 public void setInitialSelectedCategories(String [] ids) { 114 if (ids == null || ids.length == 0) 115 initialSelectedCategories = null; 116 else { 117 CapabilityRegistry reg = IDEWorkbenchPlugin.getDefault() 118 .getCapabilityRegistry(); 119 ArrayList results = new ArrayList (ids.length); 120 for (int i = 0; i < ids.length; i++) { 121 Category cat = reg.findCategory(ids[i]); 122 if (cat != null) 123 results.add(cat); 124 } 125 if (results.isEmpty()) 126 initialSelectedCategories = null; 127 else { 128 initialSelectedCategories = new Category[results.size()]; 129 results.toArray(initialSelectedCategories); 130 } 131 } 132 } 133 134 140 public void setInitialProjectCapabilities(String [] ids) { 141 if (ids == null || ids.length == 0) 142 initialProjectCapabilities = null; 143 else { 144 CapabilityRegistry reg = IDEWorkbenchPlugin.getDefault() 145 .getCapabilityRegistry(); 146 ArrayList results = new ArrayList (ids.length); 147 for (int i = 0; i < ids.length; i++) { 148 Capability cap = reg.findCapability(ids[i]); 149 if (cap != null && cap.isValid()) 150 results.add(cap); 151 } 152 if (results.isEmpty()) 153 initialProjectCapabilities = null; 154 else { 155 initialProjectCapabilities = new Capability[results.size()]; 156 results.toArray(initialProjectCapabilities); 157 } 158 } 159 } 160 161 167 public void setInitialProjectName(String name) { 168 if (name == null) 169 initialProjectName = null; 170 else 171 initialProjectName = name.trim(); 172 } 173 174 177 public void run() { 178 NewProjectWizard wizard = new NewProjectWizard(); 180 wizard.init(window.getWorkbench(), getInitialSelection()); 181 wizard.setInitialProjectName(initialProjectName); 182 wizard.setInitialProjectCapabilities(initialProjectCapabilities); 183 wizard.setInitialSelectedCategories(initialSelectedCategories); 184 185 WizardDialog dialog = new MultiStepWizardDialog(window.getShell(), 187 wizard); 188 dialog.create(); 189 dialog.getShell().setSize( 190 Math.max(SIZING_WIZARD_WIDTH, dialog.getShell().getSize().x), 191 SIZING_WIZARD_HEIGHT); 192 PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), 193 IIDEHelpContextIds.NEW_PROJECT_WIZARD); 194 195 dialog.open(); 197 } 198 } 199 | Popular Tags |