Example usage for com.vaadin.ui Tree setStyleName

List of usage examples for com.vaadin.ui Tree setStyleName

Introduction

In this page you can find the example usage for com.vaadin.ui Tree setStyleName.

Prototype

@Override
    public void setStyleName(String style) 

Source Link

Usage

From source file:com.wintindustries.pfserver.interfaces.view.dashboard.DashboardMenu.java

private Component buildFolderTree() {

    CssLayout treeLayout = new CssLayout();
    treeLayout.setWidth("100%");
    if (treeLayout.getComponentCount() > 0) {
        treeLayout.removeAllComponents();
    }/*  www .  j av  a2  s. c  o  m*/

    System.out.println("Init Dataasource");

    for (PFDataSource source : PFCore.core.getDataSources()) {
        System.out.println("NEW TREE");

        Label label = new Label(source.getName(), ContentMode.HTML);
        label.setPrimaryStyleName("valo-menu-subtitle");
        label.addStyleName("h4");

        label.setSizeUndefined();
        treeLayout.addComponent(label);
        //      label.setIcon(FontAwesome.LAPTOP);
        treeLayout.addStyleName("valo-menuitems");

        Tree tree = new Tree();
        //tree.setIcon(FontAwesome.LAPTOP);
        // tree.setWidth("100%");

        // container.setItemSorter(new l);

        source.Session().OpenSession();
        source.Session().getSession().beginTransaction();
        source.Session().getSession().getTransaction().setTimeout(4);

        System.out.println(": " + source.getDatabase().getSessionManager());

        Set<PFFolder> rootFolders = PFLocation.getRootDirectoriesFromDatabase(source.getDatabase());

        System.out.println(": " + source.getDatabase().getSessionManager());

        final PFFolderProxyContainer container = new PFFolderProxyContainer(rootFolders, source);

        container.setSortAlphabetic(true);
        tree.setContainerDataSource(container);
        tree.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY);
        tree.setItemCaptionPropertyId("Name");
        tree.setItemIconPropertyId("Icon");

        ItemClickListener treeclick;
        treeclick = new ItemClickListener() {

            @Override
            public void itemClick(final ItemClickEvent event) {

                //  Notification note = new Notification("Notificaton", event.getItemId().toString(), Notification.Type.ERROR_MESSAGE);
                // note.show(Page.getCurrent());
                PFFolderProxy proxyFolder = (PFFolderProxy) event.getItemId();
                MyUI.getPFNavigator().navigateTo(MyUI.PAGE_FOLDERVIEW + "/" + proxyFolder.getIdentifier());
            }
        };

        tree.addItemClickListener(treeclick);

        // Allow all nodes to have children
        //   .dashboard-menu-folder-wrapper
        // all these wrappers are a hacky workaround to a Vaadin CSS glitch
        CssLayout treeWrapper = new CssLayout();
        treeWrapper.setStyleName(".dashboard-menu-folder-wrapper");
        treeWrapper.addComponent(tree);
        treeWrapper.setWidth("40px");
        tree.setWidth("800px");
        tree.setStyleName(".dashboard-menu-folder-tree");

        treeLayout.addComponent(treeWrapper);
        source.Session().getSession().getTransaction().commit();
        source.getDatabase().getSessionManager().CloseSession();
    }

    return treeLayout;

}

From source file:org.ow2.sirocco.cloudmanager.MyUI.java

License:Open Source License

Tree createLeftMenu() {
    final Tree resourceTree = new Tree("Root");
    resourceTree.setStyleName("myTree");
    resourceTree.setImmediate(true);// w  w  w. j  av a 2 s . c  o m
    resourceTree.setSizeFull();
    resourceTree.addItem(MyUI.PROVIDERS_MENU_ITEM_ID);
    resourceTree.setItemIcon(MyUI.PROVIDERS_MENU_ITEM_ID, new ThemeResource("img/cloud.png"));
    resourceTree.setChildrenAllowed(MyUI.PROVIDERS_MENU_ITEM_ID, false);

    // resourceTree.addItem(MyUI.COMPUTE_MENU_ITEM_ID);

    resourceTree.addItem(MyUI.INSTANCES_MENU_ITEM_ID);
    resourceTree.setItemIcon(MyUI.INSTANCES_MENU_ITEM_ID, new ThemeResource("img/server.png"));
    resourceTree.setChildrenAllowed(MyUI.INSTANCES_MENU_ITEM_ID, false);
    // resourceTree.setParent(MyUI.INSTANCES_MENU_ITEM_ID, MyUI.COMPUTE_MENU_ITEM_ID);

    resourceTree.addItem(MyUI.IMAGES_MENU_ITEM_ID);
    resourceTree.setItemIcon(MyUI.IMAGES_MENU_ITEM_ID, new ThemeResource("img/image.png"));
    resourceTree.setItemCaption(MyUI.IMAGES_MENU_ITEM_ID, "  Images");
    resourceTree.setChildrenAllowed(MyUI.IMAGES_MENU_ITEM_ID, false);
    // resourceTree.setParent(MyUI.IMAGES_MENU_ITEM_ID, MyUI.COMPUTE_MENU_ITEM_ID);

    // resourceTree.addItem(MyUI.STORAGE_MENU_ITEM_ID);

    resourceTree.addItem(MyUI.VOLUMES_MENU_ITEM_ID);
    resourceTree.setItemIcon(MyUI.VOLUMES_MENU_ITEM_ID, new ThemeResource("img/disk.png"));
    resourceTree.setItemCaption(MyUI.VOLUMES_MENU_ITEM_ID, "  Volumes");
    resourceTree.setChildrenAllowed(MyUI.VOLUMES_MENU_ITEM_ID, false);
    // resourceTree.setParent(MyUI.VOLUMES_MENU_ITEM_ID, MyUI.STORAGE_MENU_ITEM_ID);

    // resourceTree.addItem(MyUI.NETWORKING_MENU_ITEM_ID);

    resourceTree.addItem(MyUI.NETWORKS_MENU_ITEM_ID);
    resourceTree.setItemIcon(MyUI.NETWORKS_MENU_ITEM_ID, new ThemeResource("img/network.png"));
    resourceTree.setChildrenAllowed(MyUI.NETWORKS_MENU_ITEM_ID, false);
    // resourceTree.setParent(MyUI.NETWORKS_MENU_ITEM_ID, MyUI.NETWORKING_MENU_ITEM_ID);

    resourceTree.addItem(MyUI.ADDRESSES_MENU_ITEM_ID);
    resourceTree.setItemIcon(MyUI.ADDRESSES_MENU_ITEM_ID, new ThemeResource("img/ip-icon.png"));
    resourceTree.setChildrenAllowed(MyUI.ADDRESSES_MENU_ITEM_ID, false);

    resourceTree.addItem(MyUI.SECURITY_GROUP_MENU_ITEM_ID);
    resourceTree.setItemIcon(MyUI.SECURITY_GROUP_MENU_ITEM_ID, new ThemeResource("img/secgroup.png"));
    resourceTree.setChildrenAllowed(MyUI.SECURITY_GROUP_MENU_ITEM_ID, false);

    // resourceTree.addItem(MyUI.SECURITY_MENU_ITEM_ID);

    resourceTree.addItem(MyUI.KEYPAIRS_MENU_ITEM_ID);
    resourceTree.setItemIcon(MyUI.KEYPAIRS_MENU_ITEM_ID, new ThemeResource("img/key.png"));
    resourceTree.setChildrenAllowed(MyUI.KEYPAIRS_MENU_ITEM_ID, false);
    // resourceTree.setParent(MyUI.KEYPAIRS_MENU_ITEM_ID, MyUI.SECURITY_MENU_ITEM_ID);

    // resourceTree.expandItemsRecursively(MyUI.COMPUTE_MENU_ITEM_ID);
    // resourceTree.expandItemsRecursively(MyUI.STORAGE_MENU_ITEM_ID);
    // resourceTree.expandItemsRecursively(MyUI.NETWORKING_MENU_ITEM_ID);
    // resourceTree.expandItemsRecursively(MyUI.SECURITY_MENU_ITEM_ID);

    resourceTree.select(MyUI.INSTANCES_MENU_ITEM_ID);

    resourceTree.addValueChangeListener(new ValueChangeListener() {
        Object previous = null;

        @Override
        public void valueChange(final ValueChangeEvent event) {
            if (resourceTree.getValue() != null) {
                if (resourceTree.hasChildren(resourceTree.getValue())) {
                    resourceTree.setValue(this.previous);
                } else {
                    this.previous = resourceTree.getValue();
                    switch ((String) resourceTree.getValue()) {
                    case PROVIDERS_MENU_ITEM_ID:
                        MyUI.this.inventoryContainer.replaceComponent(
                                MyUI.this.inventoryContainer.getComponent(0), MyUI.this.providerView);
                        break;
                    case INSTANCES_MENU_ITEM_ID:
                        MyUI.this.inventoryContainer.replaceComponent(
                                MyUI.this.inventoryContainer.getComponent(0), MyUI.this.machineView);
                        break;
                    case IMAGES_MENU_ITEM_ID:
                        MyUI.this.inventoryContainer.replaceComponent(
                                MyUI.this.inventoryContainer.getComponent(0), MyUI.this.machineImageView);
                        break;
                    case VOLUMES_MENU_ITEM_ID:
                        MyUI.this.inventoryContainer.replaceComponent(
                                MyUI.this.inventoryContainer.getComponent(0), MyUI.this.volumeView);
                        break;
                    case NETWORKS_MENU_ITEM_ID:
                        MyUI.this.inventoryContainer.replaceComponent(
                                MyUI.this.inventoryContainer.getComponent(0), MyUI.this.networkView);
                        break;
                    case ADDRESSES_MENU_ITEM_ID:
                        MyUI.this.inventoryContainer.replaceComponent(
                                MyUI.this.inventoryContainer.getComponent(0), MyUI.this.addressView);
                        break;
                    case SECURITY_GROUP_MENU_ITEM_ID:
                        MyUI.this.inventoryContainer.replaceComponent(
                                MyUI.this.inventoryContainer.getComponent(0), MyUI.this.secGroupView);
                        break;
                    case KEYPAIRS_MENU_ITEM_ID:
                        MyUI.this.inventoryContainer.replaceComponent(
                                MyUI.this.inventoryContainer.getComponent(0), MyUI.this.keyPairView);
                        break;
                    }
                }
            }
        }
    });
    return resourceTree;
}