Example usage for com.vaadin.client.ui.dd VDragEvent getTransferable

List of usage examples for com.vaadin.client.ui.dd VDragEvent getTransferable

Introduction

In this page you can find the example usage for com.vaadin.client.ui.dd VDragEvent getTransferable.

Prototype

public VTransferable getTransferable() 

Source Link

Usage

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.absolutelayout.VDDAbsoluteLayout.java

License:Apache License

protected void updateDragDetails(VDragEvent drag) {

    // Get absolute coordinates
    int absoluteLeft = drag.getCurrentGwtEvent().getClientX();
    int absoluteTop = drag.getCurrentGwtEvent().getClientY();

    drag.getDropDetails().put(Constants.DROP_DETAIL_ABSOLUTE_LEFT, absoluteLeft);
    drag.getDropDetails().put(Constants.DROP_DETAIL_ABSOLUTE_TOP, absoluteTop);

    // Get relative coordinates
    int offsetLeft = 0;
    if (drag.getDragImage() != null) {
        String offsetLeftStr = drag.getDragImage().getStyle().getMarginLeft();
        offsetLeft = Integer.parseInt(offsetLeftStr.substring(0, offsetLeftStr.length() - 2));
    }//w  w  w .  ja  v a  2 s .  c  o m

    int relativeLeft = Util.getTouchOrMouseClientX(drag.getCurrentGwtEvent()) - canvas.getAbsoluteLeft()
            + offsetLeft;

    int offsetTop = 0;
    if (drag.getDragImage() != null) {
        String offsetTopStr = drag.getDragImage().getStyle().getMarginTop();
        offsetTop = Integer.parseInt(offsetTopStr.substring(0, offsetTopStr.length() - 2));
    }

    int relativeTop = Util.getTouchOrMouseClientY(drag.getCurrentGwtEvent()) - canvas.getAbsoluteTop()
            + offsetTop;

    drag.getDropDetails().put(Constants.DROP_DETAIL_RELATIVE_LEFT, relativeLeft);
    drag.getDropDetails().put(Constants.DROP_DETAIL_RELATIVE_TOP, relativeTop);

    // Get component size
    ComponentConnector widgetConnector = (ComponentConnector) drag.getTransferable()
            .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);
    if (widgetConnector != null) {
        drag.getDropDetails().put(Constants.DROP_DETAIL_COMPONENT_WIDTH,
                widgetConnector.getWidget().getOffsetWidth());
        drag.getDropDetails().put(Constants.DROP_DETAIL_COMPONENT_HEIGHT,
                widgetConnector.getWidget().getOffsetHeight());
    } else {
        drag.getDropDetails().put(Constants.DROP_DETAIL_COMPONENT_WIDTH, -1);
        drag.getDropDetails().put(Constants.DROP_DETAIL_COMPONENT_HEIGHT, -1);
    }

    // Add mouse event details
    MouseEventDetails details = MouseEventDetailsBuilder.buildMouseEventDetails(drag.getCurrentGwtEvent(),
            getElement());
    drag.getDropDetails().put(Constants.DROP_DETAIL_MOUSE_EVENT, details.serialize());
}

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.csslayout.VDDCssLayout.java

License:Apache License

private void updatePlaceHolderStyleProperties(VDragEvent drag) {
    int width = 0;
    int height = 0;
    String className = "";

    placeHolderElement.setClassName(DRAG_SHADOW_STYLE_NAME);

    ComponentConnector draggedConnector = (ComponentConnector) drag.getTransferable()
            .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);
    if (draggedConnector != null) {
        height = Util.getRequiredHeight(draggedConnector.getWidget());
        width = Util.getRequiredWidth(draggedConnector.getWidget());
        className = draggedConnector.getWidget().getElement().getClassName();
        className = className.replaceAll(VLayoutDragDropMouseHandler.ACTIVE_DRAG_SOURCE_STYLENAME, "");
        placeHolderElement.addClassName(className);
    } else if (drag.getElementOver() != getElement()) {
        width = 3;//w ww  .  j  a  v  a2  s.  c  o m
        height = drag.getElementOver().getOffsetHeight();
    }

    placeHolderElement.getStyle().setWidth(width, Unit.PX);
    placeHolderElement.getStyle().setHeight(height, Unit.PX);
}

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.csslayout.VDDCssLayout.java

License:Apache License

public void updateDrag(VDragEvent drag) {

    if (placeHolderElement == null) {
        /*/* ww w  .j  a  va 2  s  .co m*/
         * Drag image might not have been detach due to lazy attaching in
         * the DragAndDropManager. Detach it again here if it has not been
         * detached.
         */
        attachDragImageToLayout(drag);
        return;
    }

    if (drag.getElementOver().isOrHasChild(placeHolderElement)) {
        return;
    }

    if (placeHolderElement.hasParentElement()) {
        /*
         * Remove the placeholder from the DOM so we can reposition
         */
        placeHolderElement.removeFromParent();
    }

    Widget w = Util.findWidget(drag.getElementOver(), null);

    ComponentConnector draggedConnector = (ComponentConnector) drag.getTransferable()
            .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);

    if (draggedConnector != null && w == draggedConnector.getWidget()) {
        /*
         * Dragging drag image over the placeholder should not have any
         * effect (except placeholder should be removed)
         */
        return;
    }

    if (w != null && w != this) {

        HorizontalDropLocation hl = getHorizontalDropLocation(w, drag);
        VerticalDropLocation vl = getVerticalDropLocation(w, drag);

        if (hl == HorizontalDropLocation.LEFT || vl == VerticalDropLocation.TOP) {
            Element prev = w.getElement().getPreviousSibling().cast();
            if (draggedConnector == null || prev == null
                    || !draggedConnector.getWidget().getElement().isOrHasChild(prev)) {

                w.getElement().getParentElement().insertBefore(placeHolderElement, w.getElement());

            }
        } else if (hl == HorizontalDropLocation.RIGHT || vl == VerticalDropLocation.BOTTOM) {
            Element next = w.getElement().getNextSibling().cast();
            if (draggedConnector == null || next == null
                    || !draggedConnector.getWidget().getElement().isOrHasChild(next)) {
                w.getElement().getParentElement().insertAfter(placeHolderElement, w.getElement());
            }

        } else {
            Element prev = w.getElement().getPreviousSibling().cast();
            if (draggedConnector == null || prev == null
                    || !draggedConnector.getWidget().getElement().isOrHasChild(prev)) {
                w.getElement().getParentElement().insertBefore(placeHolderElement, w.getElement());
            }
        }

    } else {
        /*
         * First child or hoovering outside of current components
         */
        getElement().appendChild(placeHolderElement);
    }

    updatePlaceHolderStyleProperties(drag);
}

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.gridlayout.VDDGridLayout.java

License:Apache License

/**
 * Emphasizes a component container when user is hovering a dragged
 * component over the container.//from ww w.  j ava  2 s  . c o m
 * 
 * @param cell
 *            The container
 * @param event
 */
protected void emphasis(CellDetails cell, VDragEvent event) {

    Style shadowStyle = dragShadow.getElement().getStyle();
    shadowStyle.setPosition(Position.ABSOLUTE);
    shadowStyle.setWidth(cell.width, Unit.PX);
    shadowStyle.setHeight(cell.height, Unit.PX);
    shadowStyle.setLeft(cell.x, Unit.PX);
    shadowStyle.setTop(cell.y, Unit.PX);

    // Remove any existing empasis
    deEmphasis();

    // Ensure we are not dragging ourself into ourself
    ComponentConnector draggedConnector = (ComponentConnector) event.getTransferable()
            .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);

    if (draggedConnector != null && draggedConnector.getWidget() == VDDGridLayout.this) {
        return;
    }

    HorizontalDropLocation hl = getHorizontalDropLocation(cell, event);
    VerticalDropLocation vl = getVerticalDropLocation(cell, event);

    // Apply over style
    setStyleName(dragShadow.getElement(), OVER, true);

    // Add vertical location dependent style
    setStyleName(dragShadow.getElement(), OVER + "-" + vl.toString().toLowerCase(), true);

    // Add horizontal location dependent style
    setStyleName(dragShadow.getElement(), OVER + "-" + hl.toString().toLowerCase(), true);

}

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.horizontalsplitpanel.VDDHorizontalSplitPanelDropHandler.java

License:Apache License

@Override
public void dragOver(VDragEvent drag) {

    getLayout().deEmphasis();//  www.  j ava2  s.c o m

    getLayout().updateDragDetails(drag);

    getLayout().postOverHook(drag);

    ComponentConnector widgetConnector = (ComponentConnector) drag.getTransferable()
            .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);

    if (widgetConnector != null && getLayout().equals(widgetConnector.getWidget())) {
        return;
    }

    // Validate the drop
    validate(new VAcceptCallback() {
        public void accepted(VDragEvent event) {
            getLayout().emphasis(event.getElementOver());
        }
    }, drag);
}

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.tabsheet.VDDTabSheet.java

License:Apache License

/**
 * Emphasisizes a container element/*w  ww  . j  ava2 s . co m*/
 * 
 * @param element
 */
protected void emphasis(Element element, VDragEvent event) {

    boolean internalDrag = event.getTransferable().getDragSource() == this;

    if (tabBar.getElement().isOrHasChild(element)) {
        Widget w = Util.findWidget(element, null);

        if (w == tabBar && !internalDrag) {
            // Over spacer
            Element spacerContent = spacer.getChild(0).cast();
            spacerContent.appendChild(newTab);
            currentlyEmphasised = element;

        } else if (w instanceof VCaption) {

            // Over a tab
            HorizontalDropLocation location = VDragDropUtil.getHorizontalDropLocation(DOM.asOld(element),
                    Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()), tabLeftRightDropRatio);

            if (location == HorizontalDropLocation.LEFT) {

                int index = getTabPosition(w);

                if (index == 0) {

                    currentlyEmphasised = tabBar.getWidget(0).getElement().getFirstChildElement().cast();
                    currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_LEFT);
                } else {
                    Widget prevTab = tabBar.getWidget(index - 1);
                    currentlyEmphasised = prevTab.getElement();
                    currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_RIGHT);
                }

            } else if (location == HorizontalDropLocation.RIGHT) {
                int index = getTabPosition(w);
                currentlyEmphasised = tabBar.getWidget(index).getElement();
                currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_RIGHT);
            } else {
                int index = getTabPosition(w);
                currentlyEmphasised = tabBar.getWidget(index).getElement();
                currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_CENTER);
            }

        }
    }
}

From source file:fi.jasoft.dragdroplayouts.client.ui.gridlayout.VDDGridLayout.java

License:Apache License

/**
 * Emphasizes a component container when user is hovering a dragged
 * component over the container.//from   w ww  .j ava  2 s  . c  o m
 * 
 * @param cell
 *            The container
 * @param event
 */
protected void emphasis(CellDetails cell, VDragEvent event) {

    Style shadowStyle = dragShadow.getElement().getStyle();
    shadowStyle.setPosition(Position.ABSOLUTE);
    shadowStyle.setWidth(cell.width, Unit.PX);
    shadowStyle.setHeight(cell.height, Unit.PX);
    shadowStyle.setLeft(cell.x, Unit.PX);
    shadowStyle.setTop(cell.y, Unit.PX);

    // Remove any existing empasis
    deEmphasis();

    // Ensure we are not dragging ourself into ourself
    ComponentConnector draggedConnector = (ComponentConnector) event.getTransferable()
            .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);

    if (draggedConnector != null && draggedConnector.getWidget() == VDDGridLayout.this) {
        return;
    }

    HorizontalDropLocation hl = getHorizontalDropLocation(cell, event);
    VerticalDropLocation vl = getVerticalDropLocation(cell, event);

    // Apply over style
    UIObject.setStyleName(dragShadow.getElement(), OVER, true);

    // Add vertical location dependent style
    UIObject.setStyleName(dragShadow.getElement(), OVER + "-" + vl.toString().toLowerCase(), true);

    // Add horizontal location dependent style
    UIObject.setStyleName(dragShadow.getElement(), OVER + "-" + hl.toString().toLowerCase(), true);

}

From source file:org.eclipse.hawkbit.ui.dd.client.criteria.CriterionTestHelper.java

License:Open Source License

static VDragEvent createMockedVDragEvent(String dragSourceId, Widget widget, String theme) {
    VDragEvent dragEvent = createMockedVDragEvent(dragSourceId, widget);
    ApplicationConnection connection = Mockito.mock(ApplicationConnection.class);
    when(dragEvent.getTransferable().getDragSource().getConnection()).thenReturn(connection);
    UIConnector uiConnector = Mockito.mock(UIConnector.class);
    when(connection.getUIConnector()).thenReturn(uiConnector);
    when(uiConnector.getActiveTheme()).thenReturn(theme);

    return dragEvent;
}

From source file:org.eclipse.hawkbit.ui.dd.client.criteria.CriterionTestHelper.java

License:Open Source License

static VDragEvent createMockedVDragEvent(String dragSourceId, Widget widget) {
    com.google.gwt.user.client.Element element = Mockito.mock(com.google.gwt.user.client.Element.class);
    when(element.getId()).thenReturn(dragSourceId);
    when(widget.getElement()).thenReturn(element);
    ComponentConnector dragSource = Mockito.mock(ComponentConnector.class);
    when(dragSource.getWidget()).thenReturn(widget);
    VTransferable transferable = Mockito.mock(VTransferable.class);
    when(transferable.getDragSource()).thenReturn(dragSource);
    VDragEvent dragEvent = Mockito.mock(VDragEvent.class);
    when(dragEvent.getTransferable()).thenReturn(transferable);

    return dragEvent;
}

From source file:org.eclipse.hawkbit.ui.dd.client.criteria.ItemIdClientCriterion.java

License:Open Source License

@Override
// Exception squid:S1166 - Hide origin exception
// Exception squid:S2221 - This code is trans-coded to JavaScript, hence
// Exception semantics changes
@SuppressWarnings({ "squid:S1166", "squid:S2221" })
protected boolean accept(VDragEvent drag, UIDL configuration) {
    try {/*w  w w  .j  av a  2 s .  c o m*/

        String component = drag.getTransferable().getDragSource().getWidget().getElement().getId();
        int c = configuration.getIntAttribute(COMPONENT_COUNT);
        String mode = configuration.getStringAttribute(MODE);
        for (int dragSourceIndex = 0; dragSourceIndex < c; dragSourceIndex++) {
            String requiredPid = configuration.getStringAttribute(COMPONENT + dragSourceIndex);
            if ((STRICT_MODE.equals(mode) && component.equals(requiredPid))
                    || (PREFIX_MODE.equals(mode) && component.startsWith(requiredPid))) {
                return true;
            }

        }
    } catch (Exception e) {
        // log and continue
        LOGGER.log(Level.SEVERE, "Error verifying drop target: " + e.getLocalizedMessage());
    }
    return false;
}