private void removeOrdered(Shell shell) {
   TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
   TableItem[] itemsOrdered = fOrderedTable.getSelection();
   if (itemsOrdered.length > 0 && itemsIdMaps.length > 0) {
     Mapping mapping = (Mapping) itemsOrdered[0].getData();
     IdMap idmap = (IdMap) itemsIdMaps[0].getData();
     ArrayList idmapAL = (ArrayList) fOrderedElements.get(idmap.getName());
     idmapAL.remove(mapping.getKey());
     if (idmapAL.size() <= 0) fOrderedElements.remove(idmap.getName());
     ArrayList ordered = idmap.getOrdered();
     ordered.remove(mapping);
     if (ordered.size() <= 0) idmap.setOrdered(null);
     itemsOrdered[0].dispose(); // Table is single selection
   }
 }
  private void handleSetImportSelection(ArrayList<Object> newSelectionList) {
    if (newSelectionList.size() == 0) {
      handleRemoveAll();
      pageChanged();
      return;
    }
    TableItem[] items = fImportListViewer.getTable().getItems();
    Object[] oldSelection = new Object[items.length];
    for (int i = 0; i < items.length; i++) {
      oldSelection[i] = items[i].getData();
    }

    // remove items that were in the old selection, but are not in the new one
    List<Object> itemsToRemove = new ArrayList<>();
    for (int i = 0; i < oldSelection.length; i++) {
      if (newSelectionList.contains(oldSelection[i])) {
        newSelectionList.remove(oldSelection[i]);
      } else {
        itemsToRemove.add(oldSelection[i]);
      }
    }
    doRemove(itemsToRemove);

    // add items that were not in the old selection and are in the new one
    doAdd(newSelectionList);

    pageChanged();
  }
  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 void handleSwap() {
    TableItem[] aItems = fAvailableListViewer.getTable().getItems();
    TableItem[] iItems = fImportListViewer.getTable().getItems();

    ArrayList<Object> data = new ArrayList<>();
    for (int i = 0; i < iItems.length; i++) {
      data.add(iItems[i].getData());
    }
    if (data.size() > 0) {
      doRemove(data);
    }

    data.clear();
    for (int i = 0; i < aItems.length; i++) {
      data.add(aItems[i].getData());
    }
    if (data.size() > 0) {
      doAdd(data);
    }
    pageChanged();
  }
  private void handleRemoveAll() {
    TableItem[] items = fImportListViewer.getTable().getItems();

    ArrayList<Object> data = new ArrayList<>();
    for (int i = 0; i < items.length; i++) {
      data.add(items[i].getData());
    }
    if (data.size() > 0) {
      doRemove(data);
      pageChanged(false, true);
    }
  }
  private void handleAddAll() {
    TableItem[] items = fAvailableListViewer.getTable().getItems();

    ArrayList<Object> data = new ArrayList<>();
    for (int i = 0; i < items.length; i++) {
      data.add(items[i].getData());
    }
    if (data.size() > 0) {
      doAdd(data);
      pageChanged(true, false);
    }
  }
 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 handleAddRequiredPlugins() {
    TableItem[] items = fImportListViewer.getTable().getItems();
    if (items.length == 0) return;
    if (items.length == 1) {
      IPluginModelBase model = (IPluginModelBase) items[0].getData();
      if (model.getPluginBase().getId().equals("org.eclipse.core.boot")) { // $NON-NLS-1$
        return;
      }
    }

    ArrayList<IPluginModelBase> result = new ArrayList<>();
    for (int i = 0; i < items.length; i++) {
      addPluginAndDependencies(
          (IPluginModelBase) items[i].getData(), result, fAddFragmentsButton.getSelection());
    }
    ArrayList<Object> resultObject = new ArrayList<>(result.size());
    resultObject.addAll(result);
    handleSetImportSelection(resultObject);
  }
  private void editIdMap(Shell shell) {
    TableItem[] items = fIdMapsTable.getSelection();
    if (items.length > 0) {
      IdMap idmap = (IdMap) items[0].getData();
      XMLCompareEditCopyIdMapDialog dialog =
          new XMLCompareEditCopyIdMapDialog(shell, idmap, fIdMaps, fIdMapsInternal);
      if (dialog.open() == Window.OK) {
        String new_idmapName = dialog.getResult();
        if (!fIdMaps.containsKey(new_idmapName)) {
          // copy over id mappings
          Vector newMappings = new Vector();
          IdMap newIdMap = new IdMap(new_idmapName, false, newMappings);
          HashMap newIdmapHM = new HashMap();
          fIdMaps.put(newIdMap.getName(), newIdmapHM);
          Vector Mappings = idmap.getMappings();
          for (Enumeration enumeration = Mappings.elements(); enumeration.hasMoreElements(); ) {
            Mapping mapping = (Mapping) enumeration.nextElement();
            Mapping newMapping =
                new Mapping(mapping.getElement(), mapping.getSignature(), mapping.getIdAttribute());
            newMappings.add(newMapping);
            newIdmapHM.put(newMapping.getKey(), newMapping.getIdAttribute());
          }
          // copy over ordered entries
          ArrayList orderedAL = idmap.getOrdered();
          if (orderedAL != null && orderedAL.size() > 0) {
            ArrayList newOrderedAL = new ArrayList();
            newIdMap.setOrdered(newOrderedAL);
            ArrayList idmapOrdered = new ArrayList();
            fOrderedElements.put(newIdMap.getName(), idmapOrdered);
            for (Iterator iter = orderedAL.iterator(); iter.hasNext(); ) {
              Mapping ordered = (Mapping) iter.next();
              Mapping newOrdered = new Mapping(ordered.getElement(), ordered.getSignature());
              newOrderedAL.add(newOrdered);
              idmapOrdered.add(newOrdered.getKey());
            }
          }

          newIdMapsTableItem(newIdMap, true);
          selectionChanged();
        }
      }
    }
  }
 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()]));
   }
 }