private CPElement removePathFromResourceGroups(CPElement element, List<CPElementGroup> groups) {
   CPElement Inherited = element.getInherited();
   CPElementGroup resGroup = element.getParent();
   resGroup.removeChild(element);
   if (Inherited != null) { // applied exclusion to orig.
     IPath exclude = element.getPath().removeFirstSegments(Inherited.getPath().segmentCount());
     IPath[] exclusions = (IPath[]) Inherited.getAttribute(CPElement.EXCLUSION);
     IPath[] newExlusions = new IPath[exclusions.length + 1];
     System.arraycopy(exclusions, 0, newExlusions, 0, exclusions.length);
     newExlusions[exclusions.length] = exclude;
     Inherited.setAttribute(CPElement.EXCLUSION, newExlusions);
     return null;
   }
   // remove all inherited
   for (int i = 0; i < groups.size(); i++) {
     CPElementGroup group = groups.get(i);
     CPElement elements[] = group.getChildren(element.getEntryKind());
     for (CPElement element2 : elements) {
       if (element2.getInherited() == element) {
         group.removeChild(element2);
         break;
       }
     }
   }
   return element;
 }
 protected void addInclude(CPElement existing) {
   InputDialog dialog;
   if (existing == null) {
     dialog =
         new SelectPathInputDialog(
             getShell(),
             CPathEntryMessages.IncludeSymbolEntryPage_addExternal_title,
             CPathEntryMessages.IncludeSymbolEntryPage_addExternal_message,
             null,
             null);
   } else {
     dialog =
         new SelectPathInputDialog(
             getShell(),
             CPathEntryMessages.IncludeSymbolEntryPage_editExternal_title,
             CPathEntryMessages.IncludeSymbolEntryPage_editExternal_message,
             ((IPath) existing.getAttribute(CPElement.INCLUDE)).toOSString(),
             null);
   }
   String newItem = null;
   if (dialog.open() == Window.OK) {
     newItem = dialog.getValue();
     if (newItem != null && !newItem.isEmpty()) {
       if (existing == null) {
         CPElementGroup group = getSelectedGroup();
         CPElement newPath =
             new CPElement(
                 fCurrCProject,
                 IPathEntry.CDT_INCLUDE,
                 group.getResource().getFullPath(),
                 group.getResource());
         newPath.setAttribute(CPElement.INCLUDE, new Path(newItem));
         if (!group.contains(newPath)) {
           addPathToResourceGroups(newPath, group, fIncludeSymPathsList.getElements());
           fIncludeSymPathsList.refresh();
           fIncludeSymPathsList.selectElements(new StructuredSelection(newPath));
         }
       } else {
         existing.setAttribute(CPElement.INCLUDE, new Path(newItem));
         updatePathOnResourceGroups(existing, fIncludeSymPathsList.getElements());
         fIncludeSymPathsList.refresh();
       }
       updateStatus();
     }
   }
 }
 private void editAttributeEntry(CPElementAttribute elem) {
   String key = elem.getKey();
   if (key.equals(CPElement.EXCLUSION)) {
     CPElement selElement = elem.getParent();
     ExclusionPatternDialog dialog = new ExclusionPatternDialog(getShell(), selElement);
     if (dialog.open() == Window.OK) {
       selElement.setAttribute(CPElement.EXCLUSION, dialog.getExclusionPattern());
       updatePathOnResourceGroups(selElement, fIncludeSymPathsList.getElements());
       fIncludeSymPathsList.refresh();
       updateStatus();
     }
   }
 }
  protected void addSymbol(CPElement existing) {
    // Popup an entry dialog
    InputDialog dialog;
    if (existing == null) {
      dialog =
          new InputDialog(
              getShell(),
              CPathEntryMessages.IncludeSymbolEntryPage_addSymbol_title,
              CPathEntryMessages.IncludeSymbolEntryPage_addSymbol_message,
              "", //$NON-NLS-1$
              null);
    } else {
      StringBuilder initialValue = new StringBuilder();
      initialValue.append((String) existing.getAttribute(CPElement.MACRO_NAME));
      initialValue.append('=');
      initialValue.append((String) existing.getAttribute(CPElement.MACRO_VALUE));
      dialog =
          new InputDialog(
              getShell(),
              CPathEntryMessages.IncludeSymbolEntryPage_editSymbol_title,
              CPathEntryMessages.IncludeSymbolEntryPage_editSymbol_message,
              initialValue.toString(),
              null);
    }

    String symbol = null;
    if (dialog.open() == Window.OK) {
      symbol = dialog.getValue();
      if (symbol != null && symbol.length() > 0) {
        CPElementGroup group = getSelectedGroup();
        CPElement newPath =
            new CPElement(
                fCurrCProject,
                IPathEntry.CDT_MACRO,
                group.getResource().getFullPath(),
                group.getResource());
        String name, value = ""; // $NON-NLS-1$
        int index = symbol.indexOf("="); // $NON-NLS-1$
        if (index != -1) {
          name = symbol.substring(0, index).trim();
          value = symbol.substring(index + 1).trim();
        } else {
          name = symbol.trim();
        }
        if (existing != null) {
          existing.setAttribute(CPElement.MACRO_NAME, name);
          existing.setAttribute(CPElement.MACRO_VALUE, value);
          updatePathOnResourceGroups(existing, fIncludeSymPathsList.getElements());
          fIncludeSymPathsList.refresh();
        } else {
          newPath.setAttribute(CPElement.MACRO_NAME, name);
          newPath.setAttribute(CPElement.MACRO_VALUE, value);
          if (!group.contains(newPath)) {
            addPathToResourceGroups(newPath, group, fIncludeSymPathsList.getElements());
            fIncludeSymPathsList.refresh();
            fIncludeSymPathsList.selectElements(new StructuredSelection(newPath));
          }
          updateStatus();
        }
      }
    }
  }