List of usage examples for com.vaadin.client.ui.dd VDragEvent getCurrentGwtEvent
public NativeEvent getCurrentGwtEvent()
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)); }//from w ww . j av a 2s . 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.absolutelayout.VDDAbsoluteLayoutDropHandler.java
License:Apache License
@Override public void dragLeave(VDragEvent drag) { super.dragLeave(drag); // Due to http://dev.vaadin.com/ticket/14880 we need to abort if gwt // event is null if (drag.getCurrentGwtEvent() != null) { getLayout().updateDragDetails(drag); getLayout().postLeaveHook(drag); }//from w w w.j ava2s . co m }
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. * /*from ww w . ja v a 2 s. c om*/ * @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.accordion.VDDAccordion.java
License:Apache License
/** * Returns the drop location of a tab//from w w w . j ava 2 s. c o m * * @param tab * The tab that was dragged * @param event * The drag event * @return */ protected VerticalDropLocation getDropLocation(StackItem tab, VDragEvent event) { VerticalDropLocation location; if (tab.isOpen()) { location = VDragDropUtil.getVerticalDropLocation(tab.getElement(), Util.getTouchOrMouseClientY(event.getCurrentGwtEvent()), tabTopBottomDropRatio); } else { location = VDragDropUtil.getVerticalDropLocation(tab.getWidget(0).getElement(), Util.getTouchOrMouseClientY(event.getCurrentGwtEvent()), tabTopBottomDropRatio); } return location; }
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. * // www . j a v a2s . c om * @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.csslayout.VDDCssLayout.java
License:Apache License
/** * Returns the horizontal location within the cell when hoovering over the * cell. By default the cell is devided into three parts: left,center,right * with the ratios 10%,80%,10%;//from ww w . j a v a 2s.c o m * * @param container * The widget container * @param event * The drag event * @return The horizontal drop location */ protected HorizontalDropLocation getHorizontalDropLocation(Widget container, VDragEvent event) { return VDragDropUtil.getHorizontalDropLocation(container.getElement(), Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()), horizontalDropRatio); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.csslayout.VDDCssLayout.java
License:Apache License
/** * Returns the horizontal location within the cell when hoovering over the * cell. By default the cell is devided into three parts: left,center,right * with the ratios 10%,80%,10%;//from www . j a v a 2 s. c om * * @param container * The widget container * @param event * The drag event * @return The horizontal drop location */ protected VerticalDropLocation getVerticalDropLocation(Widget container, VDragEvent event) { return VDragDropUtil.getVerticalDropLocation(container.getElement(), Util.getTouchOrMouseClientY(event.getCurrentGwtEvent()), verticalDropRatio); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.formlayout.VDDFormLayout.java
License:Apache License
/** * Returns the horizontal location within the cell when hoovering over the * cell. By default the cell is devided into three parts: left,center,right * with the ratios 10%,80%,10%;//from w ww .j a v a 2s . com * * @param rowElement * The row * @param event * The drag event * @return The horizontal drop location */ protected VerticalDropLocation getVerticalDropLocation(Element rowElement, VDragEvent event) { return VDragDropUtil.getVerticalDropLocation((com.google.gwt.user.client.Element) rowElement, Util.getTouchOrMouseClientY(event.getCurrentGwtEvent()), cellTopBottomDropRatio); }
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. * // ww w. j a va2s . 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 * /* w w w .ja 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()); } }