Example usage for com.vaadin.event.dd DragAndDropEvent getTransferable

List of usage examples for com.vaadin.event.dd DragAndDropEvent getTransferable

Introduction

In this page you can find the example usage for com.vaadin.event.dd DragAndDropEvent getTransferable.

Prototype

public Transferable getTransferable() 

Source Link

Usage

From source file:ch.vorburger.vaadin.beans.dragdroplayouts.NotifyingDropHandler.java

License:Apache License

@Override
public void drop(DragAndDropEvent event) {
    super.drop(event);

    // @see DefaultAbsoluteLayoutDropHandler#handleComponentReordering
    TargetDetails details = event.getTargetDetails();
    DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    Component component = transferable.getComponent();
    ComponentPosition position = layout.getPosition(component);

    assert (position.getLeftUnits() == Sizeable.UNITS_PIXELS);
    assert (position.getTopUnits() == Sizeable.UNITS_PIXELS);

    Float leftPixelPosition = position.getLeftValue();
    Float topPixelPosition = position.getTopValue();

    AbsoluteNotifyingComponentPosition absoluteComponentPosition = componentToPosition.get(component);
    if (absoluteComponentPosition != null) {
        int leftPixelPositionAsInteger = leftPixelPosition.intValue();
        int topPixelPositionAsInteger = topPixelPosition.intValue();
        absoluteComponentPosition.setLeft(leftPixelPositionAsInteger);
        absoluteComponentPosition.setTop(topPixelPositionAsInteger);
    } else {/*  w  ww  . j  a va2 s.  c  o  m*/
        logger.error(
                "Something's wrong internally... how come this component is not in my componentToPositionMap?! "
                        + component.toString());
    }
}

From source file:com.cavisson.gui.dashboard.components.controls.Tables.java

License:Apache License

static void configure(Table table, boolean footer, boolean sized, boolean expandRatios, boolean stripes,
        boolean verticalLines, boolean horizontalLines, boolean borderless, boolean headers, boolean compact,
        boolean small, boolean rowIndex, boolean rowCaption, boolean rowIcon, boolean componentsInRows) {
    table.setSelectable(true);// ww w.j  a  v a  2s  .c  o m
    table.setMultiSelect(true);
    table.setSortEnabled(true);
    table.setColumnCollapsingAllowed(true);
    table.setColumnReorderingAllowed(true);
    table.setPageLength(6);
    table.addActionHandler(ValoThemeUI.getActionHandler());
    table.setDragMode(TableDragMode.MULTIROW);
    table.setDropHandler(new DropHandler() {
        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }

        @Override
        public void drop(DragAndDropEvent event) {
            Notification.show(event.getTransferable().toString());
        }
    });
    table.setColumnAlignment(ValoThemeUI.DESCRIPTION_PROPERTY, Align.RIGHT);
    table.setColumnAlignment(ValoThemeUI.INDEX_PROPERTY, Align.CENTER);

    table.removeContainerProperty("textfield");
    table.removeGeneratedColumn("textfield");
    table.removeContainerProperty("button");
    table.removeGeneratedColumn("button");
    table.removeContainerProperty("label");
    table.removeGeneratedColumn("label");
    table.removeContainerProperty("checkbox");
    table.removeGeneratedColumn("checkbox");
    table.removeContainerProperty("datefield");
    table.removeGeneratedColumn("datefield");
    table.removeContainerProperty("combobox");
    table.removeGeneratedColumn("combobox");
    table.removeContainerProperty("optiongroup");
    table.removeGeneratedColumn("optiongroup");
    table.removeContainerProperty("slider");
    table.removeGeneratedColumn("slider");
    table.removeContainerProperty("progress");
    table.removeGeneratedColumn("progress");

    if (componentsInRows) {
        table.addContainerProperty("textfield", TextField.class, null);
        table.addGeneratedColumn("textfield", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                TextField tf = new TextField();
                tf.setInputPrompt("Type here");
                // tf.addStyleName("compact");
                if ((Integer) itemId % 2 == 0) {
                    tf.addStyleName("borderless");
                }
                return tf;
            }
        });

        table.addContainerProperty("datefield", TextField.class, null);
        table.addGeneratedColumn("datefield", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                DateField tf = new DateField();
                tf.addStyleName("compact");
                if ((Integer) itemId % 2 == 0) {
                    tf.addStyleName("borderless");
                }
                return tf;
            }
        });

        table.addContainerProperty("combobox", TextField.class, null);
        table.addGeneratedColumn("combobox", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                ComboBox tf = new ComboBox();
                tf.setInputPrompt("Select");
                tf.addStyleName("compact");
                if ((Integer) itemId % 2 == 0) {
                    tf.addStyleName("borderless");
                }
                return tf;
            }
        });

        table.addContainerProperty("button", Button.class, null);
        table.addGeneratedColumn("button", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                Button b = new Button("Button");
                b.addStyleName("small");
                return b;
            }
        });

        table.addContainerProperty("label", TextField.class, null);
        table.addGeneratedColumn("label", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                Label label = new Label("Label component");
                label.setSizeUndefined();
                label.addStyleName("bold");
                return label;
            }
        });

        table.addContainerProperty("checkbox", TextField.class, null);
        table.addGeneratedColumn("checkbox", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                CheckBox cb = new CheckBox(null, true);
                return cb;
            }
        });

        table.addContainerProperty("optiongroup", TextField.class, null);
        table.addGeneratedColumn("optiongroup", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                OptionGroup op = new OptionGroup();
                op.addItem("Male");
                op.addItem("Female");
                op.addStyleName("horizontal");
                return op;
            }
        });

        table.addContainerProperty("slider", TextField.class, null);
        table.addGeneratedColumn("slider", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                Slider s = new Slider();
                s.setValue(30.0);
                return s;
            }
        });

        table.addContainerProperty("progress", TextField.class, null);
        table.addGeneratedColumn("progress", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                ProgressBar bar = new ProgressBar();
                bar.setValue(0.7f);
                return bar;
            }
        });
    }
    table.setFooterVisible(footer);
    if (footer) {
        table.setColumnFooter(ValoThemeUI.CAPTION_PROPERTY, "caption");
        table.setColumnFooter(ValoThemeUI.DESCRIPTION_PROPERTY, "description");
        table.setColumnFooter(ValoThemeUI.ICON_PROPERTY, "icon");
        table.setColumnFooter(ValoThemeUI.INDEX_PROPERTY, "index");
    }

    if (sized) {
        table.setWidth("400px");
        table.setHeight("300px");
    } else {
        table.setSizeUndefined();
    }

    if (expandRatios) {
        if (!sized) {
            table.setWidth("100%");
        }
    }
    table.setColumnExpandRatio(ValoThemeUI.CAPTION_PROPERTY, expandRatios ? 1.0f : 0);
    table.setColumnExpandRatio(ValoThemeUI.DESCRIPTION_PROPERTY, expandRatios ? 1.0f : 0);

    if (!stripes) {
        table.addStyleName("no-stripes");
    } else {
        table.removeStyleName("no-stripes");
    }

    if (!verticalLines) {
        table.addStyleName("no-vertical-lines");
    } else {
        table.removeStyleName("no-vertical-lines");
    }

    if (!horizontalLines) {
        table.addStyleName("no-horizontal-lines");
    } else {
        table.removeStyleName("no-horizontal-lines");
    }

    if (borderless) {
        table.addStyleName("borderless");
    } else {
        table.removeStyleName("borderless");
    }

    if (!headers) {
        table.addStyleName("no-header");
    } else {
        table.removeStyleName("no-header");
    }

    if (compact) {
        table.addStyleName("compact");
    } else {
        table.removeStyleName("compact");
    }

    if (small) {
        table.addStyleName("small");
    } else {
        table.removeStyleName("small");
    }

    if (!rowIndex && !rowCaption && rowIcon) {
        table.setRowHeaderMode(RowHeaderMode.HIDDEN);
    }

    if (rowIndex) {
        table.setRowHeaderMode(RowHeaderMode.INDEX);
    }

    if (rowCaption) {
        table.setRowHeaderMode(RowHeaderMode.PROPERTY);
        table.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
    } else {
        table.setItemCaptionPropertyId(null);
    }

    if (rowIcon) {
        table.setRowHeaderMode(RowHeaderMode.ICON_ONLY);
        table.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
    } else {
        table.setItemIconPropertyId(null);
    }
}

From source file:com.etest.valo.Tables.java

License:Apache License

static void configure(Table table, boolean footer, boolean sized, boolean expandRatios, boolean stripes,
        boolean verticalLines, boolean horizontalLines, boolean borderless, boolean headers, boolean compact,
        boolean small, boolean rowIndex, boolean rowCaption, boolean rowIcon, boolean componentsInRows) {
    table.setSelectable(true);/*  w w  w  . j a va 2s.  co  m*/
    table.setMultiSelect(true);
    table.setSortEnabled(true);
    table.setColumnCollapsingAllowed(true);
    table.setColumnReorderingAllowed(true);
    table.setPageLength(6);
    table.addActionHandler(MainUI.getActionHandler());
    table.setDragMode(TableDragMode.MULTIROW);
    table.setDropHandler(new DropHandler() {
        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }

        @Override
        public void drop(DragAndDropEvent event) {
            Notification.show(event.getTransferable().toString());
        }
    });
    table.setColumnAlignment(MainUI.DESCRIPTION_PROPERTY, Align.RIGHT);
    table.setColumnAlignment(MainUI.INDEX_PROPERTY, Align.CENTER);

    table.removeContainerProperty("textfield");
    table.removeGeneratedColumn("textfield");
    table.removeContainerProperty("button");
    table.removeGeneratedColumn("button");
    table.removeContainerProperty("label");
    table.removeGeneratedColumn("label");
    table.removeContainerProperty("checkbox");
    table.removeGeneratedColumn("checkbox");
    table.removeContainerProperty("datefield");
    table.removeGeneratedColumn("datefield");
    table.removeContainerProperty("combobox");
    table.removeGeneratedColumn("combobox");
    table.removeContainerProperty("optiongroup");
    table.removeGeneratedColumn("optiongroup");
    table.removeContainerProperty("slider");
    table.removeGeneratedColumn("slider");
    table.removeContainerProperty("progress");
    table.removeGeneratedColumn("progress");

    if (componentsInRows) {
        table.addContainerProperty("textfield", TextField.class, null);
        table.addGeneratedColumn("textfield", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                TextField tf = new TextField();
                tf.setInputPrompt("Type here");
                // tf.addStyleName("compact");
                if ((Integer) itemId % 2 == 0) {
                    tf.addStyleName("borderless");
                }
                return tf;
            }
        });

        table.addContainerProperty("datefield", TextField.class, null);
        table.addGeneratedColumn("datefield", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                DateField tf = new DateField();
                tf.addStyleName("compact");
                if ((Integer) itemId % 2 == 0) {
                    tf.addStyleName("borderless");
                }
                return tf;
            }
        });

        table.addContainerProperty("combobox", TextField.class, null);
        table.addGeneratedColumn("combobox", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                ComboBox tf = new ComboBox();
                tf.setInputPrompt("Select");
                tf.addStyleName("compact");
                if ((Integer) itemId % 2 == 0) {
                    tf.addStyleName("borderless");
                }
                return tf;
            }
        });

        table.addContainerProperty("button", Button.class, null);
        table.addGeneratedColumn("button", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                Button b = new Button("Button");
                b.addStyleName("small");
                return b;
            }
        });

        table.addContainerProperty("label", TextField.class, null);
        table.addGeneratedColumn("label", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                Label label = new Label("Label component");
                label.setSizeUndefined();
                label.addStyleName("bold");
                return label;
            }
        });

        table.addContainerProperty("checkbox", TextField.class, null);
        table.addGeneratedColumn("checkbox", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                CheckBox cb = new CheckBox(null, true);
                return cb;
            }
        });

        table.addContainerProperty("optiongroup", TextField.class, null);
        table.addGeneratedColumn("optiongroup", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                OptionGroup op = new OptionGroup();
                op.addItem("Male");
                op.addItem("Female");
                op.addStyleName("horizontal");
                return op;
            }
        });

        table.addContainerProperty("slider", TextField.class, null);
        table.addGeneratedColumn("slider", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                Slider s = new Slider();
                s.setValue(30.0);
                return s;
            }
        });

        table.addContainerProperty("progress", TextField.class, null);
        table.addGeneratedColumn("progress", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                ProgressBar bar = new ProgressBar();
                bar.setValue(0.7f);
                return bar;
            }
        });
    }
    table.setFooterVisible(footer);
    if (footer) {
        table.setColumnFooter(MainUI.CAPTION_PROPERTY, "caption");
        table.setColumnFooter(MainUI.DESCRIPTION_PROPERTY, "description");
        table.setColumnFooter(MainUI.ICON_PROPERTY, "icon");
        table.setColumnFooter(MainUI.INDEX_PROPERTY, "index");
    }

    if (sized) {
        table.setWidth("400px");
        table.setHeight("300px");
    } else {
        table.setSizeUndefined();
    }

    if (expandRatios) {
        if (!sized) {
            table.setWidth("100%");
        }
    }
    table.setColumnExpandRatio(MainUI.CAPTION_PROPERTY, expandRatios ? 1.0f : 0);
    table.setColumnExpandRatio(MainUI.DESCRIPTION_PROPERTY, expandRatios ? 1.0f : 0);

    if (!stripes) {
        table.addStyleName("no-stripes");
    } else {
        table.removeStyleName("no-stripes");
    }

    if (!verticalLines) {
        table.addStyleName("no-vertical-lines");
    } else {
        table.removeStyleName("no-vertical-lines");
    }

    if (!horizontalLines) {
        table.addStyleName("no-horizontal-lines");
    } else {
        table.removeStyleName("no-horizontal-lines");
    }

    if (borderless) {
        table.addStyleName("borderless");
    } else {
        table.removeStyleName("borderless");
    }

    if (!headers) {
        table.addStyleName("no-header");
    } else {
        table.removeStyleName("no-header");
    }

    if (compact) {
        table.addStyleName("compact");
    } else {
        table.removeStyleName("compact");
    }

    if (small) {
        table.addStyleName("small");
    } else {
        table.removeStyleName("small");
    }

    if (!rowIndex && !rowCaption && rowIcon) {
        table.setRowHeaderMode(RowHeaderMode.HIDDEN);
    }

    if (rowIndex) {
        table.setRowHeaderMode(RowHeaderMode.INDEX);
    }

    if (rowCaption) {
        table.setRowHeaderMode(RowHeaderMode.PROPERTY);
        table.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    } else {
        table.setItemCaptionPropertyId(null);
    }

    if (rowIcon) {
        table.setRowHeaderMode(RowHeaderMode.ICON_ONLY);
        table.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    } else {
        table.setItemIconPropertyId(null);
    }
}

From source file:com.etest.valo.Trees.java

License:Apache License

public Trees() {
    setMargin(true);/* www  .j  av a  2s  .  c o  m*/

    Label h1 = new Label("Trees");
    h1.addStyleName("h1");
    addComponent(h1);

    HorizontalLayout row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    Tree tree = new Tree();
    tree.setSelectable(true);
    tree.setMultiSelect(true);
    Container generateContainer = MainUI.generateContainer(10, true);
    tree.setContainerDataSource(generateContainer);
    tree.setDragMode(TreeDragMode.NODE);
    row.addComponent(tree);
    tree.setItemCaptionPropertyId(MainUI.CAPTION_PROPERTY);
    tree.setItemIconPropertyId(MainUI.ICON_PROPERTY);
    tree.expandItem(generateContainer.getItemIds().iterator().next());

    tree.setDropHandler(new DropHandler() {
        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }

        @Override
        public void drop(DragAndDropEvent event) {
            Notification.show(event.getTransferable().toString());
        }
    });

    // Add actions (context menu)
    tree.addActionHandler(MainUI.getActionHandler());
}

From source file:com.foc.vaadin.gui.components.FVTreeDropHandler_ObjectTree.java

License:Apache License

@Override
public void drop(DragAndDropEvent dropEvent) {
    if (dropEvent.getTransferable() instanceof DataBoundTransferable) {
        DataBoundTransferable t = (DataBoundTransferable) dropEvent.getTransferable();
        if (t.getSourceContainer() instanceof ContainerOrderedWrapper) {
            ContainerOrderedWrapper source = (ContainerOrderedWrapper) t.getSourceContainer();
            Object sourceItemId = t.getItemId();
            FocObject objDroped = (FocObject) source.getItem(sourceItemId);

            AbstractSelectTargetDetails dropData = ((AbstractSelectTargetDetails) dropEvent.getTargetDetails());
            Object targetItemId = dropData.getItemIdOver();

            if (focData != null && focData instanceof FocDataMap) {
                FocDataMap focDataMap = (FocDataMap) focData;
                focData = focDataMap.getMainFocData();
            }/*from  w  w w .  j  ava  2  s  .  c o  m*/

            if (focData != null && focData instanceof FObjectTree) {
                FObjectTree objectTree = (FObjectTree) focData;
                setObjectTree(objectTree);
                if (objectTree != null) {
                    targetNode = (FObjectNode) objectTree.findNode(((Long) targetItemId).longValue());
                    sourceNode = (FObjectNode) objectTree.findNode(objDroped.getReference().getLong());

                    if (targetNode != null && sourceNode != null && focXMLLayout != null) {

                        XMLViewKey xmlViewKey = new XMLViewKey(AdminWebModule.OPTION_WINDOW_STORAGE,
                                XMLViewKey.TYPE_FORM);
                        OptionDialog_Form optionDialogForm = (OptionDialog_Form) XMLViewDictionary.getInstance()
                                .newCentralPanel(focXMLLayout.getMainWindow(), xmlViewKey, null);

                        setOptionDialog_Form(optionDialogForm);

                        ClickListener clickListener = new ClickListener() {

                            @Override
                            public void buttonClick(ClickEvent event) {
                                FocObject targetObject = (FocObject) targetNode.getObject();
                                FocObject sourceObject = (FocObject) sourceNode.getObject();

                                boolean shouldExecute = (sourceObject != null && sourceObject != targetObject)
                                        && (!sourceNode.isAncestorOf(targetNode));

                                if (shouldExecute && getObjectTree() != null) {

                                    sourceObject.setPropertyObject(getObjectTree().getFatherNodeId(),
                                            targetObject);
                                    sourceNode.moveTo(targetNode);

                                    FVTableWrapperLayout bkdnTreeWrapper = (FVTableWrapperLayout) focXMLLayout
                                            .getComponentByName(treeName);
                                    if (bkdnTreeWrapper != null) {
                                        FVTreeTable treeTable = ((FVTreeTable) bkdnTreeWrapper
                                                .getTableOrTree());
                                        if (treeTable != null && treeTable instanceof FVTreeTable) {
                                            getOptionDialog_Form().goBack(null);
                                            treeTable.markAsDirty();
                                            treeTable.refreshRowCache_Foc();
                                            focXMLLayout.refresh();
                                        }
                                    }
                                }
                            }
                        };

                        optionDialogForm.addButton("Confirm node move", clickListener);

                        clickListener = new ClickListener() {

                            @Override
                            public void buttonClick(ClickEvent event) {
                                getOptionDialog_Form().goBack(null);
                            }

                        };
                        optionDialogForm.addButton("Cancel", clickListener);

                        FocCentralPanel centralPanel = new FocCentralPanel();
                        centralPanel.fill();
                        centralPanel.changeCentralPanelContent(getOptionDialog_Form(), false);
                        Window optionWindow = centralPanel.newWrapperWindow();
                        optionWindow.setCaption("Node Move Confirmation");
                        optionWindow.setWidth("400px");
                        optionWindow.setHeight("200px");
                        focXMLLayout.getUI().addWindow(optionWindow);
                    }
                }
            }
        }
    }
}

From source file:com.foc.vaadin.gui.components.tableAndTree.FVTableDropHandler.java

License:Apache License

public FocObject getSourceFocObject(DragAndDropEvent dropEvent) {
    FocObject sourceObj = null;//  w w  w. ja  va 2s  . co m
    if (dropEvent != null && dropEvent.getTransferable() instanceof DataBoundTransferable) {
        DataBoundTransferable transferable = (DataBoundTransferable) dropEvent.getTransferable();
        if (transferable != null && transferable.getSourceContainer() instanceof Container) {
            Container container = (Container) transferable.getSourceContainer();
            if (container != null) {
                Object sourceItemId = transferable.getItemId();
                sourceObj = (FocObject) container.getItem(sourceItemId);
            }
        }
    }
    return sourceObj;
}

From source file:com.foc.vaadin.gui.components.tableAndTree.FVTableDropHandler.java

License:Apache License

public FocObject getTargetFocObject(DragAndDropEvent dropEvent) {
    FocObject targetObject = null;// ww  w .  j a v  a  2  s  .  c  o m
    if (dropEvent != null && dropEvent.getTransferable() instanceof DataBoundTransferable) {
        AbstractSelectTargetDetails dropData = ((AbstractSelectTargetDetails) dropEvent.getTargetDetails());
        Object targetItemId = dropData.getItemIdOver();
        if (targetItemId != null) {
            targetObject = getFocList() != null ? getFocList().searchByReference((Long) targetItemId) : null;
        }
    }
    return targetObject;
}

From source file:com.foc.vaadin.gui.layouts.FVAbsoulte_WYSIWYG_DropHandler.java

License:Apache License

/**
 * Called when a component changed location within the layout
 * //from   www. j a v  a 2s  .  c o  m
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event.getTargetDetails();
    DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    Component component = transferable.getComponent();

    // Get top-left pixel position
    int leftPixelPosition = details.getRelativeLeft();
    int topPixelPosition = details.getRelativeTop();

    ComponentPosition position = layout.getPosition(component);

    position.setLeft((float) leftPixelPosition, com.vaadin.server.Sizeable.Unit.PIXELS);
    position.setTop((float) topPixelPosition, com.vaadin.server.Sizeable.Unit.PIXELS);

    AttributesImpl newAttributes = new AttributesImpl(((FocXMLGuiComponent) component).getAttributes());
    newAttributes.setValue(newAttributes.getIndex(FXML.ATT_LEFT), leftPixelPosition + "px");
    newAttributes.setValue(newAttributes.getIndex(FXML.ATT_TOP), topPixelPosition + "px");
    ((FocXMLGuiComponent) component).setAttributes(newAttributes);

    if (component instanceof FVLayout) {
        ((FVLayout) component).setDragDrop(true);
    }
}

From source file:com.foc.vaadin.gui.layouts.FVAbsoulte_WYSIWYG_DropHandler.java

License:Apache License

/**
 * Handle a drop from another layout/*from  w ww  . j  av a2  s  . c o  m*/
 * 
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event.getTargetDetails();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    Component component = transferable.getComponent();
    Component source = event.getTransferable().getSourceComponent();
    DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget();
    int leftPixelPosition = details.getRelativeLeft();
    int topPixelPosition = details.getRelativeTop();

    // Check that we are not dragging an outer layout into an
    // inner
    // layout
    Component parent = source.getParent();
    while (parent != null) {
        parent = parent.getParent();
    }

    ComponentContainer sourceLayout = null;

    // remove component from source
    if (source instanceof ComponentContainer) {
        sourceLayout = (ComponentContainer) source;
        sourceLayout.removeComponent(component);
    }

    AttributesImpl newAttributes = removeNotNeededAttributes(((FocXMLGuiComponent) component).getAttributes(),
            (FVLayout) sourceLayout);

    if (newAttributes.getIndex(FXML.ATT_LEFT) != -1) {
        newAttributes.setValue(newAttributes.getIndex(FXML.ATT_LEFT), leftPixelPosition + "px");
    } else {
        newAttributes.addAttribute("", FXML.ATT_LEFT, FXML.ATT_LEFT, "CDATA", leftPixelPosition + "px");
    }

    if (newAttributes.getIndex(FXML.ATT_TOP) != -1) {
        newAttributes.setValue(newAttributes.getIndex(FXML.ATT_TOP), topPixelPosition + "px");
    } else {
        newAttributes.addAttribute("", FXML.ATT_TOP, FXML.ATT_TOP, "CDATA", topPixelPosition + "px");
    }

    ((FocXMLGuiComponent) component).setAttributes(newAttributes);

    // Add component to absolute layout
    layout.addComponent(component, "left:" + leftPixelPosition + "px;top:" + topPixelPosition + "px");
}

From source file:com.foc.vaadin.gui.layouts.FVAbsoulte_WYSIWYG_DropHandler.java

License:Apache License

public void drop(DragAndDropEvent event) {
    AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event.getTargetDetails();
    DropTarget layout = details.getTarget();
    Component source = event.getTransferable().getSourceComponent();

    if (layout == source) {
        Globals.logString("Here in");
        handleComponentReordering(event);
    } else if (event.getTransferable() instanceof LayoutBoundTransferable) {
        LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
        Component comp = transferable.getComponent();

        if (comp == layout) {
            if (comp.getParent() instanceof DDAbsoluteLayout) {
                handleDropFromAbsoluteParentLayout(event);
            }//from   www.j  a va2s  .c  o  m
        } else {
            handleDropFromLayout(event);
        }
    } else if (event.getTransferable() instanceof DataBoundTransferable) {

        DataBoundTransferable t = (DataBoundTransferable) event.getTransferable();

        String name = t.getItemId() + "";

        Globals.logString("Item ID = " + t.getItemId());

        FVLayout targetLayout = (FVLayout) details.getTarget();

        FocXMLAttributes attributes = new FocXMLAttributes();
        attributes.addAttribute("", FXML.ATT_LEFT, FXML.ATT_LEFT, "CDATA", details.getRelativeLeft() + "px");
        attributes.addAttribute("", FXML.ATT_TOP, FXML.ATT_TOP, "CDATA", details.getRelativeTop() + "px");

        handleSourceContainer(t, targetLayout, name, attributes);

        Globals.logString(targetLayout.toString());
    }
}