FileSystem Browser

Hello Everyone,

I have made a tree that traverses the server’s files very well. But it shows the entire path for each leaf. How can I get it to only show a folder or file name without show the full path?

Thank you
Andy

Also,

How can I make the panel that I house the tree in scroll when the contents of the tree go outside the panel?

You need to meet two conditions. First, setScrollable(true), second, the content layout must have a defined size, meaning no setSizeFull, but setSizeUndefined, so it snaps to the panel dimensions. Lastly, you could substring the path out of the files before you add them to the tree, or iterate through all the items in the container and substring them in place maybe.

The panel that the tree is housed in is set to a definite pixel size. The panel is then in another panel. So that panel needs to a have a set size?

And as for the Filesystem, yeah I have discovered that too. But it almost defeats the purpose of a container to make one only to iterate through. It will also mean I will have to remake the tree every time a file is added, which isn’t the end of the world, but isn’t ideal.

The things that can have scrollbars on my app are setSizeUndefined(), but the parents are setSizeFull().

About the substring you probably want something like this (untested code):

Iterator i = container.getItemIds().iterator();
			while(i.hasNext()){
				Object o = i.next();
				for(Iterator j = container.getContainerPropertyIds().iterator(); j.hasNext();){
					Object p = j.next();
					String temp = (String) container.getItem(o).getItemProperty(
							p).getValue();
					temp = temp.substring(temp.lastIndexOf("\\"));
					container.getItem(o).getItemProperty(
							p).setValue(temp);
				}
			}

That was very close. I thought for sure your code would work. But the FilesystemContainer is read only. Which makes since in hindsight because otherwise I would be moving my files all over the place by accident.

Sorry. I only used BeanItemContainer, since ever :grin:
EDIT: ah… and the HierarchicalContainer.

The javadoc on this container:

http://vaadin.com/api/com/vaadin/data/util/FilesystemContainer.html

But if you say it’s read-only, you can use [b]
addItem
/b, and [b]
setParent
/b, to pupulate it after getting the files with regular Java.

File abstractFilePath = new File(filePath);
ArrayList<String> pathList = new ArrayList<String>(Arrays.asList(abstractFilePath .list()));

And you have to check which is directory which is file: isDirectory() or isFile() on the File object like

new File("asdf").isDirectory()

So you have a chance before you add them to rename them.

Here’s my FilterManager through which i populate my tree control, which has a hierarchical container too:

public class FilterManager {

	public static final String FILTER_NAME = "name";
	private static final String[] filterImpactTypes = { "Passive filters",
			"Active filters" };
	private static final String[] mainFilterTypes = { "Sums", "Parities", "Numbers" };

	public static HierarchicalContainer getFilters() {
		HierarchicalContainer hc = new HierarchicalContainer();
		hc.addContainerProperty(FILTER_NAME, String.class, null);

		Item item = null;
		Integer itemId = 0;
		for (int i = 0; i < filterImpactTypes.length; i++) {
			item = hc.addItem(itemId);
			item.getItemProperty(FILTER_NAME).setValue(filterImpactTypes[i]
);
			hc.setChildrenAllowed(itemId, true);
			itemId++;
		}

		itemId = 10;
		for (int j = 0; j < mainFilterTypes.length; j++) {
			item = hc.addItem(itemId);
			item.getItemProperty(FILTER_NAME).setValue(mainFilterTypes[j]
);
			hc.setParent(itemId, 0);
			hc.setChildrenAllowed(itemId, false);
			itemId++;
		}

		return hc;
	}
}

P.S. I don’t see any constructors taking anything proper for your needs, so you’re stuck with either addItem, setParent, redo the control and recompile the widgetset. The former is faster to do probably :slight_smile: Otherwise, IDK, good luck.

Perhaps this is a very late answer. But for those who are still struggling:

FilesystemContainer filesystemContainer = new FilesystemContainer(new File("pathToDirectory"));
Tree tree = new Tree(null,filesystemContainer);
tree.setItemCaptionPropertyId(FilesystemContainer.PROPERTY_NAME);

This should make only the file/directory name visible.