List of usage examples for com.vaadin.client.ui.dd VDragEvent getElementOver
public com.google.gwt.user.client.Element getElementOver()
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 ava2 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.accordion.VDDAccordionDropHandler.java
License:Apache License
@Override public void dragOver(VDragEvent drag) { getLayout().deEmphasis();// w ww . jav a 2 s. com getLayout().updateDragDetails(drag); getLayout().postOverHook(drag); // Validate the drop validate(new VAcceptCallback() { public void accepted(VDragEvent event) { getLayout().emphasis(event.getElementOver(), event); } }, drag); }
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 av a 2s.c om 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
/** * Updates the drop details while dragging. This is needed to ensure client * side criterias can validate the drop location. * /*w w 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.csslayout.VDDCssLayout.java
License:Apache License
public void updateDrag(VDragEvent drag) { if (placeHolderElement == null) { /*/*w w 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.formlayout.VDDFormLayoutDropHandler.java
License:Apache License
private Widget getTableRowWidgetFromDragEvent(VDragEvent event) { /**/*from ww w . j ava 2s. c om*/ * Find the widget of the row */ Element e = event.getElementOver(); if (getLayout().table.getRowCount() == 0) { /* * Empty layout */ return getLayout(); } /** * Check if element is inside one of the table widgets */ for (int i = 0; i < getLayout().table.getRowCount(); i++) { Element caption = getLayout().table.getWidget(i, getLayout().COLUMN_CAPTION).getElement(); Element error = getLayout().table.getWidget(i, getLayout().COLUMN_ERRORFLAG).getElement(); Element widget = getLayout().table.getWidget(i, getLayout().COLUMN_WIDGET).getElement(); if (caption.isOrHasChild(e) || error.isOrHasChild(e) || widget.isOrHasChild(e)) { return getLayout().table.getWidget(i, getLayout().COLUMN_WIDGET); } } /* * Is the element a element outside the row structure but inside the * layout */ Element rowElement = getLayout().getRowFromChildElement(e, getLayout().getElement()); if (rowElement != null) { Element tableElement = rowElement.getParentElement(); for (int i = 0; i < tableElement.getChildCount(); i++) { Element r = tableElement.getChild(i).cast(); if (r.equals(rowElement)) { return getLayout().table.getWidget(i, getLayout().COLUMN_WIDGET); } } } /* * Element was not found in rows so defaulting to the form layout * instead */ return getLayout(); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.horizontallayout.VDDHorizontalLayoutDropHandler.java
License:Apache License
@Override public boolean drop(VDragEvent drag) { // Un-emphasis any selections getLayout().emphasis(null, null);// ww w.java2 s . c om // Update the details Widget slot = getSlot(drag.getElementOver(), drag.getCurrentGwtEvent()); getLayout().updateDragDetails(slot, drag); return getLayout().postDropHook(drag) && super.drop(drag); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.horizontallayout.VDDHorizontalLayoutDropHandler.java
License:Apache License
@Override public void dragOver(VDragEvent drag) { // Remove any emphasis getLayout().emphasis(null, null);//from w ww . ja v a 2 s. co m Slot slot = getSlot(drag.getElementOver(), drag.getCurrentGwtEvent()); if (slot != null) { getLayout().updateDragDetails(slot, drag); } else { getLayout().updateDragDetails(getLayout(), drag); } getLayout().postOverHook(drag); // Validate the drop validate(new VAcceptCallback() { public void accepted(VDragEvent event) { Slot slot = getSlot(event.getElementOver(), event.getCurrentGwtEvent()); if (slot != null) { getLayout().emphasis(slot, event); } else { getLayout().emphasis(getLayout(), event); } } }, drag); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.horizontallayout.VDDHorizontalLayoutDropHandler.java
License:Apache License
@Override public void dragEnter(VDragEvent drag) { super.dragEnter(drag); Slot slot = getSlot(drag.getElementOver(), drag.getCurrentGwtEvent()); if (slot != null) { getLayout().updateDragDetails(slot, drag); } else {/*from www . j a v a2s .co m*/ getLayout().updateDragDetails(getLayout(), drag); } getLayout().postEnterHook(drag); }
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 ww w . j ava 2 s . com*/ * @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()); }