1 11 package org.eclipse.team.internal.ui.wizards; 12 13 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.jface.wizard.IWizardPage; 17 import org.eclipse.jface.wizard.Wizard; 18 import org.eclipse.team.internal.ui.*; 19 import org.eclipse.team.ui.IConfigurationWizard; 20 import org.eclipse.ui.IWorkbench; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.activities.IActivityManager; 23 import org.eclipse.ui.activities.IIdentifier; 24 import org.eclipse.ui.model.AdaptableList; 25 26 29 public class ConfigureProjectWizard extends Wizard implements IConfigurationWizard { 30 protected IWorkbench workbench; 31 protected IProject project; 32 protected IConfigurationWizard wizard; 33 34 protected ConfigureProjectWizardMainPage mainPage; 35 private String pluginId = TeamUIPlugin.PLUGIN_ID; 36 37 protected final static String PT_CONFIGURATION ="configurationWizards"; protected final static String TAG_WIZARD = "wizard"; protected final static String TAG_DESCRIPTION = "description"; protected final static String ATT_NAME = "name"; protected final static String ATT_CLASS = "class"; protected final static String ATT_ICON = "icon"; protected final static String ATT_ID = "id"; 45 public ConfigureProjectWizard() { 46 setNeedsProgressMonitor(true); 47 setWindowTitle(getWizardWindowTitle()); 48 } 49 50 protected String getExtensionPoint() { 51 return PT_CONFIGURATION; 52 } 53 54 protected String getWizardWindowTitle() { 55 return TeamUIMessages.ConfigureProjectWizard_title; 56 } 57 58 protected String getWizardLabel() { 59 return TeamUIMessages.ConfigureProjectWizard_configureProject; 60 } 61 62 protected String getWizardDescription() { 63 return TeamUIMessages.ConfigureProjectWizard_description; 64 } 65 66 69 public void addPages() { 70 AdaptableList disabledWizards = new AdaptableList(); 71 AdaptableList wizards = getAvailableWizards(disabledWizards); 72 if (wizards.size() == 1 && disabledWizards.size() == 0) { 73 ConfigurationWizardElement element = (ConfigurationWizardElement)wizards.getChildren()[0]; 76 try { 77 this.wizard = (IConfigurationWizard)element.createExecutableExtension(); 78 wizard.init(workbench, project); 79 wizard.addPages(); 80 if (wizard.getPageCount() > 0) { 81 wizard.setContainer(getContainer()); 82 IWizardPage[] pages = wizard.getPages(); 83 for (int i = 0; i < pages.length; i++) { 84 addPage(pages[i]); 85 } 86 return; 87 } 88 } catch (CoreException e) { 89 TeamUIPlugin.log(e); 90 return; 91 } 92 } 93 mainPage = new ConfigureProjectWizardMainPage("configurePage1", getWizardLabel(), TeamUIPlugin.getImageDescriptor(ITeamUIImages.IMG_WIZBAN_SHARE), wizards, disabledWizards); mainPage.setDescription(getWizardDescription()); 95 mainPage.setProject(project); 96 mainPage.setWorkbench(workbench); 97 addPage(mainPage); 98 } 99 public IWizardPage getNextPage(IWizardPage page) { 100 if (wizard != null) { 101 return wizard.getNextPage(page); 102 } 103 return super.getNextPage(page); 104 } 105 public boolean canFinish() { 106 if (getContainer().getCurrentPage() == mainPage) { 108 if (mainPage.getSelectedWizard() != null && mainPage.getNextPage() == null) { 109 return true; 110 } 111 return false; 112 } 113 if (wizard != null) { 114 return wizard.canFinish(); 115 } 116 return super.canFinish(); 117 } 118 121 public boolean performFinish() { 122 if (wizard != null) { 124 return wizard.performFinish(); 125 } 126 if (getContainer().getCurrentPage() == mainPage) { 129 IConfigurationWizard noPageWizard = mainPage.getSelectedWizard(); 130 if (noPageWizard != null) { 131 if (noPageWizard.canFinish()) 132 { 133 return noPageWizard.performFinish(); 134 } 135 } 136 } 137 return true; 141 } 142 143 146 public boolean performCancel() { 147 if (wizard != null) { 148 return wizard.performCancel(); 149 } 150 return super.performCancel(); 151 } 152 153 158 protected AdaptableList getAvailableWizards(AdaptableList disabledWizards) { 159 AdaptableList result = new AdaptableList(); 160 IExtensionRegistry registry = Platform.getExtensionRegistry(); 161 IExtensionPoint point = registry.getExtensionPoint(pluginId, getExtensionPoint()); 162 if (point != null) { 163 IExtension[] extensions = point.getExtensions(); 164 for (int i = 0; i < extensions.length; i++) { 165 IConfigurationElement[] elements = extensions[i].getConfigurationElements(); 166 for (int j = 0; j < elements.length; j++) { 167 IConfigurationElement element = elements[j]; 168 if (element.getName().equals(TAG_WIZARD)) { 169 ConfigurationWizardElement wizard = createWizardElement(element); 170 if (wizard != null && filterItem(element)) { 171 disabledWizards.add(wizard); 172 } else if (wizard != null) { 173 result.add(wizard); 174 } 175 } 176 } 177 } 178 } 179 return result; 180 } 181 182 private boolean filterItem(IConfigurationElement element) { 183 String extensionId = element.getAttribute(ATT_ID); 184 String extensionPluginId = element.getNamespace(); 185 IActivityManager activityMgr = PlatformUI.getWorkbench().getActivitySupport().getActivityManager(); 186 IIdentifier id = activityMgr.getIdentifier(extensionPluginId + "/" + extensionId); return (!id.isEnabled()); 188 } 189 190 200 protected ConfigurationWizardElement createWizardElement(IConfigurationElement element) { 201 String nameString = element.getAttribute(ATT_NAME); 203 if (nameString == null) { 204 return null; 206 } 207 ConfigurationWizardElement result = new ConfigurationWizardElement(nameString); 208 if (initializeWizard(result, element)) { 209 return result; 211 } 212 return null; 213 } 214 223 protected boolean initializeWizard(ConfigurationWizardElement element, IConfigurationElement config) { 224 element.setID(config.getAttribute(ATT_ID)); 225 String description = ""; IConfigurationElement [] children = config.getChildren(TAG_DESCRIPTION); 227 if (children.length >= 1) { 228 description = children[0].getValue(); 229 } 230 231 element.setDescription(description); 232 233 element.setConfigurationElement(config); 235 String iconName = config.getAttribute(ATT_ICON); 236 if (iconName != null) { 237 IExtension extension = config.getDeclaringExtension(); 238 element.setImageDescriptor(TeamUIPlugin.getImageDescriptorFromExtension(extension, iconName)); 239 } 240 if (element.getConfigurationElement() == null) { 242 return false; 244 } 245 setForcePreviousAndNextButtons(true); 246 return true; 247 } 248 251 public void init(IWorkbench workbench, IProject project) { 252 this.workbench = workbench; 253 this.project = project; 254 } 255 } 256 | Popular Tags |