use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.
the class DefaultHorizontalSplitPanelDropHandler method handleDropFromLayout.
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
ComponentContainer source = (ComponentContainer) transferable.getSourceComponent();
HorizontalSplitPanelTargetDetails details = (HorizontalSplitPanelTargetDetails) event.getTargetDetails();
Component component = transferable.getComponent();
DDHorizontalSplitPanel panel = (DDHorizontalSplitPanel) details.getTarget();
// Detach from old source
if (source instanceof ComponentContainer) {
((ComponentContainer) source).removeComponent(component);
} else if (source instanceof SingleComponentContainer) {
((SingleComponentContainer) source).setContent(null);
}
if (details.getDropLocation() == HorizontalDropLocation.LEFT) {
// Dropped in the left area
panel.setFirstComponent(component);
} else if (details.getDropLocation() == HorizontalDropLocation.RIGHT) {
// Dropped in the right area
panel.setSecondComponent(component);
}
}
use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.
the class DefaultTabSheetDropHandler method handleComponentReordering.
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
TabSheetTargetDetails details = (TabSheetTargetDetails) event.getTargetDetails();
DDTabSheet tabSheet = (DDTabSheet) details.getTarget();
Component c = transferable.getComponent();
Tab tab = tabSheet.getTab(c);
HorizontalDropLocation location = details.getDropLocation();
int idx = details.getOverIndex();
if (location == HorizontalDropLocation.LEFT) {
// Left of previous tab
int originalIndex = tabSheet.getTabPosition(tab);
if (originalIndex > idx) {
tabSheet.setTabPosition(tab, idx);
} else if (idx - 1 >= 0) {
tabSheet.setTabPosition(tab, idx - 1);
}
} else if (location == HorizontalDropLocation.RIGHT) {
// Right of previous tab
int originalIndex = tabSheet.getTabPosition(tab);
if (originalIndex > idx) {
tabSheet.setTabPosition(tab, idx + 1);
} else {
tabSheet.setTabPosition(tab, idx);
}
}
}
use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.
the class DefaultAbsoluteLayoutDropHandler method handleComponentReordering.
/**
* Called when a component changed location within the layout
*
* @param event
* The drag and drop event
*/
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event.getTargetDetails();
DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget();
LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
Component component = transferable.getComponent();
// Get top-left pixel position
int leftPixelPosition = details.getRelativeLeft();
int topPixelPosition = details.getRelativeTop();
ComponentPosition position = layout.getPosition(component);
position.setLeft((float) leftPixelPosition, Sizeable.UNITS_PIXELS);
position.setTop((float) topPixelPosition, Sizeable.UNITS_PIXELS);
}
use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable 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);
}
}
use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.
the class DefaultGridLayoutDropHandler method handleComponentReordering.
/*
* (non-Javadoc)
*
* @see
* com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.AbstractDefaultLayoutDropHandler
* #handleComponentReordering(com.vaadin.event.dd.DragAndDropEvent)
*/
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
GridLayoutTargetDetails details = (GridLayoutTargetDetails) event.getTargetDetails();
DDGridLayout layout = (DDGridLayout) details.getTarget();
LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
Component comp = transferable.getComponent();
int row = details.getOverRow();
int column = details.getOverColumn();
if (layout.getComponent(column, row) == null) {
layout.removeComponent(comp);
addComponent(event, comp, column, row);
}
}
Aggregations