use of com.vaadin.ui.AbstractOrderedLayout in project cuba by cuba-platform.
the class DefaultVerticalLayoutDropHandler method handleDropFromLayout.
/**
* Handle a drop from another layout
*
* @param event
* The drag and drop event
*/
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
VerticalLayoutTargetDetails details = (VerticalLayoutTargetDetails) event.getTargetDetails();
AbstractOrderedLayout layout = (AbstractOrderedLayout) details.getTarget();
Component source = event.getTransferable().getSourceComponent();
int idx = (details).getOverIndex();
Component comp = transferable.getComponent();
// 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();
}
// Detach from old source
if (source instanceof ComponentContainer) {
((ComponentContainer) source).removeComponent(comp);
} else if (source instanceof SingleComponentContainer) {
((SingleComponentContainer) source).setContent(null);
}
// Increase index if component is dropped after or above a
// previous
// component
VerticalDropLocation loc = (details).getDropLocation();
if (loc == VerticalDropLocation.MIDDLE || loc == VerticalDropLocation.BOTTOM) {
idx++;
}
// 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.ui.AbstractOrderedLayout in project cuba by cuba-platform.
the class DefaultVerticalLayoutDropHandler method handleHTML5Drop.
@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
VerticalLayoutTargetDetails details = (VerticalLayoutTargetDetails) event.getTargetDetails();
AbstractOrderedLayout layout = (AbstractOrderedLayout) details.getTarget();
int idx = (details).getOverIndex();
// Increase index if component is dropped after or above a
// previous
// component
VerticalDropLocation loc = (details).getDropLocation();
if (loc == VerticalDropLocation.MIDDLE || loc == VerticalDropLocation.BOTTOM) {
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.ui.AbstractOrderedLayout in project cuba by cuba-platform.
the class DefaultVerticalLayoutDropHandler 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();
VerticalLayoutTargetDetails details = (VerticalLayoutTargetDetails) 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
VerticalDropLocation loc = details.getDropLocation();
if (loc == VerticalDropLocation.MIDDLE || loc == VerticalDropLocation.BOTTOM) {
idx++;
}
// 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.ui.AbstractOrderedLayout in project cuba by cuba-platform.
the class WebGroupBox method setExpandRatio.
@Override
public void setExpandRatio(Component component, float ratio) {
AbstractOrderedLayout layout = getComponentContent();
layout.setExpandRatio(component.unwrapComposition(com.vaadin.ui.Component.class), ratio);
}
use of com.vaadin.ui.AbstractOrderedLayout in project cuba by cuba-platform.
the class WebScrollBoxLayout method add.
@Override
public void add(Component childComponent, int index) {
if (childComponent.getParent() != null && childComponent.getParent() != this) {
throw new IllegalStateException("Component already has parent");
}
AbstractOrderedLayout newContent = null;
if (orientation == Orientation.VERTICAL && !(getContent() instanceof CubaVerticalActionsLayout)) {
newContent = new CubaVerticalActionsLayout();
newContent.setWidth(100, Sizeable.Unit.PERCENTAGE);
} else if (orientation == Orientation.HORIZONTAL && !(getContent() instanceof CubaHorizontalActionsLayout)) {
newContent = new CubaHorizontalActionsLayout();
}
if (newContent != null) {
newContent.setMargin((getContent()).getMargin());
newContent.setSpacing((getContent()).isSpacing());
newContent.setStyleName(SCROLLBOX_CONTENT_STYLENAME);
com.vaadin.ui.Component oldContent = component.getComponent(0);
newContent.setWidth(oldContent.getWidth(), oldContent.getWidthUnits());
newContent.setHeight(oldContent.getHeight(), oldContent.getHeightUnits());
component.removeAllComponents();
component.addComponent(newContent);
applyScrollBarsPolicy(scrollBarPolicy);
}
if (ownComponents.contains(childComponent)) {
int existingIndex = getContent().getComponentIndex(WebComponentsHelper.getComposition(childComponent));
if (index > existingIndex) {
index--;
}
remove(childComponent);
}
com.vaadin.ui.Component vComponent = WebComponentsHelper.getComposition(childComponent);
getContent().addComponent(vComponent, index);
getContent().setComponentAlignment(vComponent, WebWrapperUtils.toVaadinAlignment(childComponent.getAlignment()));
if (frame != null) {
if (childComponent instanceof BelongToFrame && ((BelongToFrame) childComponent).getFrame() == null) {
((BelongToFrame) childComponent).setFrame(frame);
} else {
((FrameImplementation) frame).registerComponent(childComponent);
}
}
if (index == ownComponents.size()) {
ownComponents.add(childComponent);
} else {
ownComponents.add(index, childComponent);
}
childComponent.setParent(this);
}
Aggregations