Java Code Examples for org.eclipse.core.resources.IContainer#accept()

The following examples show how to use org.eclipse.core.resources.IContainer#accept() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackageFilterEditor.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void setSubElementsGrayedChecked(final IContainer container, final boolean checked) {

      final List<IContainer> subContainers = new ArrayList<>();

      try {
        container.accept(new IResourceVisitor() {
          @Override
          public boolean visit(IResource resource) {
            if (!resource.equals(container) && resource instanceof IContainer) {
              subContainers.add((IContainer) resource);
            }
            return true;
          }
        });
      } catch (CoreException e) {
        CheckstyleUIPlugin.errorDialog(getShell(), e, true);
      }

      for (IContainer grayedChild : subContainers) {
        mViewer.setGrayChecked(grayedChild, checked);
      }
    }
 
Example 2
Source File: FacetUtil.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of WEB-INF folders in {@code container}.
 */
@VisibleForTesting
static List<IFolder> findAllWebInfFolders(IContainer container) {
  final List<IFolder> webInfFolders = new ArrayList<>();

  try {
    IResourceVisitor webInfCollector = new IResourceVisitor() {
      @Override
      public boolean visit(IResource resource) throws CoreException {
        if (resource.getType() == IResource.FOLDER && "WEB-INF".equals(resource.getName())) {
          webInfFolders.add((IFolder) resource);
          return false;  // No need to visit sub-directories.
        }
        return true;
      }
    };
    container.accept(webInfCollector);
  } catch (CoreException ex) {
    // Our attempt to find folders failed, but don't error out.
  }
  return webInfFolders;
}
 
Example 3
Source File: Storage2UriMapperImpl.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.4
 */
@Override
public Map<URI, IStorage> getAllEntries(IContainer container) {
	final Map<URI,IStorage> result = newLinkedHashMap();
	try {
		container.accept(new IResourceVisitor() {
			@Override
			public boolean visit(IResource resource) throws CoreException {
				if (resource instanceof IFile) {
					final IFile storage = (IFile) resource;
					URI uri = getUri(storage);
					if (uri != null)
						result.put(uri, storage);
				}
				if (resource instanceof IFolder) {
					return isHandled((IFolder)resource);
				}
				return true;
			}
		});
	} catch (CoreException e) {
		log.error(e.getMessage(), e);
	}
	return result;
}
 
Example 4
Source File: ModuleUtils.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Finds all GWT modules located directly in a particular container.
 *
 * @param container container to search within
 * @return the list of modules found
 */
public static IModule[] findChildModules(IContainer container) {
  final List<IModule> modules = new ArrayList<IModule>();

  IResourceVisitor moduleVisitor = new IResourceVisitor() {
    @Override
    public boolean visit(IResource resource) throws CoreException {
      if (resource.getType() == IResource.FILE) {
        IModule module = create((IFile) resource);
        if (module != null) {
          modules.add(module);
        }
      }
      return true;
    }
  };

  try {
    container.accept(moduleVisitor, IResource.DEPTH_ONE, false);
  } catch (CoreException e) {
    GWTPluginLog.logError(e);
  }

  return modules.toArray(new IModule[modules.size()]);
}
 
Example 5
Source File: PyFileListing.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @return All the IFiles below the current folder that are python files (does not check if it has an __init__ path)
 */
public static List<IFile> getAllIFilesBelow(IContainer member) {
    final ArrayList<IFile> ret = new ArrayList<IFile>();
    try {
        member.accept(new IResourceVisitor() {

            @Override
            public boolean visit(IResource resource) {
                if (resource instanceof IFile) {
                    ret.add((IFile) resource);
                    return false; //has no members
                }
                return true;
            }

        });
    } catch (CoreException e) {
        throw new RuntimeException(e);
    }
    return ret;
}
 
Example 6
Source File: SwaggerFileFinder.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
protected Iterable<IFile> collectFiles(IContainer parent, IFile currentFile) {
    final FileVisitor visitor = new FileVisitor(currentFile, fileContentType);

    try {
        parent.accept(visitor, 0);
    } catch (CoreException e) {
        return Arrays.asList();
    }
    return visitor.getFiles();
}