1 11 package org.eclipse.ui.internal.ide.dialogs; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.jface.dialogs.MessageDialog; 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.jface.wizard.IWizardPage; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.ui.IWorkbench; 22 import org.eclipse.ui.PlatformUI; 23 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 24 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 25 import org.eclipse.ui.internal.ide.registry.Capability; 26 import org.eclipse.ui.internal.ide.registry.CapabilityRegistry; 27 28 33 public class UpdateProjectCapabilityWizard extends MultiStepCapabilityWizard { 34 private IProject project; 35 36 private Capability[] addCapabilities; 37 38 private Capability[] removeCapabilities; 39 40 48 public UpdateProjectCapabilityWizard(IProject project, 49 Capability[] addCapabilities, Capability[] removeCapabilities) { 50 super(); 51 this.project = project; 52 this.addCapabilities = addCapabilities; 53 this.removeCapabilities = removeCapabilities; 54 initializeDefaultPageImageDescriptor(); 55 setWindowTitle(IDEWorkbenchMessages.UpdateProjectCapabilityWizard_windowTitle); 56 } 57 58 61 private void buildSteps() { 62 int stepNumber = 1; 63 ArrayList steps = new ArrayList (removeCapabilities.length 64 + addCapabilities.length); 65 66 if (removeCapabilities.length > 0) { 68 for (int i = removeCapabilities.length - 1; i >= 0; i--) { 70 if (removeCapabilities[i] != null) { 71 ArrayList natureIds = new ArrayList (); 75 natureIds.add(removeCapabilities[i].getNatureId()); 76 ArrayList uiIds = removeCapabilities[i].getHandleUIs(); 77 if (uiIds != null) { 78 Iterator it = uiIds.iterator(); 79 while (it.hasNext()) { 80 String id = (String ) it.next(); 81 for (int j = 0; j < removeCapabilities.length; j++) { 82 if (removeCapabilities[j] != null) { 83 if (removeCapabilities[j].getId() 84 .equals(id)) { 85 natureIds.add(removeCapabilities[j] 86 .getNatureId()); 87 removeCapabilities[j] = null; 88 } 89 } 90 } 91 } 92 } 93 String [] ids = new String [natureIds.size()]; 95 natureIds.toArray(ids); 96 steps.add(new RemoveCapabilityStep(stepNumber, 97 removeCapabilities[i], ids, project)); 98 stepNumber++; 99 } 100 } 101 } 102 103 if (addCapabilities.length > 0) { 105 IWorkbench workbench = PlatformUI.getWorkbench(); 106 CapabilityRegistry reg = IDEWorkbenchPlugin.getDefault() 107 .getCapabilityRegistry(); 108 Capability[] results = reg.pruneCapabilities(addCapabilities); 109 for (int i = 0; i < results.length; i++, stepNumber++) 110 steps.add(new InstallCapabilityStep(stepNumber, results[i], 111 workbench, this)); 112 } 113 114 WizardStep[] results = new WizardStep[steps.size()]; 116 steps.toArray(results); 117 setSteps(results); 118 } 119 120 123 protected void addCustomPages() { 124 } 125 126 129 protected boolean canFinishOnReviewPage() { 130 WizardStep[] steps = getSteps(); 131 return steps.length == 1 && steps[0] instanceof RemoveCapabilityStep; 133 } 134 135 138 protected String getConfigurePageTitle() { 139 return IDEWorkbenchMessages.UpdateProjectCapabilityWizard_title; 140 } 141 142 145 protected String getConfigurePageDescription() { 146 return IDEWorkbenchMessages.WizardProjectConfigurePage_description; 147 } 148 149 152 protected String getFinishStepLabel(WizardStep[] steps) { 153 int count = 0; 154 for (int i = 0; i < steps.length; i++) { 155 if (!(steps[i] instanceof RemoveCapabilityStep)) { 156 count++; 157 if (count > 1) 158 return super.getFinishStepLabel(steps); 159 } 160 } 161 162 return null; 163 } 164 165 168 protected String [] getPerspectiveChoices() { 169 ArrayList results = new ArrayList (); 170 for (int i = 0; i < addCapabilities.length; i++) { 171 ArrayList ids = addCapabilities[i].getPerspectiveChoices(); 172 if (ids != null) { 173 Iterator it = ids.iterator(); 174 while (it.hasNext()) { 175 String id = (String ) it.next(); 176 if (!results.contains(id)) 177 results.add(id); 178 } 179 } 180 } 181 String [] ids = new String [results.size()]; 182 results.toArray(ids); 183 return ids; 184 } 185 186 189 public IProject getProject() { 190 return project; 191 } 192 193 196 protected String getReviewPageTitle() { 197 return IDEWorkbenchMessages.UpdateProjectCapabilityWizard_title; 198 } 199 200 203 protected String getReviewPageDescription() { 204 return IDEWorkbenchMessages.WizardProjectReviewPage_description; 205 } 206 207 210 public IWizardPage getStartingPage() { 211 IWizardPage page = super.getStartingPage(); 212 buildSteps(); 213 return page; 214 } 215 216 219 boolean handleMissingStepWizard(WizardStep step) { 220 MessageDialog 221 .openError( 222 getShell(), 223 IDEWorkbenchMessages.UpdateProjectCapabilityWizard_errorTitle, 224 NLS.bind(IDEWorkbenchMessages.UpdateProjectCapabilityWizard_noWizard, step.getLabel())); 225 return false; 226 } 227 228 231 protected void initializeDefaultPageImageDescriptor() { 232 ImageDescriptor desc = IDEWorkbenchPlugin.getIDEImageDescriptor("wizban/newprj_wiz.gif"); 234 setDefaultPageImageDescriptor(desc); 235 236 } 237 } 238 | Popular Tags |