Java Code Examples for com.vaadin.ui.AbstractOrderedLayout#setComponentAlignment()

The following examples show how to use com.vaadin.ui.AbstractOrderedLayout#setComponentAlignment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultVerticalLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@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);
    }

}
 
Example 2
Source File: DefaultVerticalLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@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);
    }

}
 
Example 3
Source File: DefaultFormLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
    FormLayoutTargetDetails details = (FormLayoutTargetDetails) event
            .getTargetDetails();
    int idx = details.getOverIndex();
    AbstractOrderedLayout layout = (AbstractOrderedLayout) details
            .getTarget();

    // 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(resolveComponentFromHTML5Drop(event), idx);
    } else {
        layout.addComponent(resolveComponentFromHTML5Drop(event));
    }

    // Add component alignment if given
    if (dropAlignment != null) {
        layout.setComponentAlignment(resolveComponentFromHTML5Drop(event),
                dropAlignment);
    }
}
 
Example 4
Source File: DefaultVerticalLayoutDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    }

}
 
Example 5
Source File: DefaultVerticalLayoutDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    }
}
 
Example 6
Source File: DefaultVerticalLayoutDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    }

}
 
Example 7
Source File: DefaultVerticalLayoutDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    }
}
 
Example 8
Source File: DefaultFormLayoutDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    FormLayoutTargetDetails details = (FormLayoutTargetDetails) 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);
    }
}