1 11 package org.eclipse.ui.internal.dialogs; 12 13 import java.util.StringTokenizer ; 14 15 import org.eclipse.jface.viewers.IStructuredSelection; 16 import org.eclipse.jface.wizard.IWizard; 17 import org.eclipse.jface.wizard.Wizard; 18 import org.eclipse.ui.IWorkbench; 19 import org.eclipse.ui.internal.IWorkbenchGraphicConstants; 20 import org.eclipse.ui.internal.WorkbenchImages; 21 import org.eclipse.ui.internal.WorkbenchMessages; 22 import org.eclipse.ui.internal.WorkbenchPlugin; 23 import org.eclipse.ui.wizards.IWizardCategory; 24 import org.eclipse.ui.wizards.IWizardDescriptor; 25 26 31 public class NewWizard extends Wizard { 32 private static final String CATEGORY_SEPARATOR = "/"; 34 private String categoryId = null; 35 36 private NewWizardSelectionPage mainPage; 37 38 private boolean projectsOnly = false; 39 40 private IStructuredSelection selection; 41 42 private IWorkbench workbench; 43 44 47 public void addPages() { 48 IWizardCategory root = WorkbenchPlugin.getDefault().getNewWizardRegistry().getRootCategory(); 49 IWizardDescriptor [] primary = WorkbenchPlugin.getDefault().getNewWizardRegistry().getPrimaryWizards(); 50 51 if (categoryId != null) { 52 IWizardCategory categories = root; 53 StringTokenizer familyTokenizer = new StringTokenizer (categoryId, 54 CATEGORY_SEPARATOR); 55 while (familyTokenizer.hasMoreElements()) { 56 categories = getChildWithID(categories, familyTokenizer 57 .nextToken()); 58 if (categories == null) { 59 break; 60 } 61 } 62 if (categories != null) { 63 root = categories; 64 } 65 } 66 67 mainPage = new NewWizardSelectionPage(workbench, selection, root, 68 primary, projectsOnly); 69 addPage(mainPage); 70 } 71 72 79 public String getCategoryId() { 80 return categoryId; 81 } 82 83 86 private IWizardCategory getChildWithID( 87 IWizardCategory parent, String id) { 88 IWizardCategory [] children = parent.getCategories(); 89 for (int i = 0; i < children.length; ++i) { 90 IWizardCategory currentChild = children[i]; 91 if (currentChild.getId().equals(id)) { 92 return currentChild; 93 } 94 } 95 return null; 96 } 97 98 103 public void init(IWorkbench aWorkbench, 104 IStructuredSelection currentSelection) { 105 this.workbench = aWorkbench; 106 this.selection = currentSelection; 107 108 if (projectsOnly) { 109 setWindowTitle(WorkbenchMessages.NewProject_title); 110 } else { 111 setWindowTitle(WorkbenchMessages.NewWizard_title); 112 } 113 setDefaultPageImageDescriptor(WorkbenchImages 114 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_WIZBAN_NEW_WIZ)); 115 setNeedsProgressMonitor(true); 116 } 117 118 124 public boolean performFinish() { 125 mainPage.saveWidgetValues(); 127 if (getContainer().getCurrentPage() == mainPage) { 129 if (mainPage.canFinishEarly()) { 130 IWizard wizard = mainPage.getSelectedNode().getWizard(); 131 wizard.setContainer(getContainer()); 132 return wizard.performFinish(); 133 } 134 } 135 return true; 136 } 137 138 145 public void setCategoryId(String id) { 146 categoryId = id; 147 } 148 149 154 public void setProjectsOnly(boolean b) { 155 projectsOnly = b; 156 } 157 158 161 public boolean canFinish() { 162 if (getContainer().getCurrentPage() == mainPage) { 164 if (mainPage.canFinishEarly()) { 165 return true; 166 } 167 } 168 return super.canFinish(); 169 } 170 } 171 | Popular Tags |