Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.wintindustries.pfserver.interfaces.container; import com.vaadin.data.Item; import com.vaadin.data.Property; import com.vaadin.data.util.HierarchicalContainer; import com.vaadin.data.util.MethodProperty; import com.vaadin.server.FontAwesome; import com.vaadin.server.Resource; import com.wintindustries.pdffilter.PFDocument.PFFile; import com.wintindustries.pdffilter.PFLocation.PFFolder; import java.util.ArrayList; import java.util.Collection; import java.util.Set; /** * * @author Admin */ public class PFFolderContainer extends HierarchicalContainer { public PFFolderContainer() { super(); this.addContainerProperty("Name", String.class, "null"); this.addContainerProperty("Icon", Resource.class, null); this.addContainerProperty("IsFolder", Boolean.class, null); } public PFFolderContainer(PFFolder folder) { this(); recursivlyCreateTree(this, null, folder); } public PFFolderContainer(Set<PFFolder> folder) { this(); for (PFFolder f : folder) { recursivlyCreateTree(this, null, f); } } private static void recursivlyCreateTree(HierarchicalContainer container, PFFolder parent, PFFolder child) { Item childFolder = container.addItem(child); container.getContainerProperty(child, "Name").setValue(child.getName()); container.getContainerProperty(child, "Icon").setValue(FontAwesome.FOLDER); container.getContainerProperty(child, "IsFolder").setValue(true); //childFolder.addItemProperty("Name", new ObjectProperty(child.getName(), String.class)); //childFolder.addItemProperty("icon", new ObjectProperty(FontAwesome.FOLDER,Resource.class)); //childFolder.addItemProperty("name", ) // childFolder. if (parent != null) container.setParent(child, parent); container.setChildrenAllowed(child, true); // now add in files if (child.getDocuments() != null) { for (PFFile file : child.getDocuments()) { // container.addItem(file.g) } } for (PFFolder folder : child.getFolders()) { recursivlyCreateTree(container, child, folder); } } public void setSortAlphabetic(boolean Ascending) { Object[] properties = new Object[2]; properties[0] = "IsFolder"; properties[1] = "Name"; boolean[] ascending = new boolean[1]; ascending[0] = Ascending; this.sort(properties, ascending); } }