Package com.vaadin.event

Examples of com.vaadin.event.DataBoundTransferable


                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
View Full Code Here


                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
View Full Code Here

                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) {
                    FileIcon draggedIcon = (FileIcon) dropEvent
                            .getTransferable().getSourceComponent();
                    file = draggedIcon.file;
View Full Code Here

            }

            @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");
        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
View Full Code Here

            public void drop(DragAndDropEvent event) {
                /*
                 * We know transferrable is from table, so it is of type
                 * DataBoundTransferrable
                 */
                DataBoundTransferable tr = (DataBoundTransferable) event
                        .getTransferable();
                Object itemId = tr.getItemId();
                Container sourceContainer = tr.getSourceContainer();
                if (tr.getSourceComponent() != tree1) {
                    // if the source is from table (not from tree1 itself),
                    // transfer Name property and use it as an identifier in
                    // tree1
                    Object nameValue = sourceContainer.getItem(itemId)
                            .getItemProperty("Name").getValue();
                    String name = (null != nameValue) ? nameValue.toString()
                            : null;

                    tree1.addItem(name);
                    tree1.setChildrenAllowed(name, false);

                    /*
                     * Remove the item from table
                     */
                    sourceContainer.removeItem(itemId);

                    itemId = name;

                }

                /*
                 * As we also accept only drops on folders, we know dropDetails
                 * is from Tree and it contains itemIdOver.
                 */
                AbstractSelectTargetDetails details = (AbstractSelectTargetDetails) event
                        .getTargetDetails();
                Object idOver = details.getItemIdOver();
                tree1.setParent(itemId, idOver);

            }

            @Override
            public AcceptCriterion getAcceptCriterion() {
                return and;
            }
        };
        tree1.setDropHandler(dropHandler);

        /*
         * First step done. tree1 now accepts drags only from table and only
         * over tree nodes aka "folders"
         */

        /*
         * Now set the rightmost tree accept any item drag. On drop, copy from
         * source. Also make drags from tree1 possible.
         */

        dropHandler = new DropHandler() {
            @Override
            public void drop(DragAndDropEvent event) {
                AbstractSelectTargetDetails details = (AbstractSelectTargetDetails) event
                        .getTargetDetails();
                Transferable transferable = event.getTransferable();

                if (transferable instanceof DataBoundTransferable) {
                    DataBoundTransferable tr = (DataBoundTransferable) transferable;

                    Object itemId = tree2.addItem();
                    tree2.setParent(itemId, details.getItemIdOver());
                    if (tr.getSourceComponent() == tree1) {
                        // use item id from tree1 as caption
                        tree2.setItemCaption(itemId, (String) tr.getItemId());
                        // if comes from tree1, move subtree too
                        copySubTree(tr.getItemId(), itemId);
                    } else if (tr.getSourceComponent() == table) {
                        // comes from table, override caption with name
                        String name = (String) table.getItem(tr.getItemId())
                                .getItemProperty("Name").getValue();
                        tree2.setItemCaption(itemId, name);
                    } else if (tr.getSourceComponent() == tree2) {
                        tree2.setItemCaption(itemId,
                                tree2.getItemCaption(tr.getItemId()));
                    }
                }
            }

            private void copySubTree(Object itemId, Object itemIdTo) {
View Full Code Here

            @Override
            public void drop(DragAndDropEvent dropEvent) {
                AbstractSelectTargetDetails dropTargetData = (AbstractSelectTargetDetails) dropEvent
                        .getTargetDetails();
                DataBoundTransferable transferable = (DataBoundTransferable) dropEvent
                        .getTransferable();
                Object itemIdOver = dropTargetData.getItemIdOver();
                Object itemId = transferable.getItemId();
                if (itemId == null || itemIdOver == null
                        || itemId.equals(itemIdOver)) {
                    return; // no move happened
                }
View Full Code Here

            @Override
            public void drop(DragAndDropEvent dropEvent) {
                AbstractSelectTargetDetails dropTargetData = (AbstractSelectTargetDetails) dropEvent
                        .getTargetDetails();
                DataBoundTransferable transferable = (DataBoundTransferable) dropEvent
                        .getTransferable();
                Object itemIdOver = dropTargetData.getItemIdOver();
                Object itemId = transferable.getItemId();
                if (itemId == null || itemIdOver == null
                        || itemId.equals(itemIdOver)) {
                    return; // no move happened
                }
View Full Code Here

            }

            @Override
            public void drop(DragAndDropEvent dropEvent) {
                // criteria verify that this is safe
                DataBoundTransferable t = (DataBoundTransferable) dropEvent
                        .getTransferable();
                Container sourceContainer = t.getSourceContainer();
                Object sourceItemId = t.getItemId();
                System.out.println(sourceItemId);

                AbstractSelectTargetDetails dropData = ((AbstractSelectTargetDetails) dropEvent
                        .getTargetDetails());
                Object targetItemId = dropData.getItemIdOver();
View Full Code Here

            @Override
            public void drop(DragAndDropEvent dropEvent) {
                AbstractSelectTargetDetails dropTargetData = (AbstractSelectTargetDetails) dropEvent
                        .getTargetDetails();
                DataBoundTransferable transferable = (DataBoundTransferable) dropEvent
                        .getTransferable();
                Object itemIdOver = dropTargetData.getItemIdOver();
                Object itemId = transferable.getItemId();
                if (itemId == null || itemIdOver == null
                        || itemId.equals(itemIdOver)) {
                    return; // no move happened
                }
View Full Code Here

                return AcceptAll.get();
            }

            @Override
            public void drop(DragAndDropEvent event) {
                DataBoundTransferable t = (DataBoundTransferable) event
                        .getTransferable();
                Object dragged = t.getItemId();

                AbstractSelectTargetDetails dropData = ((AbstractSelectTargetDetails) event
                        .getTargetDetails());
                Object target = dropData.getItemIdOver();
View Full Code Here

TOP

Related Classes of com.vaadin.event.DataBoundTransferable

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.