public void computeImports() throws CoreException { // some existing imports may valid and can be preserved Vector preservedImports = new Vector(fImports.size()); // new imports ArrayList newImports = new ArrayList(); IPluginModelBase model = null; for (int i = 0; i < fPlugins.size(); i++) { IFeaturePlugin fp = (IFeaturePlugin) fPlugins.get(i); ModelEntry entry = PluginRegistry.findEntry(fp.getId()); if (entry == null) continue; IPluginModelBase[] models = entry.getActiveModels(); for (int j = 0; j < models.length; j++) { IPluginModelBase m = models[j]; if (fp.getVersion().equals(m.getPluginBase().getVersion()) || fp.getVersion().equals("0.0.0")) // $NON-NLS-1$ model = m; } if (model != null) { addPluginImports(preservedImports, newImports, model.getPluginBase()); if (model.isFragmentModel()) { BundleDescription desc = model.getBundleDescription(); if (desc == null) continue; HostSpecification hostSpec = desc.getHost(); String id = hostSpec.getName(); String version = null; int match = IMatchRules.NONE; VersionRange versionRange = hostSpec.getVersionRange(); if (!(versionRange == null || VersionRange.emptyRange.equals(versionRange))) { version = versionRange.getMinimum() != null ? versionRange.getMinimum().toString() : null; match = PluginBase.getMatchRule(versionRange); } addNewDependency(id, version, match, preservedImports, newImports); } } } // preserve imports of features for (int i = 0; i < fImports.size(); i++) { IFeatureImport iimport = (IFeatureImport) fImports.get(i); if (iimport.getType() == IFeatureImport.FEATURE) preservedImports.add(iimport); } // removed = old - preserved Vector removedImports = ((Vector) fImports.clone()); removedImports.removeAll(preservedImports); // perform remove fImports = preservedImports; if (removedImports.size() > 0) { fireStructureChanged( (IFeatureImport[]) removedImports.toArray(new IFeatureImport[removedImports.size()]), IModelChangedEvent.REMOVE); } // perform add if (newImports.size() > 0) { fImports.addAll(newImports); fireStructureChanged( (IFeatureImport[]) newImports.toArray(new IFeatureImport[newImports.size()]), IModelChangedEvent.INSERT); } }
private void handleAddWorkingSet() { IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); IWorkingSetSelectionDialog dialog = manager.createWorkingSetSelectionDialog(PDEPlugin.getActiveWorkbenchShell(), true); if (dialog.open() == Window.OK) { IWorkingSet[] workingSets = dialog.getSelection(); IProduct product = getProduct(); IProductModelFactory factory = product.getModel().getFactory(); ArrayList<IProductPlugin> pluginList = new ArrayList<IProductPlugin>(); for (int i = 0; i < workingSets.length; i++) { IAdaptable[] elements = workingSets[i].getElements(); for (int j = 0; j < elements.length; j++) { IPluginModelBase model = findModel(elements[j]); if (model != null) { IProductPlugin plugin = factory.createPlugin(); IPluginBase base = model.getPluginBase(); plugin.setId(base.getId()); pluginList.add(plugin); } } } product.addPlugins(pluginList.toArray(new IProductPlugin[pluginList.size()])); } }
public static void handleAddRequired(IProductPlugin[] plugins, boolean includeOptional) { if (plugins.length == 0) return; ArrayList<BundleDescription> list = new ArrayList<BundleDescription>(plugins.length); for (int i = 0; i < plugins.length; i++) { list.add(TargetPlatformHelper.getState().getBundle(plugins[i].getId(), null)); } DependencyCalculator calculator = new DependencyCalculator(includeOptional); calculator.findDependencies(list.toArray()); BundleDescription[] bundles = TargetPlatformHelper.getState().getBundles(); for (int i = 0; i < bundles.length; i++) { HostSpecification host = bundles[i].getHost(); if (host != null && !("org.eclipse.ui.workbench.compatibility" .equals(bundles[i].getSymbolicName())) // $NON-NLS-1$ && calculator.containsPluginId(host.getName())) { calculator.findDependency(bundles[i]); } } Collection<?> dependencies = calculator.getBundleIDs(); IProduct product = plugins[0].getProduct(); IProductModelFactory factory = product.getModel().getFactory(); IProductPlugin[] requiredPlugins = new IProductPlugin[dependencies.size()]; int i = 0; Iterator<?> iter = dependencies.iterator(); while (iter.hasNext()) { String id = iter.next().toString(); IProductPlugin plugin = factory.createPlugin(); plugin.setId(id); requiredPlugins[i++] = plugin; } product.addPlugins(requiredPlugins); }