/*
   * (non-Javadoc)
   *
   * @see IJavaSearchScope#encloses(IModelElement)
   */
  public boolean encloses(IModelElement element) {
    IDLTKLanguageToolkit elementToolkit = DLTKLanguageManager.getLanguageToolkit(element);
    if (!toolkit.getNatureId().equals(elementToolkit.getNatureId())) {
      return false;
    }

    if (this.elements != null) {
      for (int i = 0, length = this.elements.size(); i < length; i++) {
        IModelElement scopeElement = this.elements.get(i);
        IModelElement searchedElement = element;
        while (searchedElement != null) {
          if (searchedElement.equals(scopeElement)) return true;
          searchedElement = searchedElement.getParent();
        }
      }
      return false;
    }
    IProjectFragment root = (IProjectFragment) element.getAncestor(IModelElement.PROJECT_FRAGMENT);
    if (root != null && root.isArchive()) {
      // external or internal archive
      IPath rootPath = root.getPath();
      String rootPathToString = rootPath.toString();
      IPath relativePath = getPath(element, true /* relative path */);
      return indexOf(rootPathToString, relativePath.toString()) >= 0;
    }
    // resource in workspace
    String fullResourcePathString = getPath(element, false /* full path */).toString();
    return indexOf(fullResourcePathString) >= 0;
  }
  /* package */ void handleAffectedChildren(
      final IModelElementDelta delta,
      final IModelElement element,
      final Collection<Runnable> runnables)
      throws ModelException {
    int count = 0;

    IResourceDelta[] resourceDeltas = delta.getResourceDeltas();
    if (resourceDeltas != null) {
      for (int i = 0; i < resourceDeltas.length; i++) {
        int kind = resourceDeltas[i].getKind();
        if (kind == IResourceDelta.ADDED || kind == IResourceDelta.REMOVED) {
          count++;
        }
      }
    }
    IModelElementDelta[] affectedChildren = delta.getAffectedChildren();
    for (int i = 0; i < affectedChildren.length; i++) {
      int kind = affectedChildren[i].getKind();
      if (kind == IModelElementDelta.ADDED || kind == IModelElementDelta.REMOVED) {
        count++;
      }
    }

    if (count > 1) {
      // more than one child changed, refresh from here downwards
      if (element instanceof IScriptFolder) {
        // a package fragment might become non empty refresh from the
        // parent
        IModelElement parent = (IModelElement) internalGetParent(element);
        // 1GE8SI6: ITPJUI:WIN98 - Rename is not shown in Packages View
        // avoid posting a refresh to an invisible parent
        if (element.equals(fInput)) {
          postRefresh(element, ScriptExplorerContentProvider.ORIGINAL, element, runnables);
        } else {
          postRefresh(parent, ScriptExplorerContentProvider.PARENT, element, runnables);
        }
      } else if (element instanceof IProjectFragment) {
        Object toRefresh = internalGetParent(element);
        postRefresh(toRefresh, ScriptExplorerContentProvider.ORIGINAL, toRefresh, runnables);
      } else {
        postRefresh(element, ScriptExplorerContentProvider.ORIGINAL, element, runnables);
      }
      return;
    }
    if (resourceDeltas != null) {
      for (int i = 0; i < resourceDeltas.length; i++) {
        if (processResourceDelta(resourceDeltas[i], element, runnables)) {
          return; // early return, element got refreshed
        }
      }
    }
    for (int i = 0; i < affectedChildren.length; i++) {
      if (processDelta(affectedChildren[i], runnables)) {
        return; // early return, element got refreshed
      }
    }
  }
 /**
  * Compute if a new input must be set.
  *
  * @param elementToSelect the element to select
  * @param oldInput old input
  * @param newInput new input
  * @return <code>true</code> if the input has to be set
  * @since 3.0
  */
 private boolean mustSetNewInput(
     IModelElement elementToSelect, IModelElement oldInput, IModelElement newInput) {
   return (newInput == null || !newInput.equals(oldInput))
       && (elementToSelect == null
           || oldInput == null
           || (!((elementToSelect instanceof IPackageDeclaration)
               && (elementToSelect.getParent().equals(oldInput.getParent()))
               && (!isAncestorOf(getViewPartInput(), elementToSelect)))));
 }
Example #4
0
  /*
   * Overridden from JavaBrowsingPart to handel LogicalPackages and tree
   * structure.
   *
   * @see org.eclipse.jdt.internal.ui.browsing.JavaBrowsingPart#adjustInputAndSetSelection(org.eclipse.jdt.core.IJavaElement)
   */
  void adjustInputAndSetSelection(IModelElement je) {

    IModelElement jElementToSelect = findElementToSelect(je);
    LogicalPackagesProvider p = (LogicalPackagesProvider) fWrappedViewer.getContentProvider();

    Object elementToSelect = jElementToSelect;
    if (jElementToSelect != null
        && jElementToSelect.getElementType() == IModelElement.SCRIPT_FOLDER) {
      IScriptFolder pkgFragment = (IScriptFolder) jElementToSelect;
      elementToSelect = p.findLogicalPackage(pkgFragment);
      if (elementToSelect == null) elementToSelect = pkgFragment;
    }

    IModelElement newInput = findInputForJavaElement(je);
    if (elementToSelect == null && !isValidInput(newInput)) setInput(null);
    else if (elementToSelect == null || getViewer().testFindItem(elementToSelect) == null) {

      // optimization, if you are in the same project but expansion hasn't
      // happened
      Object input = getViewer().getInput();
      if (elementToSelect != null && newInput != null) {
        if (newInput.equals(input)) {
          getViewer().reveal(elementToSelect);
          // Adjust input to selection
        } else {
          setInput(newInput);
          getViewer().reveal(elementToSelect);
        }
      } else setInput(newInput);

      if (elementToSelect instanceof IScriptFolder) {
        IScriptFolder pkgFragment = (IScriptFolder) elementToSelect;
        elementToSelect = p.findLogicalPackage(pkgFragment);
        if (elementToSelect == null) elementToSelect = pkgFragment;
      }
    }

    ISelection selection;
    if (elementToSelect != null) selection = new StructuredSelection(elementToSelect);
    else selection = StructuredSelection.EMPTY;
    setSelection(selection, true);
  }
 private boolean internalIsAncestorOf(IModelElement ancestor, IModelElement element) {
   if (element != null)
     return element.equals(ancestor) || internalIsAncestorOf(ancestor, element.getParent());
   else return false;
 }