1 11 package org.eclipse.pde.internal.ui.launcher; 12 13 import java.util.TreeSet ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.debug.core.ILaunchConfiguration; 17 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 18 import org.eclipse.pde.core.plugin.IPluginAttribute; 19 import org.eclipse.pde.core.plugin.IPluginElement; 20 import org.eclipse.pde.core.plugin.IPluginExtension; 21 import org.eclipse.pde.core.plugin.IPluginModelBase; 22 import org.eclipse.pde.core.plugin.PluginRegistry; 23 import org.eclipse.pde.core.plugin.TargetPlatform; 24 import org.eclipse.pde.internal.core.util.IdUtil; 25 import org.eclipse.pde.internal.ui.IPDEUIConstants; 26 import org.eclipse.pde.ui.launcher.AbstractLauncherTab; 27 import org.eclipse.pde.ui.launcher.EclipseLaunchShortcut; 28 import org.eclipse.pde.ui.launcher.IPDELauncherConstants; 29 30 public class PluginBlock extends AbstractPluginBlock { 31 32 protected ILaunchConfiguration fLaunchConfig; 33 34 public PluginBlock(AbstractLauncherTab tab) { 35 super(tab); 36 } 37 38 public void initializeFrom(ILaunchConfiguration config, boolean customSelection) throws CoreException { 39 super.initializeFrom(config); 40 if (customSelection) { 41 initWorkspacePluginsState(config); 42 initExternalPluginsState(config); 43 } else { 44 handleRestoreDefaults(); 45 } 46 enableViewer(customSelection); 47 updateCounter(); 48 fTab.updateLaunchConfigurationDialog(); 49 fLaunchConfig = config; 50 } 51 52 63 protected void initWorkspacePluginsState(ILaunchConfiguration configuration) throws CoreException { 64 boolean automaticAdd = configuration.getAttribute(IPDELauncherConstants.AUTOMATIC_ADD, true); 65 fPluginTreeViewer.setSubtreeChecked(fWorkspacePlugins, automaticAdd); 66 fNumWorkspaceChecked = automaticAdd ? fWorkspaceModels.length : 0; 67 68 String attribute = automaticAdd 69 ? IPDELauncherConstants.DESELECTED_WORKSPACE_PLUGINS 70 : IPDELauncherConstants.SELECTED_WORKSPACE_PLUGINS; 71 TreeSet ids = LaunchPluginValidator.parsePlugins(configuration, attribute); 72 for (int i = 0; i < fWorkspaceModels.length; i++) { 73 String id = fWorkspaceModels[i].getPluginBase().getId(); 74 if (id == null) 75 continue; 76 if (automaticAdd && ids.contains(id)) { 77 if (fPluginTreeViewer.setChecked(fWorkspaceModels[i], false)) 78 fNumWorkspaceChecked -= 1; 79 } else if (!automaticAdd && ids.contains(id)) { 80 if (fPluginTreeViewer.setChecked(fWorkspaceModels[i], true)) 81 fNumWorkspaceChecked += 1; 82 } 83 } 84 85 fPluginTreeViewer.setChecked(fWorkspacePlugins, fNumWorkspaceChecked > 0); 86 fPluginTreeViewer.setGrayed( 87 fWorkspacePlugins, 88 fNumWorkspaceChecked > 0 && fNumWorkspaceChecked < fWorkspaceModels.length); 89 } 90 91 protected void initExternalPluginsState(ILaunchConfiguration config) 92 throws CoreException { 93 fNumExternalChecked = 0; 94 95 fPluginTreeViewer.setSubtreeChecked(fExternalPlugins, false); 96 TreeSet selected = LaunchPluginValidator.parsePlugins(config, 97 IPDELauncherConstants.SELECTED_TARGET_PLUGINS); 98 for (int i = 0; i < fExternalModels.length; i++) { 99 if (selected.contains(fExternalModels[i].getPluginBase().getId())) { 100 if (fPluginTreeViewer.setChecked(fExternalModels[i], true)) 101 fNumExternalChecked += 1; 102 } 103 } 104 105 fPluginTreeViewer.setChecked(fExternalPlugins, fNumExternalChecked > 0); 106 fPluginTreeViewer.setGrayed(fExternalPlugins, fNumExternalChecked > 0 107 && fNumExternalChecked < fExternalModels.length); 108 } 109 110 protected void savePluginState(ILaunchConfigurationWorkingCopy config) { 111 if (isEnabled()) { 112 StringBuffer wbuf = new StringBuffer (); 114 for (int i = 0; i < fWorkspaceModels.length; i++) { 115 IPluginModelBase model = fWorkspaceModels[i]; 116 if (fPluginTreeViewer.getChecked(model) != fAddWorkspaceButton.getSelection()) { 119 if (wbuf.length() > 0) 120 wbuf.append(","); wbuf.append(model.getPluginBase().getId()); 122 } 123 } 124 125 String value = wbuf.length() > 0 ? wbuf.toString() : null; 126 if (fAddWorkspaceButton.getSelection()) { 127 config.setAttribute(IPDELauncherConstants.DESELECTED_WORKSPACE_PLUGINS, value); 128 config.setAttribute(IPDELauncherConstants.SELECTED_WORKSPACE_PLUGINS, (String )null); 129 } else { 130 config.setAttribute(IPDELauncherConstants.SELECTED_WORKSPACE_PLUGINS, value); 131 } 132 StringBuffer exbuf = new StringBuffer (); 134 Object [] checked = fPluginTreeViewer.getCheckedElements(); 135 for (int i = 0; i < checked.length; i++) { 136 if (checked[i] instanceof IPluginModelBase) { 137 IPluginModelBase model = (IPluginModelBase) checked[i]; 138 if (model.getUnderlyingResource() == null) { 139 if (exbuf.length() > 0) 140 exbuf.append(","); exbuf.append(model.getPluginBase().getId()); 142 } 143 } 144 } 145 value = exbuf.length() > 0 ? exbuf.toString() : null; 146 config.setAttribute(IPDELauncherConstants.SELECTED_TARGET_PLUGINS, value); 147 } else { 148 config.setAttribute(IPDELauncherConstants.SELECTED_TARGET_PLUGINS, (String ) null); 149 config.setAttribute(IPDELauncherConstants.SELECTED_WORKSPACE_PLUGINS, (String ) null); 150 config.setAttribute(IPDELauncherConstants.DESELECTED_WORKSPACE_PLUGINS, (String )null); 151 } 152 } 153 154 protected void computeSubset() { 155 validateExtensions(); 156 super.computeSubset(); 157 } 158 159 private void validateExtensions() { 160 try { 161 if (fLaunchConfig.getAttribute(IPDELauncherConstants.USE_PRODUCT, true)) { 162 String product = fLaunchConfig.getAttribute(IPDELauncherConstants.PRODUCT, (String )null); 163 if (product != null) { 164 validateLaunchId(product); 165 String application = getApplication(product); 166 if (application != null) 167 validateLaunchId(application); 168 } 169 } 170 else { 171 String configType = fLaunchConfig.getType().getIdentifier(); 172 String attribute = configType.equals(EclipseLaunchShortcut.CONFIGURATION_TYPE) 173 ? IPDELauncherConstants.APPLICATION : IPDELauncherConstants.APP_TO_TEST; 174 String application = fLaunchConfig.getAttribute(attribute, TargetPlatform.getDefaultApplication()); 175 if (!IPDEUIConstants.CORE_TEST_APPLICATION.equals(application)) 176 validateLaunchId(application); 177 } 178 } catch (CoreException e) { 179 } 180 } 181 182 private void validateLaunchId(String launchId) { 183 if (launchId != null) { 184 int index = launchId.lastIndexOf('.'); 185 if (index > 0) { 186 String pluginId = launchId.substring(0, index); 187 IPluginModelBase base = findPlugin(pluginId); 189 if (base == null) { 190 base = PluginRegistry.findModel(pluginId); 191 if (base != null) { 192 fPluginTreeViewer.setChecked(base, true); 193 } 194 } 195 } 196 } 197 } 198 199 private String getApplication(String product) { 200 String bundleID = product.substring(0, product.lastIndexOf('.')); 201 IPluginModelBase model = findPlugin(bundleID); 202 203 if (model != null) { 204 IPluginExtension[] extensions = model.getPluginBase().getExtensions(); 205 for (int i = 0; i < extensions.length; i++) { 206 IPluginExtension ext = extensions[i]; 207 String point = ext.getPoint(); 208 if ("org.eclipse.core.runtime.products".equals(point) && product.equals(IdUtil.getFullId(ext))) { 210 if (ext.getChildCount() == 1) { 211 IPluginElement prod = (IPluginElement)ext.getChildren()[0]; 212 if (prod.getName().equals("product")) { IPluginAttribute attr = prod.getAttribute("application"); return attr != null ? attr.getValue() : null; 215 } 216 } 217 } 218 } 219 } 220 return null; 221 } 222 223 protected LaunchValidationOperation createValidationOperation() { 224 return new EclipsePluginValidationOperation(fLaunchConfig); 225 } 226 } 227 | Popular Tags |