use of com.vaadin.shared.ui.dd.HorizontalDropLocation in project cuba by cuba-platform.
the class DefaultHorizontalLayoutDropHandler method handleHTML5Drop.
@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
HorizontalLayoutTargetDetails details = (HorizontalLayoutTargetDetails) event.getTargetDetails();
AbstractOrderedLayout layout = (AbstractOrderedLayout) details.getTarget();
int idx = (details).getOverIndex();
// Increase index if component is dropped after or above a
// previous component
HorizontalDropLocation loc = (details).getDropLocation();
if (loc == HorizontalDropLocation.CENTER || loc == HorizontalDropLocation.RIGHT) {
idx++;
}
Component comp = resolveComponentFromHTML5Drop(event);
// Add component
if (idx >= 0) {
layout.addComponent(comp, idx);
} else {
layout.addComponent(comp);
}
// Add component alignment if given
if (dropAlignment != null) {
layout.setComponentAlignment(comp, dropAlignment);
}
}
use of com.vaadin.shared.ui.dd.HorizontalDropLocation 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.vaadin.shared.ui.dd.HorizontalDropLocation 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.vaadin.shared.ui.dd.HorizontalDropLocation in project cuba by cuba-platform.
the class DefaultHorizontalLayoutDropHandler method handleHTML5Drop.
@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
HorizontalLayoutTargetDetails details = (HorizontalLayoutTargetDetails) event.getTargetDetails();
AbstractOrderedLayout layout = (AbstractOrderedLayout) details.getTarget();
int idx = (details).getOverIndex();
// Increase index if component is dropped after or above a
// previous component
HorizontalDropLocation loc = (details).getDropLocation();
if (loc == HorizontalDropLocation.CENTER || loc == HorizontalDropLocation.RIGHT) {
idx++;
}
Component comp = resolveComponentFromHTML5Drop(event);
// Add component
if (idx >= 0) {
layout.addComponent(comp, idx);
} else {
layout.addComponent(comp);
}
// Add component alignment if given
if (dropAlignment != null) {
layout.setComponentAlignment(comp, dropAlignment);
}
}
use of com.vaadin.shared.ui.dd.HorizontalDropLocation in project cuba by cuba-platform.
the class DefaultHorizontalLayoutDropHandler method handleComponentReordering.
/**
* Called when a component changed location within the layout
*
* @param event
* The drag and drop event
*/
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
// Component re-ordering
LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
HorizontalLayoutTargetDetails details = (HorizontalLayoutTargetDetails) event.getTargetDetails();
AbstractOrderedLayout layout = (AbstractOrderedLayout) details.getTarget();
Component comp = transferable.getComponent();
int idx = details.getOverIndex();
int oldIndex = layout.getComponentIndex(comp);
if (idx == oldIndex) {
// Index did not change
return;
}
// Detach
layout.removeComponent(comp);
// Account for detachment if new index is bigger then old index
if (idx > oldIndex) {
idx--;
}
// Increase index if component is dropped after or above a previous
// component
HorizontalDropLocation loc = details.getDropLocation();
if (loc == HorizontalDropLocation.CENTER || loc == HorizontalDropLocation.RIGHT) {
idx++;
}
// Add component
if (idx >= 0) {
layout.addComponent(comp, idx);
} else {
layout.addComponent(comp, 0);
}
// Add component alignment if given
if (dropAlignment != null) {
layout.setComponentAlignment(comp, dropAlignment);
}
}
Aggregations