Java Code Examples for com.vaadin.shared.ui.dd.VerticalDropLocation#BOTTOM

The following examples show how to use com.vaadin.shared.ui.dd.VerticalDropLocation#BOTTOM . 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: DefaultAccordionDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
    AccordionTargetDetails details = (AccordionTargetDetails) event
            .getTargetDetails();
    VerticalDropLocation location = details.getDropLocation();
    DDAccordion acc = (DDAccordion) details.getTarget();
    int idx = details.getOverIndex();

    Component c = resolveComponentFromHTML5Drop(event);
    c.setCaption(resolveCaptionFromHTML5Drop(event));

    if (location == VerticalDropLocation.TOP) {
        acc.addTab(c, idx);
    } else if (location == VerticalDropLocation.BOTTOM) {
        acc.addTab(c, idx + 1);
    } else {
        acc.addTab(c);
    }
}
 
Example 2
Source File: VDragDropUtil.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * Get the vertical drop location in a ordered layout
 * 
 * @param element
 *            The target element or cell
 * @param offsetHeight
 *            The height of the cell
 * @param clientY
 *            The width of the cell
 * @param topBottomRatio
 *            The ratio of the cell
 * @return The location of the drop
 */
public static VerticalDropLocation getVerticalDropLocation(Element element,
        int offsetHeight, int clientY, double topBottomRatio) {

    int absoluteTop = element.getAbsoluteTop();
    int fromTop = clientY - absoluteTop;

    float percentageFromTop = (fromTop / (float) offsetHeight);
    if (percentageFromTop < topBottomRatio) {
        return VerticalDropLocation.TOP;
    } else if (percentageFromTop > 1 - topBottomRatio) {
        return VerticalDropLocation.BOTTOM;
    } else {
        return VerticalDropLocation.MIDDLE;
    }
}
 
Example 3
Source File: VDDGridLayout.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the vertical drop location
 * 
 * @param cell
 *            The cell details
 * @param event
 *            The drag event
 * @return
 */
protected VerticalDropLocation getVerticalDropLocation(CellDetails cell,
        VDragEvent event) {

    // Get the vertical location
    VerticalDropLocation vdetail;
    int y = Util.getTouchOrMouseClientY(event.getCurrentGwtEvent())
            - getAbsoluteTop() - cell.y;

    assert(y >= 0 && y <= cell.height);

    if (y < cell.height * cellTopBottomDropRatio) {
        vdetail = VerticalDropLocation.TOP;
    } else if (y < cell.height * (1.0 - cellTopBottomDropRatio)) {
        vdetail = VerticalDropLocation.MIDDLE;
    } else {
        vdetail = VerticalDropLocation.BOTTOM;
    }
    return vdetail;
}
 
Example 4
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 5
Source File: DefaultAccordionDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new tab from the drop
 * 
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();

    // Get the target details
    AccordionTargetDetails details = (AccordionTargetDetails) event
            .getTargetDetails();
    DDAccordion acc = (DDAccordion) details.getTarget();
    Component c = transferable.getComponent();
    int idx = details.getOverIndex();
    VerticalDropLocation location = details.getDropLocation();

    // Detach from old source
    Component source = transferable.getSourceComponent();
    if (source instanceof ComponentContainer) {
        ((ComponentContainer) source).removeComponent(c);
    } else if (source instanceof SingleComponentContainer) {
        ((SingleComponentContainer) source).setContent(null);
    }

    if (location == VerticalDropLocation.TOP) {
        acc.addTab(c, idx);
    } else if (location == VerticalDropLocation.BOTTOM) {
        acc.addTab(c, idx + 1);
    } else {
        acc.addTab(c);
    }
}
 
Example 6
Source File: DefaultVerticalSplitPanelDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
    VerticalSplitPanelTargetDetails details = (VerticalSplitPanelTargetDetails) event
            .getTargetDetails();
    DDVerticalSplitPanel panel = (DDVerticalSplitPanel) details.getTarget();

    if (details.getDropLocation() == VerticalDropLocation.TOP) {
        // Dropped in the left area
        panel.setFirstComponent(resolveComponentFromHTML5Drop(event));

    } else if (details.getDropLocation() == VerticalDropLocation.BOTTOM) {
        // Dropped in the right area
        panel.setSecondComponent(resolveComponentFromHTML5Drop(event));
    }
}
 
Example 7
Source File: DefaultVerticalSplitPanelDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    VerticalSplitPanelTargetDetails details = (VerticalSplitPanelTargetDetails) event
            .getTargetDetails();
    Component component = transferable.getComponent();
    DDVerticalSplitPanel panel = (DDVerticalSplitPanel) details.getTarget();
    ComponentContainer source = (ComponentContainer) transferable
            .getSourceComponent();

    // Detach from old source
    if (source instanceof ComponentContainer) {
        ((ComponentContainer) source).removeComponent(component);
    } else if (source instanceof SingleComponentContainer) {
        ((SingleComponentContainer) source).setContent(null);
    }

    if (details.getDropLocation() == VerticalDropLocation.TOP) {
        // Dropped in the left area
        panel.setFirstComponent(component);

    } else if (details.getDropLocation() == VerticalDropLocation.BOTTOM) {
        // Dropped in the right area
        panel.setSecondComponent(component);
    }
}
 
Example 8
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 9
Source File: DefaultCssLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
    CssLayoutTargetDetails details = (CssLayoutTargetDetails) event
            .getTargetDetails();
    Component over = details.getOverComponent();
    DDCssLayout layout = (DDCssLayout) details.getTarget();
    int idx = (details).getOverIndex();
    HorizontalDropLocation hl = details.getHorizontalDropLocation();
    VerticalDropLocation vl = details.getVerticalDropLocation();

    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++;
        }
    }

    if (idx >= 0 && idx < layout.getComponentCount()) {
        layout.addComponent(resolveComponentFromHTML5Drop(event), idx);
    } else {
        layout.addComponent(resolveComponentFromHTML5Drop(event));
    }
}
 
Example 10
Source File: DDVerticalSplitPanel.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected VerticalSplitPanelTargetDetails(
        Map<String, Object> rawDropData) {
    super(rawDropData, DDVerticalSplitPanel.this);

    if (getDropLocation() == VerticalDropLocation.TOP) {
        over = getFirstComponent();
    } else if (getDropLocation() == VerticalDropLocation.BOTTOM) {
        over = getSecondComponent();
    } else {
        over = DDVerticalSplitPanel.this;
    }
}
 
Example 11
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 12
Source File: VDDAccordion.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * Emphasisizes a container element
 * 
 * @param element
 */
protected void emphasis(Element element, VDragEvent event) {

    // Find the tab
    StackItem tab = WidgetUtil.findWidget(element, StackItem.class);
    if (tab != null && getElement().isOrHasChild(tab.getElement())
            && currentlyEmphasised != tab) {
        VerticalDropLocation location = getDropLocation(tab, event);

        if (location == VerticalDropLocation.MIDDLE) {
            if (tab.isOpen()) {
                tab.addStyleName(CLASSNAME_OVER);
            } else {
                tab.getWidget(0).addStyleName(CLASSNAME_OVER);
            }
        } else if (!spacer.isAttached()) {
            if (location == VerticalDropLocation.TOP) {
                insertSpacer(spacer, getElement(), getWidgetIndex(tab));
                tab.setHeight(
                        (tab.getOffsetHeight() - spacer.getOffsetHeight())
                                + "px");
            } else if (location == VerticalDropLocation.BOTTOM) {
                insertSpacer(spacer, getElement(), getWidgetIndex(tab) + 1);
                int newHeight = tab.getOffsetHeight()
                        - spacer.getOffsetHeight();
                if (getWidgetIndex(spacer) == getWidgetCount() - 1) {
                    newHeight -= spacer.getOffsetHeight();
                }
                if (newHeight >= 0) {
                    tab.setHeight(newHeight + "px");
                }
            }
        }
        currentlyEmphasised = tab;
    }
}
 
Example 13
Source File: VDDVerticalSplitPanel.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 * 
 * @param event
 *            The drag event
 */
protected void updateDragDetails(VDragEvent event) {
    Element over = event.getElementOver();

    // Resolve where the drop was made
    VerticalDropLocation location = null;
    Widget content = null;
    if (firstContainer.isOrHasChild(over)) {
        location = VerticalDropLocation.TOP;
        content = Util.findWidget(firstContainer, null);
    } else if (splitter.isOrHasChild(over)) {
        location = VerticalDropLocation.MIDDLE;
        content = this;
    } else if (secondContainer.isOrHasChild(over)) {
        location = VerticalDropLocation.BOTTOM;
        content = Util.findWidget(secondContainer, null);
    }

    event.getDropDetails().put(Constants.DROP_DETAIL_VERTICAL_DROP_LOCATION,
            location);

    if (content != null) {
        event.getDropDetails().put(Constants.DROP_DETAIL_OVER_CLASS,
                content.getClass().getName());
    } else {
        event.getDropDetails().put(Constants.DROP_DETAIL_OVER_CLASS,
                this.getClass().getName());
    }

    // Add mouse event details
    MouseEventDetails details = MouseEventDetailsBuilder
            .buildMouseEventDetails(event.getCurrentGwtEvent(),
                    getElement());
    event.getDropDetails().put(Constants.DROP_DETAIL_MOUSE_EVENT,
            details.serialize());
}
 
Example 14
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 15
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 16
Source File: DefaultCssLayoutDropHandler.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();
    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();
    }

    // If source is an instance of a component container then remove
    // it
    // from there,
    // 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);
    }
}
 
Example 17
Source File: DefaultFormLayoutDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    FormLayoutTargetDetails details = (FormLayoutTargetDetails) event
            .getTargetDetails();
    DDFormLayout layout = (DDFormLayout) details.getTarget();

    Component comp = transferable.getComponent();
    int idx = details.getOverIndex();
    int oldIdx = layout.getComponentIndex(comp);

    if (idx == oldIdx) {
        // Dropping on myself
        return;
    }

    // Detach
    layout.removeComponent(comp);
    if (idx > 0 && idx > oldIdx) {
        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 18
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);
    }
}
 
Example 19
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 20
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);
    }

}