Search in sources :

Example 1 with AccordionTargetDetails

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AccordionTargetDetails in project cuba by cuba-platform.

the class DefaultAccordionDropHandler method handleComponentReordering.

/**
 * Called when tabs are being rearranged
 *
 * @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);
        }
    }
}
Also used : VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) Tab(com.vaadin.ui.TabSheet.Tab) DDAccordion(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAccordion) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) AccordionTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AccordionTargetDetails) Component(com.vaadin.ui.Component)

Example 2 with AccordionTargetDetails

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AccordionTargetDetails in project cuba by cuba-platform.

the class DefaultAccordionDropHandler method handleDropFromLayout.

/**
 * 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);
    }
}
Also used : VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) DDAccordion(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAccordion) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) ComponentContainer(com.vaadin.ui.ComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) AccordionTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AccordionTargetDetails) Component(com.vaadin.ui.Component)

Example 3 with AccordionTargetDetails

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AccordionTargetDetails in project cuba by cuba-platform.

the class DefaultAccordionDropHandler method handleHTML5Drop.

@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);
    }
}
Also used : VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) DDAccordion(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAccordion) AccordionTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AccordionTargetDetails) Component(com.vaadin.ui.Component)

Aggregations

DDAccordion (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAccordion)3 AccordionTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AccordionTargetDetails)3 VerticalDropLocation (com.vaadin.shared.ui.dd.VerticalDropLocation)3 Component (com.vaadin.ui.Component)3 LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)2 ComponentContainer (com.vaadin.ui.ComponentContainer)1 SingleComponentContainer (com.vaadin.ui.SingleComponentContainer)1 Tab (com.vaadin.ui.TabSheet.Tab)1