Example usage for com.vaadin.shared.ui.dd VerticalDropLocation TOP

List of usage examples for com.vaadin.shared.ui.dd VerticalDropLocation TOP

Introduction

In this page you can find the example usage for com.vaadin.shared.ui.dd VerticalDropLocation TOP.

Prototype

VerticalDropLocation TOP

To view the source code for com.vaadin.shared.ui.dd VerticalDropLocation TOP.

Click Source Link

Usage

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultAccordionDropHandler.java

License:Apache License

/**
 * Called when tabs are being rearranged
 * //from  w  ww .ja v  a 2s . c o  m
 * @param event
 *            A drag and drop event
 */
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    AccordionTargetDetails details = (AccordionTargetDetails) event.getTargetDetails();
    DDAccordion acc = (DDAccordion) details.getTarget();
    VerticalDropLocation location = details.getDropLocation();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    Component c = transferable.getComponent();
    int idx = details.getOverIndex();

    Tab tab = acc.getTab(c);

    if (location == VerticalDropLocation.TOP) {
        // Left of previous tab
        int originalIndex = acc.getTabPosition(tab);
        if (originalIndex > idx) {
            acc.setTabPosition(tab, idx);
        } else if (idx - 1 >= 0) {
            acc.setTabPosition(tab, idx - 1);
        }

    } else if (location == VerticalDropLocation.BOTTOM) {
        // Right of previous tab
        int originalIndex = acc.getTabPosition(tab);
        if (originalIndex > idx) {
            acc.setTabPosition(tab, idx + 1);
        } else {
            acc.setTabPosition(tab, idx);
        }
    }
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultAccordionDropHandler.java

License:Apache License

/**
 * Adds a new tab from the drop/*from   w  w  w  .jav a2  s  .  c o  m*/
 * 
 * @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);
    }
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultAccordionDropHandler.java

License:Apache License

@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);// w  w  w  . j  av a 2 s  .c o m
    } else if (location == VerticalDropLocation.BOTTOM) {
        acc.addTab(c, idx + 1);
    } else {
        acc.addTab(c);
    }
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultCssLayoutDropHandler.java

License:Apache License

@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;/*from w  w w . j ava  2  s  .c  o m*/
        } 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);
    }
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultCssLayoutDropHandler.java

License:Apache License

@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;/*from   w  w  w .j  a  v a  2  s. com*/
        } 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));
    }
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultVerticalSplitPanelDropHandler.java

License:Apache License

@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);
    }/* ww w  .  j  a  v a2s  .c  o m*/

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

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultVerticalSplitPanelDropHandler.java

License:Apache License

@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));
    }/*ww w  .  j  a va  2 s  .  c om*/
}

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.accordion.VDDAccordion.java

License:Apache License

/**
 * Emphasisizes a container element/*from w w  w  .  j  a va  2 s. com*/
 * 
 * @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;
    }
}

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.csslayout.VDDCssLayout.java

License:Apache License

public void updateDrag(VDragEvent drag) {

    if (placeHolderElement == null) {
        /*//from w  ww .ja v  a 2 s . c o  m
         * Drag image might not have been detach due to lazy attaching in
         * the DragAndDropManager. Detach it again here if it has not been
         * detached.
         */
        attachDragImageToLayout(drag);
        return;
    }

    if (drag.getElementOver().isOrHasChild(placeHolderElement)) {
        return;
    }

    if (placeHolderElement.hasParentElement()) {
        /*
         * Remove the placeholder from the DOM so we can reposition
         */
        placeHolderElement.removeFromParent();
    }

    Widget w = Util.findWidget(drag.getElementOver(), null);

    ComponentConnector draggedConnector = (ComponentConnector) drag.getTransferable()
            .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);

    if (draggedConnector != null && w == draggedConnector.getWidget()) {
        /*
         * Dragging drag image over the placeholder should not have any
         * effect (except placeholder should be removed)
         */
        return;
    }

    if (w != null && w != this) {

        HorizontalDropLocation hl = getHorizontalDropLocation(w, drag);
        VerticalDropLocation vl = getVerticalDropLocation(w, drag);

        if (hl == HorizontalDropLocation.LEFT || vl == VerticalDropLocation.TOP) {
            Element prev = w.getElement().getPreviousSibling().cast();
            if (draggedConnector == null || prev == null
                    || !draggedConnector.getWidget().getElement().isOrHasChild(prev)) {

                w.getElement().getParentElement().insertBefore(placeHolderElement, w.getElement());

            }
        } else if (hl == HorizontalDropLocation.RIGHT || vl == VerticalDropLocation.BOTTOM) {
            Element next = w.getElement().getNextSibling().cast();
            if (draggedConnector == null || next == null
                    || !draggedConnector.getWidget().getElement().isOrHasChild(next)) {
                w.getElement().getParentElement().insertAfter(placeHolderElement, w.getElement());
            }

        } else {
            Element prev = w.getElement().getPreviousSibling().cast();
            if (draggedConnector == null || prev == null
                    || !draggedConnector.getWidget().getElement().isOrHasChild(prev)) {
                w.getElement().getParentElement().insertBefore(placeHolderElement, w.getElement());
            }
        }

    } else {
        /*
         * First child or hoovering outside of current components
         */
        getElement().appendChild(placeHolderElement);
    }

    updatePlaceHolderStyleProperties(drag);
}

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.formlayout.VDDFormLayout.java

License:Apache License

/**
 * Removes any applies drag and drop style applied by emphasis()
 *///from w w w . j a v a 2 s. c  o m
protected void deEmphasis() {
    if (currentlyEmphasised != null) {
        // Universal over style
        setStyleName(currentlyEmphasised, OVER, false);
        setStyleName(currentlyEmphasised, OVER_SPACED, false);

        // Vertical styles
        setStyleName(currentlyEmphasised, OVER + "-" + VerticalDropLocation.TOP.toString().toLowerCase(),
                false);
        setStyleName(currentlyEmphasised, OVER + "-" + VerticalDropLocation.MIDDLE.toString().toLowerCase(),
                false);
        setStyleName(currentlyEmphasised, OVER + "-" + VerticalDropLocation.BOTTOM.toString().toLowerCase(),
                false);

        currentlyEmphasised = null;
    }
}