use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable 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);
}
}
use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.
the class DDAccordion method getTransferable.
/**
* {@inheritDoc}
*/
public Transferable getTransferable(Map<String, Object> rawVariables) {
if (rawVariables.get("index") != null) {
int index = Integer.parseInt(rawVariables.get("index").toString());
Iterator<Component> iter = getComponentIterator();
int counter = 0;
Component c = null;
while (iter.hasNext()) {
c = iter.next();
if (counter == index) {
break;
}
counter++;
}
rawVariables.put("component", c);
} else if (rawVariables.get("component") == null) {
rawVariables.put("component", DDAccordion.this);
}
return new LayoutBoundTransferable(this, rawVariables);
}
use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.
the class DDTabSheet method getTransferable.
public Transferable getTransferable(Map<String, Object> rawVariables) {
if (rawVariables.get(Constants.TRANSFERABLE_DETAIL_INDEX) != null) {
// We dragged a tab, substitute component with tab content
int index = Integer.parseInt(rawVariables.get(Constants.TRANSFERABLE_DETAIL_INDEX).toString());
Iterator<Component> iter = getComponentIterator();
int counter = 0;
Component c = null;
while (iter.hasNext()) {
c = iter.next();
if (counter == index) {
break;
}
counter++;
}
rawVariables.put(Constants.TRANSFERABLE_DETAIL_COMPONENT, c);
} else if (rawVariables.get("component") == null) {
rawVariables.put(Constants.TRANSFERABLE_DETAIL_COMPONENT, DDTabSheet.this);
}
return new LayoutBoundTransferable(this, rawVariables);
}
use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.
the class DefaultAbsoluteLayoutDropHandler method handleDropFromLayout.
/**
* Handle a drop from another layout
*
* @param event
* The drag and drop event
*/
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event.getTargetDetails();
LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
Component component = transferable.getComponent();
Component source = event.getTransferable().getSourceComponent();
DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget();
int leftPixelPosition = details.getRelativeLeft();
int topPixelPosition = details.getRelativeTop();
// Check that we are not dragging an outer layout into an
// inner
// layout
Component parent = source.getParent();
while (parent != null) {
parent = parent.getParent();
}
// remove component from source
if (source instanceof ComponentContainer) {
((ComponentContainer) source).removeComponent(component);
} else if (source instanceof SingleComponentContainer) {
((SingleComponentContainer) source).setContent(null);
}
// Add component to absolute layout
layout.addComponent(component, "left:" + leftPixelPosition + "px;top:" + topPixelPosition + "px");
}
use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.
the class DefaultCssLayoutDropHandler method handleComponentReordering.
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
// Component re-ordering
LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
CssLayoutTargetDetails details = (CssLayoutTargetDetails) event.getTargetDetails();
DDCssLayout layout = (DDCssLayout) details.getTarget();
Component comp = transferable.getComponent();
int idx = details.getOverIndex();
// Detach from old source
Component source = transferable.getSourceComponent();
if (source instanceof ComponentContainer) {
((ComponentContainer) source).removeComponent(comp);
} else if (source instanceof SingleComponentContainer) {
((SingleComponentContainer) source).setContent(null);
}
// Add component
if (idx >= 0 && idx < layout.getComponentCount()) {
layout.addComponent(comp, idx);
} else {
layout.addComponent(comp);
}
}
Aggregations