Examples of TreeTargetDetails


Examples of com.vaadin.ui.Tree.TreeTargetDetails

            }

            @Override
            public void drop(DragAndDropEvent event) {
                TreeTargetDetails details = (TreeTargetDetails) event
                        .getTargetDetails();
                // TODO set properties, so same sorter could be used in Table
                Transferable transferable = event.getTransferable();
                if (transferable instanceof DataBoundTransferable) {
                    DataBoundTransferable transferrable2 = (DataBoundTransferable) transferable;

                    Object itemId = transferrable2.getItemId();

                    Object itemIdOver = details.getItemIdOver();

                    // TODO could use the "folder" node id to make the drop
                    // logic simpler
                    Object itemIdInto = details.getItemIdInto();
                    VerticalDropLocation dropLocation = details
                            .getDropLocation();

                    Object itemIdAfter = details.getItemIdAfter();

                    if (itemIdOver.equals(itemIdInto)) { // directly on a node
                        t.setParent(itemId, itemIdOver);
                        return;
                    }
View Full Code Here

Examples of com.vaadin.ui.Tree.TreeTargetDetails

            }

            @Override
            public void drop(DragAndDropEvent event) {
                TreeTargetDetails details = (TreeTargetDetails) event
                        .getTargetDetails();
                // TODO set properties, so same sorter could be used in Table
                Transferable transferable = event.getTransferable();
                if (transferable instanceof DataBoundTransferable) {
                    DataBoundTransferable transferrable2 = (DataBoundTransferable) transferable;

                    Object itemId = transferrable2.getItemId();

                    Object itemIdOver = details.getItemIdOver();

                    // TODO could use the "folder" node id to make the drop
                    // logic simpler
                    Object itemIdInto = details.getItemIdInto();
                    VerticalDropLocation dropLocation = details
                            .getDropLocation();

                    Object itemIdAfter = details.getItemIdAfter();

                    if (itemIdOver.equals(itemIdInto)) { // directly on a node
                        t.setParent(itemId, itemIdOver);
                        return;
                    }
View Full Code Here

Examples of com.vaadin.ui.Tree.TreeTargetDetails

            @Override
            public void drop(DragAndDropEvent dropEvent) {
                File file = null;
                Folder folder = null;
                TreeTargetDetails dropTargetData = (TreeTargetDetails) dropEvent
                        .getTargetDetails();
                folder = (Folder) dropTargetData.getItemIdInto();
                if (dropEvent.getTransferable() instanceof DataBoundTransferable) {
                    DataBoundTransferable transferable = (DataBoundTransferable) dropEvent
                            .getTransferable();
                    file = (File) transferable.getItemId();
                } else if (dropEvent.getTransferable().getSourceComponent() instanceof FileIcon) {
View Full Code Here

Examples of com.vaadin.ui.Tree.TreeTargetDetails

            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");
        table.setDragMode(TableDragMode.ROW);

        // Initialize the table container
        ArrayList<InventoryObject> collection = new ArrayList<InventoryObject>();
        collection.add(new InventoryObject("Dummy Item", 0.0, false));
        final BeanItemContainer<InventoryObject> tableContainer = new BeanItemContainer<InventoryObject>(
                collection);
        table.setContainerDataSource(tableContainer);
        table.setVisibleColumns(new String[] { "name", "weight" });
        table.removeAllItems();

        // Allow the table to receive drops and handle them
        table.setDropHandler(new DropHandler() {
            @Override
            public AcceptCriterion getAcceptCriterion() {
                return new Not(VerticalLocationIs.MIDDLE);
            }

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

                // Make sure the drag source is the same tree
                if (t.getSourceComponent() != tree
                        && t.getSourceComponent() != table) {
                    return;
                }

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

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

                // Do not allow drop on the item itself
                if (sourceItemId.equals(targetItemId)) {
                    return;
                }

                InventoryObject bean = null;
                if (sourceItemId instanceof BeanItem<?>) {
                    bean = (InventoryObject) ((BeanItem<?>) sourceItemId)
                            .getBean();
                } else if (sourceItemId instanceof InventoryObject) {
                    bean = (InventoryObject) sourceItemId;
                }

                // Remove the item from the source container
                t.getSourceContainer().removeItem(sourceItemId);

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

                // The table was empty or otherwise not on an item
                if (targetItemId == null) {
                    tableContainer.addItem(bean); // Add to the end
                } else if (location == VerticalDropLocation.TOP) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.