Example #1
0
  private void removeBuildPath(IResource resource, IProject project) {

    IScriptProject projrct = DLTKCore.create(project);
    IPath filePath = resource.getFullPath();

    oldBuildEntries = Arrays.asList(projrct.readRawBuildpath());

    newBuildEntries = new ArrayList<IBuildpathEntry>();

    newBuildEntries.addAll(oldBuildEntries);

    for (int i = 0; i < oldBuildEntries.size(); i++) {
      IBuildpathEntry fEntryToChange = oldBuildEntries.get(i);
      IPath entryPath = fEntryToChange.getPath();

      int mattchedPath = entryPath.matchingFirstSegments(filePath);

      if (mattchedPath == filePath.segmentCount()) {
        newBuildEntries.remove(fEntryToChange);
      } else {
        IBuildpathEntry newEntry =
            RefactoringUtility.createNewBuildpathEntry(
                fEntryToChange, fEntryToChange.getPath(), filePath, ""); // $NON-NLS-1$
        newBuildEntries.remove(fEntryToChange);
        newBuildEntries.add(newEntry);
      }
    }

    oldIncludePath = new ArrayList<IBuildpathEntry>();

    newIncludePathEntries = new ArrayList<IBuildpathEntry>();
    List<IncludePath> includePathEntries =
        Arrays.asList(IncludePathManager.getInstance().getIncludePaths(project));

    for (IncludePath entry : includePathEntries) {
      Object includePathEntry = entry.getEntry();
      IResource includeResource = null;
      if (!(includePathEntry instanceof IBuildpathEntry)) {
        includeResource = (IResource) includePathEntry;
        IPath entryPath = includeResource.getFullPath();

        IBuildpathEntry oldEntry =
            RefactoringUtility.createNewBuildpathEntry(IBuildpathEntry.BPE_SOURCE, entryPath);
        oldIncludePath.add((IBuildpathEntry) oldEntry);

        if (filePath.isPrefixOf(entryPath) || entryPath.equals(filePath)) {
        } else {
          IBuildpathEntry newEntry =
              RefactoringUtility.createNewBuildpathEntry(IBuildpathEntry.BPE_SOURCE, entryPath);
          newIncludePathEntries.add(newEntry);
        }
      } else {
        newIncludePathEntries.add((IBuildpathEntry) includePathEntry);
        oldIncludePath.add((IBuildpathEntry) includePathEntry);
      }
    }
  }
 /**
  * @param element
  * @param iBuildpathEntry
  * @return the name of the container description
  */
 private String getEntryDescription(Object element, IBuildpathEntry iBuildpathEntry) {
   IProject project = ((IncludePath) element).getProject();
   IScriptProject scriptProject = DLTKCore.create(project);
   IBuildpathContainer buildpathContainer = null;
   try {
     buildpathContainer = DLTKCore.getBuildpathContainer(iBuildpathEntry.getPath(), scriptProject);
   } catch (ModelException e) {
     // no matching container - return the path
   }
   if (buildpathContainer != null) {
     return buildpathContainer.getDescription();
   }
   return iBuildpathEntry.getPath().toOSString();
 }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.dltk.internal.ui.navigator.ScriptExplorerLabelProvider#getText
   * (java.lang.Object)
   *
   * Override the default text - do not display a full path for a folder
   */
  @Override
  public String getText(Object element) {

    if (element instanceof ExternalProjectFragment) {
      ExternalProjectFragment fragment = (ExternalProjectFragment) element;
      String name =
          LanguageModelInitializer.getPathName(
              EnvironmentPathUtils.getLocalPath(fragment.getPath()));
      if (name != null) {
        return name;
      }
      return fragment.toStringWithAncestors();
    }
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=295256
    if (element instanceof IProjectFragment) {
      IProjectFragment fragment = (IProjectFragment) element;
      return fragment.getElementName();
    }
    // end
    if (element instanceof IncludePath) {
      Object entry = ((IncludePath) element).getEntry();

      // An included PHP project
      if (entry instanceof IBuildpathEntry) {
        IBuildpathEntry iBuildpathEntry = (IBuildpathEntry) entry;
        if (iBuildpathEntry.getEntryKind() == IBuildpathEntry.BPE_PROJECT) {
          return iBuildpathEntry.getPath().lastSegment();
        }
        if (iBuildpathEntry.getEntryKind() == IBuildpathEntry.BPE_CONTAINER) {
          return getEntryDescription(element, iBuildpathEntry);
        } else {
          String result =
              LabelProviderUtil.getVariableName(
                  iBuildpathEntry.getPath(), iBuildpathEntry.getEntryKind());
          if (result == null) {
            IPath localPath = EnvironmentPathUtils.getLocalPath(iBuildpathEntry.getPath());
            return localPath.toOSString();
          }
          return result;
        }
      }
      if (entry instanceof ExternalProjectFragment) {
        return ((ExternalProjectFragment) entry).toStringWithAncestors();
      }

      if (entry instanceof IResource) {
        return (((IResource) entry).getFullPath().toString()).substring(1);
      }

      return null;
    }

    if (element != null) {
      for (ILabelProvider provider :
          TreeContentProviderRegistry.getInstance().getLabelProviders()) {
        String label = provider.getText(element);

        if (label != null) {
          return label;
        }
      }
    }

    return super.getText(element);
  }