Example usage for com.vaadin.shared.ui.dd HorizontalDropLocation CENTER

List of usage examples for com.vaadin.shared.ui.dd HorizontalDropLocation CENTER

Introduction

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

Prototype

HorizontalDropLocation CENTER

To view the source code for com.vaadin.shared.ui.dd HorizontalDropLocation CENTER.

Click Source Link

Usage

From source file:com.foc.vaadin.gui.layouts.FVHorizontal_WYSIWYG_DropHandler.java

License:Apache License

@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();

    // Detach//from w  w  w . j  a v a2 s.c  o m
    if (layout != null && comp != null)
        layout.removeComponent(comp);
    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++;
    }

    if (comp != null) {
        AttributesImpl newAttributes = removeNotNeededAttributes(((FocXMLGuiComponent) comp).getAttributes(),
                (FVLayout) comp.getParent());

        if (newAttributes.getIndex(FXML.ATT_IDX) != -1) {
            newAttributes.setValue(newAttributes.getIndex("idx"), idx + "");
        } else {
            newAttributes.addAttribute("", FXML.ATT_IDX, FXML.ATT_IDX, "CDATA", idx + "");
        }

        ((FocXMLGuiComponent) comp).setAttributes(newAttributes);

        // Add component
        if (layout != null) {
            if (idx >= 0) {
                layout.addComponent(comp, idx);
            } else {
                layout.addComponent(comp);
            }
        }

        if (comp instanceof FVLayout) {
            Globals.logString("Here3");
            ((FVLayout) comp).setDragDrop(true);
        }

        // Add component alignment if given
        if (dropAlignment != null && layout != null && comp != null) {
            layout.setComponentAlignment(comp, dropAlignment);
        }
    }
}

From source file:com.foc.vaadin.gui.layouts.FVHorizontal_WYSIWYG_DropHandler.java

License:Apache License

@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// w  w  w  . j  a  v  a2 s.  c  om
    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.

    ComponentContainer sourceLayout = null;

    if (source instanceof ComponentContainer) {
        sourceLayout = (ComponentContainer) source;
        sourceLayout.removeComponent(comp);
    }

    // Increase index if component is dropped after or above a
    // previous
    // component
    HorizontalDropLocation loc = (details).getDropLocation();

    if (loc == HorizontalDropLocation.CENTER || loc == HorizontalDropLocation.RIGHT) {
        idx++;
    }

    AttributesImpl newAttributes = removeNotNeededAttributes(((FocXMLGuiComponent) comp).getAttributes(),
            (FVLayout) sourceLayout);

    if (newAttributes.getIndex(FXML.ATT_IDX) > -1) {
        newAttributes.setValue(newAttributes.getIndex(FXML.ATT_IDX), idx + "");
    }

    ((FocXMLGuiComponent) comp).setAttributes(newAttributes);

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

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

License:Apache License

/**
 * Called when a component changed location within the layout
 * //w  ww  . j a v a 2  s .  co m
 * @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);
    }
}

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

License:Apache License

/**
 * Handle a drop from another layout//from   w w  w .  j a  v  a2  s .c  om
 * 
 * @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);
    }
}

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

License:Apache License

@Override
protected void handleHTML5Drop(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();

    // Increase index if component is dropped after or above a
    // previous component
    HorizontalDropLocation loc = (details).getDropLocation();
    if (loc == HorizontalDropLocation.CENTER || loc == HorizontalDropLocation.RIGHT) {
        idx++;// w  w  w  .java2s .c om
    }

    Component comp = resolveComponentFromHTML5Drop(event);

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

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.gridlayout.VDDGridLayout.java

License:Apache License

/**
 * Returns the horizontal drop location//from   www.java 2s.  c  o m
 * 
 * @param cell
 *            The cell details
 * @param event
 *            The drag event
 * @return
 */
protected HorizontalDropLocation getHorizontalDropLocation(CellDetails cell, VDragEvent event) {

    // Get the horizontal location
    HorizontalDropLocation hdetail;
    int x = Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()) - getAbsoluteLeft() - cell.x;

    assert (x >= 0 && x <= cell.width);

    if (x < cell.width * cellLeftRightDropRatio) {
        hdetail = HorizontalDropLocation.LEFT;
    } else if (x < cell.width * (1.0 - cellLeftRightDropRatio)) {
        hdetail = HorizontalDropLocation.CENTER;
    } else {
        hdetail = HorizontalDropLocation.RIGHT;
    }
    return hdetail;
}

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.gridlayout.VDDGridLayout.java

License:Apache License

/**
 * Removes any emphasis previously set by emphasis
 *//* w w w .  j av  a 2s  . co m*/
protected void deEmphasis() {

    setStyleName(dragShadow.getElement(), OVER, false);

    // Horizontal styles
    setStyleName(dragShadow.getElement(), OVER + "-" + HorizontalDropLocation.LEFT.toString().toLowerCase(),
            false);
    setStyleName(dragShadow.getElement(), OVER + "-" + HorizontalDropLocation.CENTER.toString().toLowerCase(),
            false);
    setStyleName(dragShadow.getElement(), OVER + "-" + HorizontalDropLocation.RIGHT.toString().toLowerCase(),
            false);

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

}

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.horizontallayout.VDDHorizontalLayout.java

License:Apache License

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

        // Horizontal styles
        setStyleName(currentlyEmphasised.getElement(),
                OVER + "-" + HorizontalDropLocation.LEFT.toString().toLowerCase(), false);
        setStyleName(currentlyEmphasised.getElement(),
                OVER + "-" + HorizontalDropLocation.CENTER.toString().toLowerCase(), false);
        setStyleName(currentlyEmphasised.getElement(),
                OVER + "-" + HorizontalDropLocation.RIGHT.toString().toLowerCase(), false);

        currentlyEmphasised = null;
    }
}

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.horizontallayout.VDDHorizontalLayout.java

License:Apache License

/**
 * Empasises the drop location of the component when hovering over a
 * hildComponentContainer. Passing null as the container removes any
 * previous emphasis./*from w  ww . j  a  v  a 2  s.c  o  m*/
 * 
 * @param container
 *            The container which we are hovering over
 * @param event
 *            The drag event
 */
protected void emphasis(Widget container, VDragEvent event) {

    // Remove emphasis from previous hovers
    deEmphasis();

    // validate container
    if (container == null || !getElement().isOrHasChild(container.getElement())) {
        return;
    }

    currentlyEmphasised = container;

    HorizontalDropLocation location = null;

    // Add drop location specific style
    if (currentlyEmphasised != this) {
        location = getHorizontalDropLocation(container, event);

    } else {
        location = HorizontalDropLocation.CENTER;
    }

    setStyleName(currentlyEmphasised.getElement(), OVER, true);
    setStyleName(currentlyEmphasised.getElement(), OVER + "-" + location.toString().toLowerCase(), true);
}

From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.horizontalsplitpanel.VDDHorizontalSplitPanel.java

License:Apache License

/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 * /*ww  w .  j av a2s . c o  m*/
 * @param event
 *            The drag event
 */
protected void updateDragDetails(VDragEvent event) {
    Element over = event.getElementOver();
    if (over == null) {
        return;
    }

    // Resolve where the drop was made
    HorizontalDropLocation location = null;
    Widget content = null;
    if (firstContainer.isOrHasChild(over)) {
        location = HorizontalDropLocation.LEFT;
        content = Util.findWidget(firstContainer, null);
    } else if (splitter.isOrHasChild(over)) {
        location = HorizontalDropLocation.CENTER;
        content = this;
    } else if (secondContainer.isOrHasChild(over)) {
        location = HorizontalDropLocation.RIGHT;
        content = Util.findWidget(secondContainer, null);
    }

    event.getDropDetails().put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION, location);

    if (content != null) {
        event.getDropDetails().put(Constants.DROP_DETAIL_OVER_CLASS, content.getClass().getName());
    } else {
        event.getDropDetails().put(Constants.DROP_DETAIL_OVER_CLASS, this.getClass().getName());
    }

    // Add mouse event details
    MouseEventDetails details = MouseEventDetailsBuilder.buildMouseEventDetails(event.getCurrentGwtEvent(),
            getElement());
    event.getDropDetails().put(Constants.DROP_DETAIL_MOUSE_EVENT, details.serialize());
}