Package com.vaadin.ui

Examples of com.vaadin.ui.Tree$ItemStyleGenerator


public class TreeDragStart extends TestBase {

    @Override
    protected void setup() {
        final Tree tree = new Tree("Inventory");

        CheckBox checkBox = new CheckBox("Enabled");
        checkBox.setImmediate(true);
        checkBox.setValue(true);
        checkBox.addListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                tree.setEnabled(!tree.isEnabled());
            }
        });
        addComponent(checkBox);
        checkBox = new CheckBox("Drag start");
        checkBox.setImmediate(true);
        checkBox.setValue(true);
        checkBox.addListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                if (((CheckBox) event.getProperty()).getValue()) {
                    tree.setDragMode(TreeDragMode.NODE);
                } else {
                    tree.setDragMode(TreeDragMode.NONE);
                }
            }
        });
        addComponent(checkBox);

        tree.setContainerDataSource(createTreeContent());
        tree.setItemCaptionMode(Tree.ITEM_CAPTION_MODE_EXPLICIT_DEFAULTS_ID);
        for (Object item : tree.getItemIds().toArray()) {
            tree.setItemCaption(item, (String) ((BeanItem<?>) item)
                    .getItemProperty("name").getValue());
        }
        getLayout().addComponent(tree);

        // Expand all items
        for (Iterator<?> it = tree.rootItemIds().iterator(); it.hasNext();) {
            tree.expandItemsRecursively(it.next());
        }

        // Set the tree in drag source mode
        tree.setDragMode(TreeDragMode.NODE);

        // Allow the tree to receive drag drops and handle them
        tree.setDropHandler(new DropHandler() {
            @Override
            public AcceptCriterion getAcceptCriterion() {
                // Accept drops in the middle of container items
                // and below and above all items.
                return new Or(Tree.TargetItemAllowsChildren.get(), new Not(
                        VerticalLocationIs.MIDDLE));
            }

            @Override
            public void drop(DragAndDropEvent event) {
                // Wrapper for the object that is dragged
                DataBoundTransferable t = (DataBoundTransferable) event
                        .getTransferable();

                TreeTargetDetails target = (TreeTargetDetails) event
                        .getTargetDetails();

                // Get ids of the dragged item and the target item
                Object sourceItemId = t.getData("itemId");
                Object targetItemId = target.getItemIdOver();

                // On which side of the target the item was dropped
                VerticalDropLocation location = target.getDropLocation();

                HierarchicalContainer container = (HierarchicalContainer) tree
                        .getContainerDataSource();

                BeanItem<?> beanItem = null;
                if (sourceItemId instanceof BeanItem<?>) {
                    beanItem = (BeanItem<?>) sourceItemId;
                } else if (sourceItemId instanceof InventoryObject) {
                    beanItem = new BeanItem<InventoryObject>(
                            (InventoryObject) sourceItemId);
                }

                // Remove the item from the source container and
                // add it to the tree's container
                Container sourceContainer = t.getSourceContainer();
                sourceContainer.removeItem(sourceItemId);
                tree.addItem(beanItem);
                InventoryObject bean = (InventoryObject) beanItem.getBean();
                tree.setChildrenAllowed(beanItem, bean.isContainer());

                // Drop right on an item -> make it a child
                if (location == VerticalDropLocation.MIDDLE) {
                    tree.setParent(beanItem, targetItemId);
                } else if (location == VerticalDropLocation.TOP) {
                    Object parentId = container.getParent(targetItemId);
                    tree.setParent(beanItem, parentId);
                    container.moveAfterSibling(beanItem, targetItemId);
                    container.moveAfterSibling(targetItemId, beanItem);
                }

                // Drop below another item -> make it next
                else if (location == VerticalDropLocation.BOTTOM) {
                    Object parentId = container.getParent(targetItemId);
                    tree.setParent(beanItem, parentId);
                    container.moveAfterSibling(beanItem, targetItemId);
                }

                tree.setItemCaption(beanItem, bean.getName());
            }
        });

        // Have a table that allows dragging from
        final Table table = new Table("Inventory List");
View Full Code Here


            } catch (final Exception e) {
                e.printStackTrace();
            }
        }

        menu = new Tree("Testables", testables);

        for (final Iterator<Class<?>> i = itemCaptions.keySet().iterator(); i
                .hasNext();) {
            final Class<?> testable = i.next();
            // simplify captions
View Full Code Here

        table.setWidth("100%");
        table.setPageLength(10);
        populateTable();
        addComponent(hl);

        tree3 = new Tree(
                "Tree with lazy loading criteria, of first server visit caches accept rules for all captions");
        tree3.setDragMode(TreeDragMode.NODE);

        tree3.addItem("Drag on me");
        tree3.addItem("Or me");
View Full Code Here

    @Override
    public void setup() {
        final Label charLabel = new Label();
        charLabel.setWidth("200px");

        Tree tree = new Tree("alphabets", getContainer());
        tree.expandItem(GREEK_ALPHABET);
        tree.addListener(new ItemClickListener() {

            private static final long serialVersionUID = 5955518276555388126L;

            @Override
            public void itemClick(ItemClickEvent event) {
                charLabel.setValue(event.getItemId().toString());
            }
        });
        tree.setImmediate(true);

        VerticalLayout panelLayout = new VerticalLayout();
        panelLayout.setMargin(true);
        Panel panel = new Panel(panelLayout);
        panelLayout.addComponent(tree);
View Full Code Here

    private Tree tree;

    @Override
    public void setup() {
        // Create the Tree,a dd to layout
        tree = new Tree("Hardware Inventory");
        addComponent(tree);

        // Contents from a (prefilled example) hierarchical container:
        tree.setContainerDataSource(getHardwareContainer());
View Full Code Here

    protected void setup() {
        addComponent(getTree());
    }

    private Tree getTree() {
        Tree tree = new Tree();
        tree.setSizeFull();
        tree.setContainerDataSource(generateHierarchicalContainer());
        tree.setImmediate(true);
        tree.addValidator(new AlwaysFailValidator("failed"));
        return tree;
    }
View Full Code Here

    @Override
    protected void setup() {
        HierarchicalContainer container = new HierarchicalContainer();
        container.addContainerProperty("name", String.class, null);
        container.addContainerProperty("icon", Resource.class, null);
        final Tree tree = new Tree();
        tree.setContainerDataSource(container);
        tree.setItemIconPropertyId("icon");
        tree.setItemCaptionPropertyId("name");

        for (int i = 0; i < 20; i++) {
            Item bar = container.addItem("bar" + i);
            bar.getItemProperty("name").setValue("Bar" + i);
            bar.getItemProperty("icon").setValue(ICON1);

            if (i > 3) {
                container.setParent("bar" + i, "bar" + (i - 1));
            }
        }

        addComponent(tree);

        Button button = new Button("Change icon", new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                tree.getItem("bar0").getItemProperty("icon").setValue(ICON2);
            }
        });

        addComponent(button);
        button = new Button("Change caption", new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                tree.getItem("bar0").getItemProperty("name").setValue("foo");
            }
        });

        addComponent(button);
View Full Code Here

    public static final String TREE_ID = "my-tree";

    @Override
    protected void setup(VaadinRequest request) {
        final Tree tree = new Tree();
        tree.setId(TREE_ID);
        tree.setSizeUndefined();

        // Add item click listener for right click selection
        tree.addItemClickListener(new ItemClickEvent.ItemClickListener() {
            @SuppressWarnings("deprecation")
            @Override
            public void itemClick(ItemClickEvent event) {
                if (event.getButton() == MouseEvents.ClickEvent.BUTTON_RIGHT) {
                    tree.select(event.getItemId());
                }
            }
        });

        // Add some items
        for (int i = 0; i < 200; i++) {
            tree.addItem(String.format("Node %s", i));
        }

        addComponent(tree);
    }
View Full Code Here

        menu.setWidth("100%");
        menu.addItem("File", null);
        menu.addItem("Edit", null);
        menu.addItem("Help", null);
        left.addComponent(menu);
        Tree tree = new Tree();
        for (int i = 0; i < 10; i++) {
            tree.addItem("Node " + i);
        }
        left.addComponent(tree);
        left.setExpandRatio(tree, 1.0f);
        Label label = new Label("Right");
        mainWindow.addComponent(label);
View Full Code Here

    private int clickCounter = 0;

    @Override
    protected void setup(VaadinRequest request) {

        Tree tree = new Tree();
        tree.setImmediate(true);

        tree.addContainerProperty("caption", String.class, "");
        for (int i = 1; i <= 2; i++) {
            String item = "Node " + i;
            tree.addItem(item);
            tree.getContainerProperty(item, "caption").setValue("Caption " + i);
            tree.setChildrenAllowed(item, false);
        }
        tree.setItemCaptionMode(Tree.ITEM_CAPTION_MODE_PROPERTY);
        tree.setItemCaptionPropertyId("caption");

        tree.addListener(new ItemClickEvent.ItemClickListener() {
            @Override
            public void itemClick(ItemClickEvent event) {
                clickCounter++;
                switch (event.getButton()) {
                case LEFT:
View Full Code Here

TOP

Related Classes of com.vaadin.ui.Tree$ItemStyleGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.