Example usage for com.vaadin.shared MouseEventDetails serialize

List of usage examples for com.vaadin.shared MouseEventDetails serialize

Introduction

In this page you can find the example usage for com.vaadin.shared MouseEventDetails serialize.

Prototype

public String serialize() 

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 ww  .  j a v  a 2  s .com

    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.accordion.VDDAccordion.java

License:Apache License

/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 * /*w ww  . j  a  v  a 2  s .c  o m*/
 * @param event
 *            The drag event
 */
protected void updateDragDetails(VDragEvent event) {
    if (event.getElementOver() == null) {
        return;
    }

    StackItem tab = WidgetUtil.findWidget(event.getElementOver(), StackItem.class);

    if (tab != null && getElement().isOrHasChild(tab.getElement())) {
        Map<String, Object> dropDetails = event.getDropDetails();

        int index = getTabPosition(tab);
        dropDetails.put(Constants.DROP_DETAIL_TO, index);

        VerticalDropLocation location = getDropLocation(tab, event);
        dropDetails.put(Constants.DROP_DETAIL_VERTICAL_DROP_LOCATION, location);

        MouseEventDetails details = MouseEventDetailsBuilder.buildMouseEventDetails(event.getCurrentGwtEvent(),
                getElement());
        dropDetails.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

/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 * /*from   ww w  . j  a v  a 2 s . c o  m*/
 * @param event
 *            The drag event
 */
protected void updateDragDetails(VDragEvent event) {

    Element over = event.getElementOver();
    if (placeHolderElement.isOrHasChild(over)) {
        // Dragging over the placeholder
        return;
    }

    Widget widget = (Widget) Util.findWidget(over, null);
    if (widget == null) {
        // Null check
        return;
    }

    int offset = 0;
    int index = -1;
    for (int i = 0; i < getElement().getChildCount(); i++) {
        Element child = getElement().getChild(i).cast();
        if (child.isOrHasChild(placeHolderElement)) {
            offset--;
        } else if (child.isOrHasChild(widget.getElement())) {
            index = i + offset;
            break;
        }
    }
    event.getDropDetails().put(Constants.DROP_DETAIL_TO, index);

    /*
     * The horizontal position within the cell
     */
    event.getDropDetails().put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION,
            getHorizontalDropLocation(widget, event));

    /*
     * The vertical position within the cell
     */
    event.getDropDetails().put(Constants.DROP_DETAIL_VERTICAL_DROP_LOCATION,
            getVerticalDropLocation(widget, event));

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

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.formlayout.VDDFormLayout.java

License:Apache License

/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 * /*w  w w .  ja  va  2  s .c o  m*/
 * @param widget
 *            The container which we are hovering over
 * @param event
 *            The drag event
 */
protected void updateDragDetails(Widget widget, VDragEvent event) {
    /*
     * The horizontal position within the cell
     */
    event.getDropDetails().put(Constants.DROP_DETAIL_VERTICAL_DROP_LOCATION, getVerticalDropLocation(
            VDDFormLayout.getRowFromChildElement(widget.getElement(), VDDFormLayout.this.getElement()), event));

    /*
     * The index over which the drag is. Can be used by a client side
     * criteria to verify that a drag is over a certain index.
     */
    event.getDropDetails().put(Constants.DROP_DETAIL_TO, "-1");
    for (int i = 0; i < table.getRowCount(); i++) {
        Widget w = table.getWidget(i, COLUMN_WIDGET);
        if (widget.equals(w)) {
            event.getDropDetails().put(Constants.DROP_DETAIL_TO, i);
        }
    }

    /*
     * Add Classname of component over the drag. This can be used by a a
     * client side criteria to verify that a drag is over a specific class
     * of component.
     */
    String className = widget.getClass().getName();
    event.getDropDetails().put(Constants.DROP_DETAIL_OVER_CLASS, className);

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

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

License:Apache License

/**
 * Updates the drop details while dragging
 * //from   ww  w.j a  v  a 2  s . c  om
 * @param event
 *            The drag event
 */
public void updateDragDetails(VDragEvent event) {
    CellDetails cd = getCellDetails(event);
    if (cd != null) {
        Map<String, Object> ddetails = event.getDropDetails();

        // Add row
        ddetails.put(Constants.DROP_DETAIL_ROW, Integer.valueOf(cd.row));

        // Add column
        ddetails.put(Constants.DROP_DETAIL_COLUMN, Integer.valueOf(cd.column));

        // Add horizontal position
        HorizontalDropLocation hl = getHorizontalDropLocation(cd, event);
        ddetails.put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION, hl);

        // Add vertical position
        VerticalDropLocation vl = getVerticalDropLocation(cd, event);
        ddetails.put(Constants.DROP_DETAIL_VERTICAL_DROP_LOCATION, vl);

        // Check if the cell we are hovering over has content
        Cell cell = getCell(cd.row, cd.column);
        ddetails.put(Constants.DROP_DETAIL_EMPTY_CELL, cell != null);

        // Get class information from child
        if (cell != null && cell.slot != null) {
            ComponentConnector child = cell.slot.getChild();
            if (child != null) {
                String className = child.getWidget().getClass().getName();
                ddetails.put(Constants.DROP_DETAIL_OVER_CLASS, className);
            } else {
                ddetails.put(Constants.DROP_DETAIL_OVER_CLASS, VDDGridLayout.this.getClass().getName());
            }
        } else {
            ddetails.put(Constants.DROP_DETAIL_OVER_CLASS, VDDGridLayout.this.getClass().getName());
        }

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

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.horizontallayout.VDDHorizontalLayout.java

License:Apache License

/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 * //from  w w  w  . ja v a2s  .  co m
 * @param widget
 *            The container which we are hovering over
 * @param event
 *            The drag event
 */
protected void updateDragDetails(Widget widget, VDragEvent event) {
    if (widget == null) {
        return;
    }

    /*
     * The horizontal position within the cell{
     */
    event.getDropDetails().put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION,
            getHorizontalDropLocation(widget, event));

    /*
     * The index over which the drag is. Can be used by a client side
     * criteria to verify that a drag is over a certain index.
     */
    int index = -1;
    if (widget instanceof Slot) {
        WidgetCollection captionsAndSlots = getChildren();
        index = VDragDropUtil.findSlotIndex(captionsAndSlots, (Slot) widget);
    }

    event.getDropDetails().put(Constants.DROP_DETAIL_TO, index);

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

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

License:Apache License

/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 * //from  w w  w  .  j  a va2  s. c o m
 * @param event
 *            The drag event
 */
protected void updateDragDetails(VDragEvent event) {
    Element over = event.getElementOver();
    if (over == null) {
        return;
    }

    // Resolve where the drop was made
    HorizontalDropLocation location = null;
    Widget content = null;
    if (firstContainer.isOrHasChild(over)) {
        location = HorizontalDropLocation.LEFT;
        content = Util.findWidget(firstContainer, null);
    } else if (splitter.isOrHasChild(over)) {
        location = HorizontalDropLocation.CENTER;
        content = this;
    } else if (secondContainer.isOrHasChild(over)) {
        location = HorizontalDropLocation.RIGHT;
        content = Util.findWidget(secondContainer, null);
    }

    event.getDropDetails().put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION, location);

    if (content != null) {
        event.getDropDetails().put(Constants.DROP_DETAIL_OVER_CLASS, content.getClass().getName());
    } else {
        event.getDropDetails().put(Constants.DROP_DETAIL_OVER_CLASS, this.getClass().getName());
    }

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

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.panel.VDDPanel.java

License:Apache License

/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 * /*from   w  w  w .  ja  va 2  s.co  m*/
 * @param event
 *            The drag event
 */
protected void updateDragDetails(VDragEvent event) {
    Element over = event.getElementOver();

    Widget content = WidgetUtil.findWidget(over, null);

    if (content != null && content != this) {
        event.getDropDetails().put(Constants.DROP_DETAIL_OVER_CLASS, content.getClass().getName());
    } else {
        event.getDropDetails().put(Constants.DROP_DETAIL_OVER_CLASS, this.getClass().getName());
    }

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

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

License:Apache License

/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 * //from   w  w w .j  a va  2 s.c o  m
 * @param event
 *            The drag event
 */
protected void updateDragDetails(VDragEvent event) {
    Element element = event.getElementOver();
    if (element == null)
        return;

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

        if (w == tabBar) {
            // Ove3r the spacer

            // Add index
            event.getDropDetails().put(Constants.DROP_DETAIL_TO, tabBar.getWidgetCount() - 1);

            // Add drop location
            event.getDropDetails().put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION,
                    HorizontalDropLocation.RIGHT);

        } else {

            // Add index
            event.getDropDetails().put(Constants.DROP_DETAIL_TO, getTabPosition(w));

            // Add drop location
            HorizontalDropLocation location = VDragDropUtil.getHorizontalDropLocation(DOM.asOld(element),
                    Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()), tabLeftRightDropRatio);
            event.getDropDetails().put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION, location);
        }

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

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.verticallayout.VDDVerticalLayout.java

License:Apache License

/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 * /*from  w  w  w . jav a  2s  . c o m*/
 * @param widget
 *            The container which we are hovering over
 * @param event
 *            The drag event
 */
protected void updateDragDetails(Widget widget, VDragEvent event) {
    if (widget == null) {
        return;
    }

    /*
     * The horizontal position within the cell{
     */
    event.getDropDetails().put(Constants.DROP_DETAIL_VERTICAL_DROP_LOCATION,
            getVerticalDropLocation(widget, event));

    /*
     * The index over which the drag is. Can be used by a client side
     * criteria to verify that a drag is over a certain index.
     */
    int index = -1;
    if (widget instanceof Slot) {
        WidgetCollection captionsAndSlots = getChildren();
        index = VDragDropUtil.findSlotIndex(captionsAndSlots, (Slot) widget);
    }

    event.getDropDetails().put(Constants.DROP_DETAIL_TO, index);

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