/**
  * Recursively gets the ID of required features of this feature and adds them to the list
  *
  * @param model feature model to get requirements of
  * @param requiredFeatureList collector for the required features
  */
 private void getFeatureDependencies(
     IFeatureModel model, IFeatureModel[] allFeatures, ArrayList requiredFeatureList) {
   IFeature feature = model.getFeature();
   IFeatureImport[] featureImports = feature.getImports();
   for (int i = 0; i < featureImports.length; i++) {
     if (featureImports[i].getType() == IFeatureImport.FEATURE) {
       for (int j = 0; j < allFeatures.length; j++) {
         if (allFeatures[j].getFeature().getId().equals(featureImports[i].getId())) {
           requiredFeatureList.add(allFeatures[j]);
           getFeatureDependencies(allFeatures[j], allFeatures, requiredFeatureList);
           break;
         }
       }
     }
   }
   IFeatureChild[] featureIncludes = feature.getIncludedFeatures();
   for (int i = 0; i < featureIncludes.length; i++) {
     requiredFeatureList.add(featureIncludes[i].getId());
     for (int j = 0; j < allFeatures.length; j++) {
       if (allFeatures[j].getFeature().getId().equals(featureIncludes[i].getId())) {
         requiredFeatureList.add(allFeatures[j]);
         getFeatureDependencies(allFeatures[j], allFeatures, requiredFeatureList);
         break;
       }
     }
   }
 }
 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();
 }
  protected void handleAdd() {
    ElementListSelectionDialog dialog =
        new ElementListSelectionDialog(getShell(), new StyledBundleLabelProvider(false, false));

    try {
      dialog.setElements(getValidBundles());
    } catch (CoreException e) {
      dialog.setMessage(e.getMessage());
    }

    dialog.setTitle(PDEUIMessages.PluginSelectionDialog_title);
    dialog.setMessage(PDEUIMessages.PluginSelectionDialog_message);
    dialog.setMultipleSelection(true);
    if (dialog.open() == Window.OK) {

      Object[] models = dialog.getResult();
      ArrayList<NameVersionDescriptor> pluginsToAdd = new ArrayList<NameVersionDescriptor>();
      for (int i = 0; i < models.length; i++) {
        BundleInfo desc = ((BundleInfo) models[i]);
        pluginsToAdd.add(new NameVersionDescriptor(desc.getSymbolicName(), null));
      }
      Set<NameVersionDescriptor> allDependencies = new HashSet<NameVersionDescriptor>();
      allDependencies.addAll(pluginsToAdd);
      NameVersionDescriptor[] currentBundles = getTargetDefinition().getImplicitDependencies();
      if (currentBundles != null) {
        allDependencies.addAll(Arrays.asList(currentBundles));
      }
      getTargetDefinition()
          .setImplicitDependencies(
              allDependencies.toArray(new NameVersionDescriptor[allDependencies.size()]));
      fElementViewer.refresh();
      updateImpButtons();
    }
  }
  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);
    }
  }
  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 handleExistingProjects() {
   ArrayList<Object> result = new ArrayList<>();
   for (int i = 0; i < fModels.length; i++) {
     String id = fModels[i].getPluginBase().getId();
     IProject project = (IProject) PDEPlugin.getWorkspace().getRoot().findMember(id);
     if (project != null && project.isOpen() && WorkspaceModelManager.isPluginProject(project)) {
       result.add(fModels[i]);
     }
   }
   handleSetImportSelection(result);
 }
  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);
    }
  }
  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 addOrdered(Shell shell) {
   TableItem[] items = fIdMapsTable.getSelection();
   if (items.length > 0) {
     //			Set orderedSet= fOrderedElements.keySet();
     //			for (Iterator iter= orderedSet.iterator(); iter.hasNext(); ) {
     //				String IdMapName= (String) iter.next();
     //				ArrayList ordered= (ArrayList) fOrderedElements.get(IdMapName);
     //				for (Iterator iter2= ordered.iterator(); iter2.hasNext(); ) {
     //					System.out.println(IdMapName + ": " + iter2.next()); //$NON-NLS-1$
     //				}
     //			}
     IdMap idmap = (IdMap) items[0].getData();
     Mapping mapping = new Mapping();
     ArrayList idmapAL = (ArrayList) fOrderedElements.get(idmap.getName());
     if (idmapAL == null) idmapAL = new ArrayList();
     XMLCompareEditOrderedDialog dialog =
         new XMLCompareEditOrderedDialog(shell, mapping, idmapAL, false);
     if (dialog.open() == Window.OK) {
       String idmapALKey = mapping.getKey();
       if (!idmapAL.contains(idmapALKey)) {
         idmapAL.add(idmapALKey);
         newOrderedTableItem(mapping, true);
         ArrayList ordered = idmap.getOrdered();
         if (ordered == null) {
           ordered = new ArrayList();
           ordered.add(mapping);
           idmap.setOrdered(ordered);
         } else {
           ordered.add(mapping);
         }
         if (!fOrderedElements.containsKey(idmap.getName()))
           fOrderedElements.put(idmap.getName(), idmapAL);
       }
     }
   }
 }
 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;
 }
 protected static void setOrdered(IdMap idmap, ArrayList idmapOrdered) {
   ArrayList Ordered = new ArrayList();
   for (Iterator iter_ordered = idmapOrdered.iterator(); iter_ordered.hasNext(); ) {
     Mapping mapping = new Mapping();
     String signature = (String) iter_ordered.next();
     int end_of_signature = signature.lastIndexOf(SIGN_SEPARATOR, signature.length() - 2);
     if (end_of_signature < XMLStructureCreator.ROOT_ID.length() + 1)
       mapping.setSignature(""); // $NON-NLS-1$
     else
       mapping.setSignature(
           signature.substring(XMLStructureCreator.ROOT_ID.length() + 1, end_of_signature));
     mapping.setElement(signature.substring(end_of_signature + 1, signature.length() - 1));
     Ordered.add(mapping);
   }
   idmap.setOrdered(Ordered);
 }
 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 editOrdered(Shell shell) {
   TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
   TableItem[] itemsOrdered = fOrderedTable.getSelection();
   if (itemsOrdered.length > 0) {
     IdMap idmap = (IdMap) itemsIdMaps[0].getData();
     ArrayList idmapAL = (ArrayList) fOrderedElements.get(idmap.getName());
     Mapping mapping = (Mapping) itemsOrdered[0].getData();
     String idmapALKey = mapping.getKey();
     idmapAL.remove(idmapALKey);
     XMLCompareEditOrderedDialog dialog =
         new XMLCompareEditOrderedDialog(shell, mapping, null, true);
     if (dialog.open() == Window.OK) {
       idmapALKey = mapping.getKey();
       idmapAL.add(idmapALKey);
       fOrderedTable.remove(fOrderedTable.indexOf(itemsOrdered[0]));
       newOrderedTableItem(mapping, true);
     }
   }
 }
 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);
  }
예제 #18
0
  private ArrayList convertPkgList(ArrayList pkgList) {
    ArrayList conList = new ArrayList();
    Iterator it = pkgList.iterator();
    while (it.hasNext()) {
      CallData cd = (CallData) it.next();
      TestNode tn = null;
      if (alreadyDone.containsKey(cd)) {
        tn = (TestNode) alreadyDone.get(cd);
      } else {
        tn = new TestNode();
        tn.setData(cd.getData());
        alreadyDone.put(cd, tn);
        if (cd.getChildren().size() != 0) {
          tn.setChildren(convertPkgList(cd.getChildren()));
        }
        if (cd.getOutputs().size() != 0) {
          tn.setOutputs(convertPkgList(cd.getOutputs()));
        }
      }
      conList.add(tn);
    }

    return conList;
  }
예제 #19
0
  public void fill(Menu menu, int index) {
    final IFileRevision fileRevision = getFileRevision();
    if (fileRevision == null) {
      return;
    }

    IEditorDescriptor defaultTextEditor =
        registry.findEditor("org.eclipse.ui.DefaultTextEditor"); // $NON-NLS-1$
    IEditorDescriptor preferredEditor = Utils.getDefaultEditor(fileRevision);

    Object[] editors = Utils.getEditors(fileRevision);
    Collections.sort(Arrays.asList(editors), comparer);
    boolean defaultFound = false;

    // Check that we don't add it twice. This is possible
    // if the same editor goes to two mappings.
    ArrayList alreadyMapped = new ArrayList();

    for (int i = 0; i < editors.length; i++) {
      IEditorDescriptor editor = (IEditorDescriptor) editors[i];
      if (!alreadyMapped.contains(editor)) {
        createMenuItem(menu, editor, preferredEditor);
        if (defaultTextEditor != null && editor.getId().equals(defaultTextEditor.getId())) {
          defaultFound = true;
        }
        alreadyMapped.add(editor);
      }
    }

    // Only add a separator if there is something to separate
    if (editors.length > 0) {
      new MenuItem(menu, SWT.SEPARATOR);
    }

    // Add default editor. Check it if it is saved as the preference.
    if (!defaultFound && defaultTextEditor != null) {
      createMenuItem(menu, defaultTextEditor, preferredEditor);
    }

    // TODO : We might perhaps enable inplace and system external editors menu items
    /*// Add system editor
    IEditorDescriptor descriptor = registry
    		.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
    final MenuItem systemEditorMenuItem = createMenuItem(menu, descriptor,
    		preferredEditor);
    systemEditorMenuItem.setEnabled(false);

    // Add system in-place editor
    descriptor = registry
    		.findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID);

    final MenuItem inPlaceEditorMenuItem = (descriptor != null) ? createMenuItem(
    		menu, descriptor, preferredEditor)
    		: null;
    if (inPlaceEditorMenuItem != null)
    	inPlaceEditorMenuItem.setEnabled(false);

    Job job = new Job("updateOpenWithMenu") { //$NON-NLS-1$
    	protected IStatus run(IProgressMonitor monitor) {
    		try {
    			final boolean isFile = fileRevision.getStorage(monitor) instanceof IFile;
    			Display.getDefault().asyncExec(new Runnable() {
    				public void run() {
    					if (inPlaceEditorMenuItem != null
    							&& !inPlaceEditorMenuItem.isDisposed())
    						inPlaceEditorMenuItem.setEnabled(isFile);
    					if (!systemEditorMenuItem.isDisposed())
    						systemEditorMenuItem.setEnabled(isFile);
    				}
    			});
    			return Status.OK_STATUS;
    		} catch (CoreException e) {
    			return new Status(IStatus.WARNING, TeamUIPlugin.ID, null, e);
    		}
    	};
    };
    job.setSystem(true);
    job.schedule();*/

    createDefaultMenuItem(menu, fileRevision);

    // add Other... menu item
    createOtherMenuItem(menu);
  }