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

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

Introduction

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

Prototype

public TargetDetails getTargetDetails() 

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 {/*from  w w  w .  j a v  a2s . c o  m*/
        logger.error(
                "Something's wrong internally... how come this component is not in my componentToPositionMap?! "
                        + component.toString());
    }
}

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  ww.  java2 s  .c  om*/

            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 getTargetFocObject(DragAndDropEvent dropEvent) {
    FocObject targetObject = null;//from   www .  ja va 2s. c  om
    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  w ww  .  jav a  2  s. c om*/
 * @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   www.  ja va2s.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);
            }/*  w w w .  j  a va 2  s.c  om*/
        } 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());
    }
}

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

License:Apache License

@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);
}

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

License:Apache License

/**
 * Handle a drop from another layout//from  www  .j av a2 s .  co  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();
    }

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

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

    layout.removeAllComponents();
    layout.addComponent(FVIconFactory.getInstance().getFVIcon(FVIconFactory.ICON_TRASH, false));
}

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

License:Apache License

@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    GridLayoutTargetDetails details = (GridLayoutTargetDetails) event.getTargetDetails();
    DDGridLayout layout = (DDGridLayout) details.getTarget();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();

    Component comp = transferable.getComponent();
    layout.removeComponent(comp);// ww  w . j ava  2s  . c o m

    int row = details.getOverRow();
    int column = details.getOverColumn();

    AttributesImpl newAttributes = new AttributesImpl(((FocXMLGuiComponent) comp).getAttributes());
    newAttributes.setValue(newAttributes.getIndex(FXML.ATT_COL), column + "");
    newAttributes.setValue(newAttributes.getIndex(FXML.ATT_ROW), row + "");
    ((FocXMLGuiComponent) comp).setAttributes(newAttributes);

    addComponent(event, comp, column, row);
}

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

License:Apache License

@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    GridLayoutTargetDetails details = (GridLayoutTargetDetails) event.getTargetDetails();
    DDGridLayout layout = (DDGridLayout) details.getTarget();
    Component source = event.getTransferable().getSourceComponent();
    Component comp = transferable.getComponent();

    ComponentContainer sourceLayout = null;
    if (comp != null) {
        if (comp == layout) {
            // Dropping myself on myself, if parent is absolute layout then
            // move
            if (comp.getParent() instanceof DDAbsoluteLayout) {
                MouseEventDetails mouseDown = transferable.getMouseDownEvent();
                MouseEventDetails mouseUp = details.getMouseEvent();
                int movex = mouseUp.getClientX() - mouseDown.getClientX();
                int movey = mouseUp.getClientY() - mouseDown.getClientY();

                DDAbsoluteLayout parent = (DDAbsoluteLayout) comp.getParent();
                ComponentPosition position = parent.getPosition(comp);

                sourceLayout = parent;/*from   w w w .j  a  v a  2s .c  o  m*/

                float x = position.getLeftValue() + movex;
                float y = position.getTopValue() + movey;
                position.setLeft(x, Sizeable.Unit.PIXELS);
                position.setTop(y, Sizeable.Unit.PIXELS);

                return;
            }

        } else {

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

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

        int row = details.getOverRow();
        int column = details.getOverColumn();

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

        if (newAttributes.getValue(FXML.ATT_COL) != null) {
            newAttributes.setValue(newAttributes.getIndex(FXML.ATT_COL), column + "");
        } else {
            newAttributes.addAttribute("", FXML.ATT_COL, FXML.ATT_COL, "CDATA", column + "");
        }

        if (newAttributes.getValue(FXML.ATT_ROW) != null) {
            newAttributes.setValue(newAttributes.getIndex(FXML.ATT_ROW), row + "");
        } else {
            newAttributes.addAttribute("", FXML.ATT_ROW, FXML.ATT_ROW, "CDATA", row + "");
        }

        ((FocXMLGuiComponent) comp).setAttributes(newAttributes);

        addComponent(event, comp, column, row);
    }
}