Search in sources :

Example 6 with LayoutBoundTransferable

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.

the class DefaultHorizontalSplitPanelDropHandler method handleDropFromLayout.

@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    ComponentContainer source = (ComponentContainer) transferable.getSourceComponent();
    HorizontalSplitPanelTargetDetails details = (HorizontalSplitPanelTargetDetails) event.getTargetDetails();
    Component component = transferable.getComponent();
    DDHorizontalSplitPanel panel = (DDHorizontalSplitPanel) details.getTarget();
    // Detach from old source
    if (source instanceof ComponentContainer) {
        ((ComponentContainer) source).removeComponent(component);
    } else if (source instanceof SingleComponentContainer) {
        ((SingleComponentContainer) source).setContent(null);
    }
    if (details.getDropLocation() == HorizontalDropLocation.LEFT) {
        // Dropped in the left area
        panel.setFirstComponent(component);
    } else if (details.getDropLocation() == HorizontalDropLocation.RIGHT) {
        // Dropped in the right area
        panel.setSecondComponent(component);
    }
}
Also used : 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) HorizontalSplitPanelTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDHorizontalSplitPanel.HorizontalSplitPanelTargetDetails) Component(com.vaadin.ui.Component) DDHorizontalSplitPanel(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDHorizontalSplitPanel)

Example 7 with LayoutBoundTransferable

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.

the class DefaultTabSheetDropHandler method handleComponentReordering.

@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    TabSheetTargetDetails details = (TabSheetTargetDetails) event.getTargetDetails();
    DDTabSheet tabSheet = (DDTabSheet) details.getTarget();
    Component c = transferable.getComponent();
    Tab tab = tabSheet.getTab(c);
    HorizontalDropLocation location = details.getDropLocation();
    int idx = details.getOverIndex();
    if (location == HorizontalDropLocation.LEFT) {
        // Left of previous tab
        int originalIndex = tabSheet.getTabPosition(tab);
        if (originalIndex > idx) {
            tabSheet.setTabPosition(tab, idx);
        } else if (idx - 1 >= 0) {
            tabSheet.setTabPosition(tab, idx - 1);
        }
    } else if (location == HorizontalDropLocation.RIGHT) {
        // Right of previous tab
        int originalIndex = tabSheet.getTabPosition(tab);
        if (originalIndex > idx) {
            tabSheet.setTabPosition(tab, idx + 1);
        } else {
            tabSheet.setTabPosition(tab, idx);
        }
    }
}
Also used : TabSheetTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet.TabSheetTargetDetails) Tab(com.vaadin.ui.TabSheet.Tab) DDTabSheet(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation) Component(com.vaadin.ui.Component)

Example 8 with LayoutBoundTransferable

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.

the class DefaultAbsoluteLayoutDropHandler method handleComponentReordering.

/**
 * Called when a component changed location within the layout
 *
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event.getTargetDetails();
    DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    Component component = transferable.getComponent();
    // Get top-left pixel position
    int leftPixelPosition = details.getRelativeLeft();
    int topPixelPosition = details.getRelativeTop();
    ComponentPosition position = layout.getPosition(component);
    position.setLeft((float) leftPixelPosition, Sizeable.UNITS_PIXELS);
    position.setTop((float) topPixelPosition, Sizeable.UNITS_PIXELS);
}
Also used : ComponentPosition(com.vaadin.ui.AbsoluteLayout.ComponentPosition) AbsoluteLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AbsoluteLayoutTargetDetails) DDAbsoluteLayout(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) Component(com.vaadin.ui.Component)

Example 9 with LayoutBoundTransferable

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.

the class DefaultCssLayoutDropHandler method handleDropFromLayout.

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

Example 10 with LayoutBoundTransferable

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.

the class DefaultGridLayoutDropHandler method handleComponentReordering.

/*
     * (non-Javadoc)
     * 
     * @see
     * com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.AbstractDefaultLayoutDropHandler
     * #handleComponentReordering(com.vaadin.event.dd.DragAndDropEvent)
     */
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    GridLayoutTargetDetails details = (GridLayoutTargetDetails) event.getTargetDetails();
    DDGridLayout layout = (DDGridLayout) details.getTarget();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    Component comp = transferable.getComponent();
    int row = details.getOverRow();
    int column = details.getOverColumn();
    if (layout.getComponent(column, row) == null) {
        layout.removeComponent(comp);
        addComponent(event, comp, column, row);
    }
}
Also used : DDGridLayout(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) GridLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout.GridLayoutTargetDetails) Component(com.vaadin.ui.Component)

Aggregations

LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)27 Component (com.vaadin.ui.Component)23 ComponentContainer (com.vaadin.ui.ComponentContainer)12 SingleComponentContainer (com.vaadin.ui.SingleComponentContainer)12 VerticalDropLocation (com.vaadin.shared.ui.dd.VerticalDropLocation)9 HorizontalDropLocation (com.vaadin.shared.ui.dd.HorizontalDropLocation)7 DDAbsoluteLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout)5 AbstractOrderedLayout (com.vaadin.ui.AbstractOrderedLayout)5 ComponentPosition (com.vaadin.ui.AbsoluteLayout.ComponentPosition)3 DDAccordion (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAccordion)2 DDCssLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout)2 CssLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout.CssLayoutTargetDetails)2 FormLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDFormLayout.FormLayoutTargetDetails)2 DDGridLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout)2 GridLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout.GridLayoutTargetDetails)2 HorizontalLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDHorizontalLayout.HorizontalLayoutTargetDetails)2 DDTabSheet (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet)2 TabSheetTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet.TabSheetTargetDetails)2 VerticalLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDVerticalLayout.VerticalLayoutTargetDetails)2 AbsoluteLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AbsoluteLayoutTargetDetails)2