void createCommand(String commandId, Map parameters) { if (commandId == null) { WorkbenchPlugin.log( "Unable to create menu item \"" + getId() //$NON-NLS-1$ + "\", no command id"); //$NON-NLS-1$ return; } Command cmd = commandService.getCommand(commandId); if (!cmd.isDefined()) { WorkbenchPlugin.log( "Unable to create menu item \"" + getId() //$NON-NLS-1$ + "\", command \"" + commandId + "\" not defined"); //$NON-NLS-1$ //$NON-NLS-2$ return; } if (parameters == null || parameters.size() == 0) { command = new ParameterizedCommand(cmd, null); return; } try { ArrayList parmList = new ArrayList(); Iterator i = parameters.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); String parmName = (String) entry.getKey(); IParameter parm; parm = cmd.getParameter(parmName); if (parm == null) { WorkbenchPlugin.log( "Unable to create menu item \"" + getId() //$NON-NLS-1$ + "\", parameter \"" + parmName + "\" for command \"" //$NON-NLS-1$ //$NON-NLS-2$ + commandId + "\" is not defined"); //$NON-NLS-1$ return; } parmList.add(new Parameterization(parm, (String) entry.getValue())); } command = new ParameterizedCommand( cmd, (Parameterization[]) parmList.toArray(new Parameterization[parmList.size()])); } catch (NotDefinedException e) { // this shouldn't happen as we checked for !defined, but we // won't take the chance WorkbenchPlugin.log( "Failed to create menu item " //$NON-NLS-1$ + getId(), e); } }
private ISiteFeature[] getFeaturesFromSelection(IStructuredSelection sel) { if (sel.isEmpty()) return new ISiteFeature[0]; if (cachedSelection == sel) return cachedFeatures; cachedSelection = sel; ArrayList<ISiteFeature> features = new ArrayList<ISiteFeature>(sel.size()); Iterator<?> iterator = sel.iterator(); while (iterator.hasNext()) { Object next = iterator.next(); if (next instanceof SiteFeatureAdapter) { if ((((SiteFeatureAdapter) next).feature) != null) { features.add(((SiteFeatureAdapter) next).feature); } } } cachedFeatures = features.toArray(new ISiteFeature[features.size()]); return cachedFeatures; }
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()])); } }