Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when first root Element has no children #3

Open
ssindelar opened this issue Dec 10, 2019 · 0 comments
Open

Error when first root Element has no children #3

ssindelar opened this issue Dec 10, 2019 · 0 comments

Comments

@ssindelar
Copy link

ssindelar commented Dec 10, 2019

When the first root item (lexicographically ordered) has no children (empty folder or file) than nothing is shown.

The problem is that the FilesystemDataProvider treats the first query (parent == null) as if the first root item was the parent. If this is a file or an empty folder than nothing is return. The correct way is to return the root items.

Workaround/Fix:

public class FixedFilesystemDataProvider extends FilesystemDataProvider {

	private static final long serialVersionUID = 6219944935877634942L;

	public FixedFilesystemDataProvider(FilesystemData treeData) {
		super(treeData);
	}

	@Override
	public int getChildCount(HierarchicalQuery<File, SerializablePredicate<File>> query) {
		if(query.getParentOptional().isPresent()) {
			return (int) fetchChildren(query).count();
		} else {
			return getTreeData().getRootItems().size();
		}
	}

	@Override
	public Stream<File> fetchChildren(HierarchicalQuery<File, SerializablePredicate<File>> query) {
		if (!isInMemory()) {
			Optional<File> optParent = query.getParentOptional();
			if (optParent.isPresent()) {
				File parent = optParent.get();
				if (getTreeData().getChildren(parent).isEmpty()) {
					List<File> files = ((FilesystemData) getTreeData()).getChildrenFromFilesystem(parent);
					getTreeData().addItems(parent, files);
					return files.stream();
				} else {
					return super.fetchChildren(query);
				}
			} else {
				return getTreeData().getRootItems().stream().sorted(getSortComparator());
			}
		} else {
			return super.fetchChildren(query);
		}
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant