use of com.vaadin.shared.ui.dd.HorizontalDropLocation in project cuba by cuba-platform.
the class VDDCssLayout method updateDrag.
public void updateDrag(VDragEvent drag) {
if (placeHolderElement == null) {
/*
* 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);
}
use of com.vaadin.shared.ui.dd.HorizontalDropLocation in project cuba by cuba-platform.
the class VDDHorizontalSplitPanel method updateDragDetails.
/**
* Updates the drop details while dragging. This is needed to ensure client
* side criterias can validate the drop location.
*
* @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());
}
use of com.vaadin.shared.ui.dd.HorizontalDropLocation in project cuba by cuba-platform.
the class VDDTabSheet method updateDragDetails.
/**
* Updates the drop details while dragging. This is needed to ensure client
* side criterias can validate the drop location.
*
* @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());
}
}
use of com.vaadin.shared.ui.dd.HorizontalDropLocation in project cuba by cuba-platform.
the class VDDHorizontalLayout method emphasis.
/**
* Empasises the drop location of the component when hovering over a
* ĆhildComponentContainer. Passing null as the container removes any
* previous emphasis.
*
* @param container
* The container which we are hovering over
* @param event
* The drag event
*/
protected void emphasis(Widget container, VDragEvent event) {
// Remove emphasis from previous hovers
deEmphasis();
// validate container
if (container == null || !getElement().isOrHasChild(container.getElement())) {
return;
}
currentlyEmphasised = container;
HorizontalDropLocation location = null;
// Add drop location specific style
if (currentlyEmphasised != this) {
location = getHorizontalDropLocation(container, event);
} else {
location = HorizontalDropLocation.CENTER;
}
UIObject.setStyleName(currentlyEmphasised.getElement(), OVER, true);
UIObject.setStyleName(currentlyEmphasised.getElement(), OVER + "-" + location.toString().toLowerCase(), true);
}
use of com.vaadin.shared.ui.dd.HorizontalDropLocation in project cuba by cuba-platform.
the class DefaultCssLayoutDropHandler method handleHTML5Drop.
@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
CssLayoutTargetDetails details = (CssLayoutTargetDetails) event.getTargetDetails();
Component over = details.getOverComponent();
DDCssLayout layout = (DDCssLayout) details.getTarget();
int idx = (details).getOverIndex();
HorizontalDropLocation hl = details.getHorizontalDropLocation();
VerticalDropLocation vl = details.getVerticalDropLocation();
if (over == layout) {
if (vl == VerticalDropLocation.TOP || hl == HorizontalDropLocation.LEFT) {
idx = 0;
} else if (vl == VerticalDropLocation.BOTTOM || hl == HorizontalDropLocation.RIGHT) {
idx = -1;
}
} else {
if (vl == VerticalDropLocation.BOTTOM || hl == HorizontalDropLocation.RIGHT) {
idx++;
}
}
if (idx >= 0 && idx < layout.getComponentCount()) {
layout.addComponent(resolveComponentFromHTML5Drop(event), idx);
} else {
layout.addComponent(resolveComponentFromHTML5Drop(event));
}
}
Aggregations