com.wintindustries.pfserver.interfaces.container.PFFolderProxyContainer.java Source code

Java tutorial

Introduction

Here is the source code for com.wintindustries.pfserver.interfaces.container.PFFolderProxyContainer.java

Source

/*
 * 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.PFData.PFDataSource;
import com.wintindustries.pdffilter.PFDocument.PFFile;
import com.wintindustries.pdffilter.PFLocation.PFFolder;
import com.wintindustries.pdffilter.pfcore.PFCore;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import org.hibernate.Hibernate;

/**
 *
 * @author Admin
 */

public class PFFolderProxyContainer extends HierarchicalContainer {

    public PFFolderProxyContainer() {
        super();
        this.addContainerProperty("Name", String.class, "null");
        this.addContainerProperty("Icon", Resource.class, null);
        this.addContainerProperty("IsFolder", Boolean.class, null);

    }

    public PFFolderProxyContainer(PFFolder folder, PFDataSource source) {
        this();
        recursivlyCreateTree(this, null, null, folder, source);
    }

    public PFFolderProxyContainer(Set<PFFolder> folder, PFDataSource source) {
        this();
        for (PFFolder f : folder) {

            recursivlyCreateTree(this, null, null, f, source);

        }
    }

    private static void recursivlyCreateTree(HierarchicalContainer container, PFFolder parent,
            PFFolderProxy parentProxy, PFFolder child, PFDataSource source) {

        System.out.println("HEARTBEAT");

        PFFolderProxy childproxy = new PFFolderProxy(child, source);
        Item childFolder = container.addItem(childproxy);
        container.getContainerProperty(childproxy, "Name").setValue(childproxy.getName());
        container.getContainerProperty(childproxy, "Icon").setValue(FontAwesome.FOLDER);
        container.getContainerProperty(childproxy, "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(childproxy, parentProxy);
        container.setChildrenAllowed(childproxy, true);

        // now add in files 

        System.out.println(source.getDatabase().getSessionManager());
        source.Session().getSession().refresh(child);
        Hibernate.initialize(child);
        if (child.getDocuments() != null) {

            System.out.println("Folder name : " + child.getName());
            for (PFFile file : child.getDocuments()) {
                //   container.addItem(file.g)
            }
        }

        for (PFFolder folder : child.getFolders()) {
            recursivlyCreateTree(container, child, childproxy, folder, source);
        }

    }

    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);
    }
}