use of com.vaadin.shared.ui.dd.VerticalDropLocation in project cuba by cuba-platform.
the class VDDAccordion 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) {
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());
}
}
use of com.vaadin.shared.ui.dd.VerticalDropLocation in project cuba by cuba-platform.
the class VDDAccordion method emphasis.
/**
* Emphasisizes a container element
*
* @param element
*/
protected void emphasis(Element element, VDragEvent event) {
// Find the tab
StackItem tab = WidgetUtil.findWidget(element, StackItem.class);
if (tab != null && getElement().isOrHasChild(tab.getElement()) && currentlyEmphasised != tab) {
VerticalDropLocation location = getDropLocation(tab, event);
if (location == VerticalDropLocation.MIDDLE) {
if (tab.isOpen()) {
tab.addStyleName(CLASSNAME_OVER);
} else {
tab.getWidget(0).addStyleName(CLASSNAME_OVER);
}
} else if (!spacer.isAttached()) {
if (location == VerticalDropLocation.TOP) {
insertSpacer(spacer, getElement(), getWidgetIndex(tab));
tab.setHeight((tab.getOffsetHeight() - spacer.getOffsetHeight()) + "px");
} else if (location == VerticalDropLocation.BOTTOM) {
insertSpacer(spacer, getElement(), getWidgetIndex(tab) + 1);
int newHeight = tab.getOffsetHeight() - spacer.getOffsetHeight();
if (getWidgetIndex(spacer) == getWidgetCount() - 1) {
newHeight -= spacer.getOffsetHeight();
}
if (newHeight >= 0) {
tab.setHeight(newHeight + "px");
}
}
}
currentlyEmphasised = tab;
}
}
use of com.vaadin.shared.ui.dd.VerticalDropLocation in project cuba by cuba-platform.
the class VDDGridLayout method emphasis.
/**
* Emphasizes a component container when user is hovering a dragged
* component over the container.
*
* @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);
}
use of com.vaadin.shared.ui.dd.VerticalDropLocation in project cuba by cuba-platform.
the class VDDGridLayout method updateDragDetails.
/**
* Updates the drop details while dragging
*
* @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());
}
}
use of com.vaadin.shared.ui.dd.VerticalDropLocation in project cuba by cuba-platform.
the class DefaultCssLayoutDropHandler method handleDropFromLayout.
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
CssLayoutTargetDetails details = (CssLayoutTargetDetails) event.getTargetDetails();
DDCssLayout layout = (DDCssLayout) details.getTarget();
HorizontalDropLocation hl = details.getHorizontalDropLocation();
VerticalDropLocation vl = details.getVerticalDropLocation();
Component source = event.getTransferable().getSourceComponent();
int idx = (details).getOverIndex();
Component comp = transferable.getComponent();
Component over = details.getOverComponent();
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++;
}
}
// Check that we are not dragging an outer layout into an inner
// layout
Component parent = layout.getParent();
while (parent != null) {
if (parent == comp) {
return;
}
parent = parent.getParent();
}
// the component cannot have two parents.
if (source instanceof ComponentContainer) {
ComponentContainer sourceLayout = (ComponentContainer) source;
sourceLayout.removeComponent(comp);
}
// Add component
if (idx >= 0 && idx < layout.getComponentCount()) {
layout.addComponent(comp, idx);
} else {
layout.addComponent(comp);
}
}
Aggregations