public Menu getMenu(Control parent) {
    XMLPlugin plugin = XMLPlugin.getDefault();
    Menu menu = new Menu(parent);
    addActionToMenu(menu, new SelectMatcherAction(XMLStructureCreator.USE_UNORDERED, fViewer));
    addActionToMenu(menu, new SelectMatcherAction(XMLStructureCreator.USE_ORDERED, fViewer));
    new MenuItem(menu, SWT.SEPARATOR);
    HashMap IdMaps = plugin.getIdMaps();
    HashMap IdMapsInternal = plugin.getIdMapsInternal();

    Set keySetIdMaps = IdMaps.keySet();
    Set keySetIdMapsInternal = IdMapsInternal.keySet();
    ArrayList internalIdMapsAL = new ArrayList();
    for (Iterator iter_internal = keySetIdMapsInternal.iterator(); iter_internal.hasNext(); ) {
      String idmap_name = (String) iter_internal.next();
      internalIdMapsAL.add(idmap_name);
    }
    Object[] internalIdMapsA = internalIdMapsAL.toArray();
    Arrays.sort(internalIdMapsA);
    for (int i = 0; i < internalIdMapsA.length; i++) {
      addActionToMenu(menu, new SelectMatcherAction((String) internalIdMapsA[i], fViewer));
    }
    new MenuItem(menu, SWT.SEPARATOR);

    ArrayList userIdMapsAL = new ArrayList();
    for (Iterator iter_idmaps = keySetIdMaps.iterator(); iter_idmaps.hasNext(); ) {
      String idmap_name = (String) iter_idmaps.next();
      userIdMapsAL.add(idmap_name);
    }

    HashMap OrderedElements = plugin.getOrderedElements();
    Set keySetOrdered = OrderedElements.keySet();
    for (Iterator iter_orderedElements = keySetOrdered.iterator();
        iter_orderedElements.hasNext(); ) {
      String idmap_name = (String) iter_orderedElements.next();
      if (!keySetIdMaps.contains(idmap_name)) {
        userIdMapsAL.add(idmap_name);
      }
    }

    Object[] userIdMapsA = userIdMapsAL.toArray();
    Arrays.sort(userIdMapsA);
    for (int i = 0; i < userIdMapsA.length; i++) {
      addActionToMenu(menu, new SelectMatcherAction((String) userIdMapsA[i], fViewer));
    }

    return menu;
  }
  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);
    }
  }
 /**
  * Uses the feature model to determine the set of features required by the given list of checked
  * features
  *
  * @param allFeatures list of all features to search requirements in
  * @param checkedFeatures list of features to get requirements for
  * @return list of features to be checked
  */
 private Object[] getRequiredFeatures(
     final IFeatureModel[] allFeatures, final Object[] checkedFeatures) {
   ArrayList required = new ArrayList();
   for (int j = 0; j < checkedFeatures.length; j++) {
     if (checkedFeatures[j] instanceof IFeatureModel) {
       getFeatureDependencies((IFeatureModel) checkedFeatures[j], allFeatures, required);
     }
   }
   return required.toArray();
 }
 public Object[] getElements(Object inputElement) {
   // model = (ISite) inputElement;
   ArrayList<IWritable> result = new ArrayList<IWritable>();
   ISiteCategoryDefinition[] catDefs = fModel.getSite().getCategoryDefinitions();
   for (int i = 0; i < catDefs.length; i++) {
     result.add(catDefs[i]);
   }
   ISiteFeature[] features = fModel.getSite().getFeatures();
   for (int i = 0; i < features.length; i++) {
     if (features[i].getCategories().length == 0)
       result.add(new SiteFeatureAdapter(null, features[i]));
   }
   return result.toArray();
 }
 public void setEntity(XModelEntity entity, int child) {
   String cen = entity.getChildren()[child].getName();
   XModelEntity ce = entity.getMetaModel().getEntity(cen);
   if (ce == null) return;
   XAttribute[] as = ce.getAttributes();
   ArrayList<String> l = new ArrayList<String>();
   for (int i = 0; i < as.length; i++) {
     if (!as[i].isVisible()) continue;
     if ("element type".equals(as[i].getName())) continue; // $NON-NLS-1$
     l.add(as[i].getName());
     if (l.size() >= 4) break;
   }
   String[] h = l.toArray(new String[0]);
   if (!same(h)) headerNames = h;
 }
 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()]));
   }
 }
  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);
  }