use of com.vaadin.shared.ui.dd.HorizontalDropLocation in project cuba by cuba-platform.
the class VDDTabSheet method emphasis.
/**
* Emphasisizes a container element
*
* @param element
*/
protected void emphasis(Element element, VDragEvent event) {
boolean internalDrag = event.getTransferable().getDragSource() == this;
if (tabBar.getElement().isOrHasChild(element)) {
Widget w = Util.findWidget(element, null);
if (w == tabBar && !internalDrag) {
// Over spacer
Element spacerContent = spacer.getChild(0).cast();
spacerContent.appendChild(newTab);
currentlyEmphasised = element;
} else if (w instanceof VCaption) {
// Over a tab
HorizontalDropLocation location = VDragDropUtil.getHorizontalDropLocation(DOM.asOld(element), Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()), tabLeftRightDropRatio);
if (location == HorizontalDropLocation.LEFT) {
int index = getTabPosition(w);
if (index == 0) {
currentlyEmphasised = tabBar.getWidget(0).getElement().getFirstChildElement().cast();
currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_LEFT);
} else {
Widget prevTab = tabBar.getWidget(index - 1);
currentlyEmphasised = prevTab.getElement();
currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_RIGHT);
}
} else if (location == HorizontalDropLocation.RIGHT) {
int index = getTabPosition(w);
currentlyEmphasised = tabBar.getWidget(index).getElement();
currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_RIGHT);
} else {
int index = getTabPosition(w);
currentlyEmphasised = tabBar.getWidget(index).getElement();
currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_CENTER);
}
}
}
}
use of com.vaadin.shared.ui.dd.HorizontalDropLocation in project cuba by cuba-platform.
the class VDDGridLayout method getHorizontalDropLocation.
/**
* Returns the horizontal drop location
*
* @param cell
* The cell details
* @param event
* The drag event
* @return
*/
protected HorizontalDropLocation getHorizontalDropLocation(CellDetails cell, VDragEvent event) {
// Get the horizontal location
HorizontalDropLocation hdetail;
int x = Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()) - getAbsoluteLeft() - cell.x;
assert (x >= 0 && x <= cell.width);
if (x < cell.width * cellLeftRightDropRatio) {
hdetail = HorizontalDropLocation.LEFT;
} else if (x < cell.width * (1.0 - cellLeftRightDropRatio)) {
hdetail = HorizontalDropLocation.CENTER;
} else {
hdetail = HorizontalDropLocation.RIGHT;
}
return hdetail;
}
use of com.vaadin.shared.ui.dd.HorizontalDropLocation 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.HorizontalDropLocation 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.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;
}
setStyleName(currentlyEmphasised.getElement(), OVER, true);
setStyleName(currentlyEmphasised.getElement(), OVER + "-" + location.toString().toLowerCase(), true);
}
Aggregations