Exemplo n.º 1
0
 public ISourceModule[] getSourceModules(WorkingCopyOwner owner) {
   ISourceModule[] workingCopies =
       ModelManager.getModelManager().getWorkingCopies(owner, false /* don't add primary */);
   if (workingCopies == null) return ModelManager.NO_WORKING_COPY;
   int length = workingCopies.length;
   ISourceModule[] result = new ISourceModule[length];
   int index = 0;
   for (int i = 0; i < length; i++) {
     ISourceModule wc = workingCopies[i];
     IResource res = wc.getResource();
     boolean valid;
     if (res != null) valid = Util.isValidSourceModule(this, res);
     else valid = Util.isValidSourceModule(this, wc.getPath());
     if (equals(wc.getParent()) && !Util.isExcluded(wc) && valid) {
       result[index++] = wc;
     }
   }
   if (index != length) {
     System.arraycopy(result, 0, result = new ISourceModule[index], 0, index);
   }
   return result;
 }
Exemplo n.º 2
0
  protected boolean buildStructure(
      OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource)
      throws ModelException {
    // check whether this folder can be opened
    if (!underlyingResource.isAccessible()) throw newNotPresentException();

    int kind = getKind();

    if (kind == IProjectFragment.K_SOURCE && Util.isExcluded(this)) throw newNotPresentException();

    // add modules from resources
    HashSet vChildren = new HashSet();
    try {
      ProjectFragment root = getProjectFragment();
      char[][] inclusionPatterns = root.fullInclusionPatternChars();
      char[][] exclusionPatterns = root.fullExclusionPatternChars();
      IResource[] members = ((IContainer) underlyingResource).members();
      for (int i = 0, max = members.length; i < max; i++) {
        IResource child = members[i];
        if (child.getType() != IResource.FOLDER
            && !Util.isExcluded(child, inclusionPatterns, exclusionPatterns)) {
          IModelElement childElement;
          if (kind == IProjectFragment.K_SOURCE && Util.isValidSourceModule(this, child)) {
            childElement = getSourceModule(child.getName());
            vChildren.add(childElement);
          }
        }
      }
    } catch (CoreException e) {
      throw new ModelException(e);
    }

    if (kind == IProjectFragment.K_SOURCE) {
      // add primary source modules
      ISourceModule[] primarySourceModules = getSourceModules(DefaultWorkingCopyOwner.PRIMARY);
      for (int i = 0, length = primarySourceModules.length; i < length; i++) {
        ISourceModule primary = primarySourceModules[i];
        vChildren.add(primary);
      }
    }

    IModelElement[] children = new IModelElement[vChildren.size()];
    vChildren.toArray(children);
    info.setChildren(children);
    return true;
  }