Search in sources :

Example 16 with HorizontalDropLocation

use of com.vaadin.shared.ui.dd.HorizontalDropLocation in project cuba by cuba-platform.

the class DefaultHorizontalLayoutDropHandler method handleDropFromLayout.

/**
 * Handle a drop from another layout
 *
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    HorizontalLayoutTargetDetails details = (HorizontalLayoutTargetDetails) 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
    HorizontalDropLocation loc = (details).getDropLocation();
    if (loc == HorizontalDropLocation.CENTER || loc == HorizontalDropLocation.RIGHT) {
        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);
    }
}
Also used : HorizontalLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDHorizontalLayout.HorizontalLayoutTargetDetails) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation)

Example 17 with HorizontalDropLocation

use of com.vaadin.shared.ui.dd.HorizontalDropLocation in project cuba by cuba-platform.

the class DefaultHorizontalLayoutDropHandler method handleComponentReordering.

/**
 * 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();
    HorizontalLayoutTargetDetails details = (HorizontalLayoutTargetDetails) 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
    HorizontalDropLocation loc = details.getDropLocation();
    if (loc == HorizontalDropLocation.CENTER || loc == HorizontalDropLocation.RIGHT) {
        idx++;
    }
    // Add component
    if (idx >= 0) {
        layout.addComponent(comp, idx);
    } else {
        layout.addComponent(comp, 0);
    }
    // Add component alignment if given
    if (dropAlignment != null) {
        layout.setComponentAlignment(comp, dropAlignment);
    }
}
Also used : HorizontalLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDHorizontalLayout.HorizontalLayoutTargetDetails) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation)

Example 18 with HorizontalDropLocation

use of com.vaadin.shared.ui.dd.HorizontalDropLocation in project cuba by cuba-platform.

the class DefaultHorizontalLayoutDropHandler method handleDropFromLayout.

/**
 * Handle a drop from another layout
 *
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    HorizontalLayoutTargetDetails details = (HorizontalLayoutTargetDetails) 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
    HorizontalDropLocation loc = (details).getDropLocation();
    if (loc == HorizontalDropLocation.CENTER || loc == HorizontalDropLocation.RIGHT) {
        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);
    }
}
Also used : HorizontalLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.v7.DDHorizontalLayout.HorizontalLayoutTargetDetails) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation)

Example 19 with HorizontalDropLocation

use of com.vaadin.shared.ui.dd.HorizontalDropLocation 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 20 with HorizontalDropLocation

use of com.vaadin.shared.ui.dd.HorizontalDropLocation 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

HorizontalDropLocation (com.vaadin.shared.ui.dd.HorizontalDropLocation)20 LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)7 VerticalDropLocation (com.vaadin.shared.ui.dd.VerticalDropLocation)5 Component (com.vaadin.ui.Component)5 Element (com.google.gwt.dom.client.Element)4 Widget (com.google.gwt.user.client.ui.Widget)4 HorizontalLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDHorizontalLayout.HorizontalLayoutTargetDetails)3 DDTabSheet (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet)3 TabSheetTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet.TabSheetTargetDetails)3 HorizontalLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.v7.DDHorizontalLayout.HorizontalLayoutTargetDetails)3 ComponentConnector (com.vaadin.client.ComponentConnector)3 MouseEventDetails (com.vaadin.shared.MouseEventDetails)3 DDCssLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout)2 CssLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout.CssLayoutTargetDetails)2 ComponentContainer (com.vaadin.ui.ComponentContainer)2 SingleComponentContainer (com.vaadin.ui.SingleComponentContainer)2 Style (com.google.gwt.dom.client.Style)1 UIObject (com.google.gwt.user.client.ui.UIObject)1 VCaption (com.vaadin.client.VCaption)1 Tab (com.vaadin.ui.TabSheet.Tab)1