Skip to content

Instantly share code, notes, and snippets.

@torarnv
Created February 17, 2009 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torarnv/65799 to your computer and use it in GitHub Desktop.
Save torarnv/65799 to your computer and use it in GitHub Desktop.
/**
* File tree iterator that automatically adapts to a container iterator when
* recursing into directories that are accessible from the given workspace
* root.
*/
private class AdptableFileTreeIterator extends FileTreeIterator {
IWorkspaceRoot root;
public AdptableFileTreeIterator(final File path,
final IWorkspaceRoot workspaceRoot) {
super(path);
root = workspaceRoot;
}
protected AdptableFileTreeIterator(
final AdptableFileTreeIterator parent, File path,
final IWorkspaceRoot workspaceRoot) {
super(parent, path);
root = workspaceRoot;
}
@Override
public AbstractTreeIterator createSubtreeIterator(Repository repo)
throws IncorrectObjectTypeException, IOException {
File currentFile = ((FileEntry) current()).getFile();
IContainer[] containers = root.findContainersForLocation(new Path(
currentFile.getAbsolutePath()));
if (containers.length > 0)
return new ContainerTreeIterator(this, containers[0]);
else
return new AdptableFileTreeIterator(this, currentFile, root);
}
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment