Search in sources :

Example 1 with DDTabSheet

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet 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 2 with DDTabSheet

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

the class DefaultTabSheetDropHandler method handleHTML5Drop.

@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
    TabSheetTargetDetails details = (TabSheetTargetDetails) event.getTargetDetails();
    HorizontalDropLocation location = details.getDropLocation();
    DDTabSheet tabSheet = (DDTabSheet) details.getTarget();
    int idx = details.getOverIndex();
    Component c = resolveComponentFromHTML5Drop(event);
    c.setCaption(resolveCaptionFromHTML5Drop(event));
    if (location == HorizontalDropLocation.LEFT) {
        tabSheet.addTab(c, idx);
    } else if (location == HorizontalDropLocation.RIGHT) {
        tabSheet.addTab(c, idx + 1);
    }
}
Also used : TabSheetTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet.TabSheetTargetDetails) DDTabSheet(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation) Component(com.vaadin.ui.Component)

Example 3 with DDTabSheet

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

the class DefaultTabSheetDropHandler method handleDropFromLayout.

@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    TabSheetTargetDetails details = (TabSheetTargetDetails) event.getTargetDetails();
    DDTabSheet tabSheet = (DDTabSheet) details.getTarget();
    Component c = transferable.getComponent();
    HorizontalDropLocation location = details.getDropLocation();
    int idx = details.getOverIndex();
    ComponentContainer source = (ComponentContainer) transferable.getSourceComponent();
    // Detach from old source
    if (source instanceof ComponentContainer) {
        ((ComponentContainer) source).removeComponent(c);
    } else if (source instanceof SingleComponentContainer) {
        ((SingleComponentContainer) source).setContent(null);
    }
    if (location == HorizontalDropLocation.LEFT) {
        tabSheet.addTab(c, idx);
    } else if (location == HorizontalDropLocation.RIGHT) {
        tabSheet.addTab(c, idx + 1);
    }
}
Also used : TabSheetTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet.TabSheetTargetDetails) DDTabSheet(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet) 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) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation) Component(com.vaadin.ui.Component)

Aggregations

DDTabSheet (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet)3 TabSheetTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet.TabSheetTargetDetails)3 HorizontalDropLocation (com.vaadin.shared.ui.dd.HorizontalDropLocation)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