Search in sources :

Example 11 with VerticalDropLocation

use of com.vaadin.shared.ui.dd.VerticalDropLocation in project VaadinUtils by rlsutton1.

the class BaseCrudView method enableDragAndDropOrdering.

/**
 * allows the user to sort the items in the list via drag and drop
 *
 * @param ordinalField
 */
public void enableDragAndDropOrdering(final SingularAttribute<E, Long> ordinalField) {
    dragAndDropOrderingEnabled = true;
    this.ordinalField = ordinalField;
    container.sort(new Object[] { ordinalField.getName() }, new boolean[] { true });
    this.entityTable.setDragMode(TableDragMode.ROW);
    this.entityTable.setDropHandler(new DropHandler() {

        private static final long serialVersionUID = -6024948983201516170L;

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return SourceIsTarget.get();
        }

        @SuppressWarnings("unchecked")
        @Override
        public void drop(DragAndDropEvent event) {
            if (isDirty()) {
                Notification.show("You must save first", Type.WARNING_MESSAGE);
                return;
            }
            Object draggedItemId = event.getTransferable().getData("itemId");
            EntityItem<E> dragged = container.getItem(draggedItemId);
            if (dragged != null) {
                EntityItemProperty draggedOrdinalProp = dragged.getItemProperty(ordinalField.getName());
                if (draggedOrdinalProp != null) {
                    AbstractSelectTargetDetails td = (AbstractSelectTargetDetails) event.getTargetDetails();
                    VerticalDropLocation dl = td.getDropLocation();
                    Object targetId = ((AbstractSelectTargetDetails) event.getTargetDetails()).getItemIdOver();
                    int idx = container.indexOfId(targetId);
                    if (dl == VerticalDropLocation.BOTTOM) {
                        // drop below so move the idx down one
                        idx++;
                    }
                    if (idx > -1) {
                        targetId = container.getIdByIndex(idx);
                    }
                    boolean added = false;
                    Long ctr = 1l;
                    for (Object id : container.getItemIds()) {
                        if (id.equals(targetId)) {
                            draggedOrdinalProp.setValue(ctr++);
                            added = true;
                        }
                        if (!id.equals(draggedItemId)) {
                            container.getItem(id).getItemProperty(ordinalField.getName()).setValue(ctr++);
                        }
                    }
                    if (!added) {
                        draggedOrdinalProp.setValue(ctr++);
                    }
                    container.commit();
                    if (dragAndDropListener != null) {
                        dragAndDropListener.dropped();
                    }
                    // to save.
                    try {
                        invokeTopLevelCrudSave();
                    } catch (Exception e) {
                        ErrorWindow.showErrorWindow(e);
                    }
                } else {
                    logger.error("draggedOrdinalProp is null");
                }
            } else {
                logger.error("dragged is null");
            }
        }
    });
}
Also used : AbstractSelectTargetDetails(com.vaadin.ui.AbstractSelect.AbstractSelectTargetDetails) VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) DragAndDropEvent(com.vaadin.event.dd.DragAndDropEvent) EntityItemProperty(com.vaadin.addon.jpacontainer.EntityItemProperty) CommitException(com.vaadin.data.fieldgroup.FieldGroup.CommitException) EntityNotFoundException(javax.persistence.EntityNotFoundException) InvalidValueException(com.vaadin.data.Validator.InvalidValueException) OptimisticLockException(javax.persistence.OptimisticLockException) ExecutionException(java.util.concurrent.ExecutionException) DropHandler(com.vaadin.event.dd.DropHandler) EntityItem(com.vaadin.addon.jpacontainer.EntityItem) AcceptCriterion(com.vaadin.event.dd.acceptcriteria.AcceptCriterion)

Example 12 with VerticalDropLocation

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

the class VDDGridLayout method getVerticalDropLocation.

/**
 * Returns the vertical drop location
 *
 * @param cell
 *            The cell details
 * @param event
 *            The drag event
 * @return
 */
protected VerticalDropLocation getVerticalDropLocation(CellDetails cell, VDragEvent event) {
    // Get the vertical location
    VerticalDropLocation vdetail;
    int y = Util.getTouchOrMouseClientY(event.getCurrentGwtEvent()) - getAbsoluteTop() - cell.y;
    assert (y >= 0 && y <= cell.height);
    if (y < cell.height * cellTopBottomDropRatio) {
        vdetail = VerticalDropLocation.TOP;
    } else if (y < cell.height * (1.0 - cellTopBottomDropRatio)) {
        vdetail = VerticalDropLocation.MIDDLE;
    } else {
        vdetail = VerticalDropLocation.BOTTOM;
    }
    return vdetail;
}
Also used : VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation)

Example 13 with VerticalDropLocation

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

the class VDDFormLayout method emphasis.

/**
 * Empasises the drop location of the component when hovering over a
 * ĆhildComponentContainer. Passing null as the container removes any
 * previous emphasis.
 *
 * @param widget
 *            The container which we are hovering over
 * @param event
 *            The drag event
 */
protected void emphasis(Widget widget, VDragEvent event) {
    // Remove emphasis from previous hovers
    deEmphasis();
    // Validate
    if (widget == null || !getElement().isOrHasChild(widget.getElement())) {
        return;
    }
    /*
         * Get row for widget
         */
    Element rowElement = getRowFromChildElement(widget.getElement(), VDDFormLayout.this.getElement());
    currentlyEmphasised = rowElement;
    if (rowElement != this.getElement()) {
        VerticalDropLocation vl = getVerticalDropLocation(rowElement, event);
        setStyleName(rowElement, OVER + "-" + vl.toString().toLowerCase(), true);
    } else {
        setStyleName(rowElement, OVER, true);
    }
}
Also used : VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) Element(com.google.gwt.dom.client.Element)

Example 14 with VerticalDropLocation

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

the class VDDVerticalSplitPanel method updateDragDetails.

/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 *
 * @param event
 *            The drag event
 */
protected void updateDragDetails(VDragEvent event) {
    Element over = event.getElementOver();
    // Resolve where the drop was made
    VerticalDropLocation location = null;
    Widget content = null;
    if (firstContainer.isOrHasChild(over)) {
        location = VerticalDropLocation.TOP;
        content = Util.findWidget(firstContainer, null);
    } else if (splitter.isOrHasChild(over)) {
        location = VerticalDropLocation.MIDDLE;
        content = this;
    } else if (secondContainer.isOrHasChild(over)) {
        location = VerticalDropLocation.BOTTOM;
        content = Util.findWidget(secondContainer, null);
    }
    event.getDropDetails().put(Constants.DROP_DETAIL_VERTICAL_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());
}
Also used : VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) MouseEventDetails(com.vaadin.shared.MouseEventDetails) Element(com.google.gwt.user.client.Element) Widget(com.google.gwt.user.client.ui.Widget)

Example 15 with VerticalDropLocation

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

the class VDDVerticalLayout method emphasis.

/**
 * Empasises the drop location of the component when hovering over a
 * ĆhildComponentContainer. Passing null as the container removes any
 * previous emphasis.
 *
 * @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;
    VerticalDropLocation location = null;
    // Add drop location specific style
    if (currentlyEmphasised != this) {
        location = getVerticalDropLocation(currentlyEmphasised, event);
    } else {
        location = VerticalDropLocation.MIDDLE;
    }
    UIObject.setStyleName(currentlyEmphasised.getElement(), OVER, true);
    UIObject.setStyleName(currentlyEmphasised.getElement(), OVER + "-" + location.toString().toLowerCase(), true);
}
Also used : VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation)

Aggregations

VerticalDropLocation (com.vaadin.shared.ui.dd.VerticalDropLocation)25 Component (com.vaadin.ui.Component)13 LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)9 AbstractOrderedLayout (com.vaadin.ui.AbstractOrderedLayout)8 HorizontalDropLocation (com.vaadin.shared.ui.dd.HorizontalDropLocation)5 ComponentContainer (com.vaadin.ui.ComponentContainer)5 SingleComponentContainer (com.vaadin.ui.SingleComponentContainer)5 DDAccordion (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAccordion)3 FormLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDFormLayout.FormLayoutTargetDetails)3 VerticalLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDVerticalLayout.VerticalLayoutTargetDetails)3 AccordionTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AccordionTargetDetails)3 VerticalLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.v7.DDVerticalLayout.VerticalLayoutTargetDetails)3 ComponentConnector (com.vaadin.client.ComponentConnector)3 MouseEventDetails (com.vaadin.shared.MouseEventDetails)3 Element (com.google.gwt.dom.client.Element)2 Widget (com.google.gwt.user.client.ui.Widget)2 DDCssLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout)2 CssLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout.CssLayoutTargetDetails)2 Style (com.google.gwt.dom.client.Style)1 Element (com.google.gwt.user.client.Element)1