com.vaadin.client.ui.dd.VDragEvent Java Examples

The following examples show how to use com.vaadin.client.ui.dd.VDragEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VDDGridLayoutDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void dragOver(VDragEvent drag) {

    // Remove emphasis from previous selection
    getLayout().deEmphasis();

    // Update the drop details so we can then validate them
    getLayout().updateDragDetails(drag);

    getLayout().postOverHook(drag);

    // Emphasis drop location
    validate(new VAcceptCallback() {
        public void accepted(VDragEvent event) {
            CellDetails cd = getLayout().getCellDetails(event);
            if (cd != null) {
                getLayout().emphasis(cd, event);
            }
        }
    }, drag);
}
 
Example #2
Source File: ItemIdClientCriterion.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
// Exception squid:S1166 - Hide origin exception
// Exception squid:S2221 - This code is trans-coded to JavaScript, hence
// Exception semantics changes
@SuppressWarnings({ "squid:S1166", "squid:S2221" })
protected boolean accept(VDragEvent drag, UIDL configuration) {
    try {

        String component = drag.getTransferable().getDragSource().getWidget().getElement().getId();
        int c = configuration.getIntAttribute(COMPONENT_COUNT);
        String mode = configuration.getStringAttribute(MODE);
        for (int dragSourceIndex = 0; dragSourceIndex < c; dragSourceIndex++) {
            String requiredPid = configuration.getStringAttribute(COMPONENT + dragSourceIndex);
            if ((STRICT_MODE.equals(mode) && component.equals(requiredPid))
                    || (PREFIX_MODE.equals(mode) && component.startsWith(requiredPid))) {
                return true;
            }

        }
    } catch (Exception e) {
        // log and continue
        LOGGER.log(Level.SEVERE, "Error verifying drop target: " + e.getLocalizedMessage());
    }
    return false;
}
 
Example #3
Source File: VDDVerticalSplitPanelDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void dragOver(VDragEvent drag) {

    getLayout().deEmphasis();

    getLayout().updateDragDetails(drag);

    getLayout().postOverHook(drag);

    ComponentConnector widgetConnector = (ComponentConnector) drag
            .getTransferable()
            .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);

    if (widgetConnector != null
            && getLayout().equals(widgetConnector.getWidget())) {
        return;
    }

    // Validate the drop
    validate(new VAcceptCallback() {
        public void accepted(VDragEvent event) {
            getLayout().emphasis(event.getElementOver());
        }
    }, drag);
}
 
Example #4
Source File: ItemIdClientCriterionTest.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Test
@Description("Verifies that drag source is valid for the configured id (strict mode)")
public void matchInStrictMode() {
    final ItemIdClientCriterion cut = new ItemIdClientCriterion();

    // prepare drag-event:
    final String testId = "thisId";
    final VDragEvent dragEvent = CriterionTestHelper.createMockedVDragEvent(testId);

    // prepare configuration:
    final UIDL uidl = GWT.create(UIDL.class);
    final String configuredId = "component0";
    final String id = "thisId";
    when(uidl.getStringAttribute(configuredId)).thenReturn(id);
    final String configuredMode = "m";
    final String strictMode = "s";
    when(uidl.getStringAttribute(configuredMode)).thenReturn(strictMode);
    final String count = "c";
    when(uidl.getIntAttribute(count)).thenReturn(1);

    // act
    final boolean result = cut.accept(dragEvent, uidl);

    // verify that in strict mode: [thisId equals thisId]
    assertThat(result).as("Expected: [" + id + " equals " + testId + "].").isTrue();
}
 
Example #5
Source File: VDDGridLayout.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: ViewClientCriterionTest.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Test
@Description("Check multi row drag decoration with non-table widget")
public void processMultiRowDragDecorationNonTable() {
    final ViewClientCriterion cut = new ViewClientCriterion();

    // prepare drag-event with non table widget:
    final VDragAndDropWrapper nonTable = Mockito.mock(VDragAndDropWrapper.class);
    final VDragEvent dragEvent = CriterionTestHelper.createMockedVDragEvent("thisId", nonTable);
    final Document document = Document.get();

    // act
    cut.setMultiRowDragDecoration(dragEvent);

    // assure that multi-row decoration processing was skipped
    verify(document, Mockito.never()).getElementById(ViewClientCriterion.SP_DRAG_COUNT);
}
 
Example #7
Source File: VDDAccordion.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the drop location of a tab
 * 
 * @param tab
 *            The tab that was dragged
 * @param event
 *            The drag event
 * @return
 */
protected VerticalDropLocation getDropLocation(StackItem tab,
        VDragEvent event) {
    VerticalDropLocation location;
    if (tab.isOpen()) {
        location = VDragDropUtil.getVerticalDropLocation(tab.getElement(),
                Util.getTouchOrMouseClientY(event.getCurrentGwtEvent()),
                tabTopBottomDropRatio);
    } else {
        location = VDragDropUtil
                .getVerticalDropLocation(tab.getWidget(0).getElement(),
                        Util.getTouchOrMouseClientY(
                                event.getCurrentGwtEvent()),
                tabTopBottomDropRatio);
    }
    return location;
}
 
Example #8
Source File: VDDAccordion.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * 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) {
    if (event.getElementOver() == null) {
        return;
    }

    StackItem tab = WidgetUtil.findWidget(event.getElementOver(),
            StackItem.class);

    if (tab != null && getElement().isOrHasChild(tab.getElement())) {
        Map<String, Object> dropDetails = event.getDropDetails();

        int index = getTabPosition(tab);
        dropDetails.put(Constants.DROP_DETAIL_TO, index);

        VerticalDropLocation location = getDropLocation(tab, event);
        dropDetails.put(Constants.DROP_DETAIL_VERTICAL_DROP_LOCATION,
                location);

        MouseEventDetails details = MouseEventDetailsBuilder
                .buildMouseEventDetails(event.getCurrentGwtEvent(),
                        getElement());
        dropDetails.put(Constants.DROP_DETAIL_MOUSE_EVENT,
                details.serialize());
    }
}
 
Example #9
Source File: CalendarWeekDropHandler.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
/**
 * Update the drop details sent to the server
 *
 * @param drag
 *            The drag event
 */
private void updateDropDetails(VDragEvent drag) {
    int slotIndex = currentTargetDay.getSlotIndex(currentTargetElement);
    int dayIndex = calendarConnector.getWidget().getWeekGrid()
            .getDateCellIndex(currentTargetDay);

    drag.getDropDetails().put("dropDayIndex", dayIndex);
    drag.getDropDetails().put("dropSlotIndex", slotIndex);
}
 
Example #10
Source File: VDDHorizontalLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void dragEnter(VDragEvent drag) {
    super.dragEnter(drag);
    Slot slot = getSlot(drag.getElementOver(), drag.getCurrentGwtEvent());
    if (slot != null) {
        getLayout().updateDragDetails(slot, drag);
    } else {
        getLayout().updateDragDetails(getLayout(), drag);
    }

    getLayout().postEnterHook(drag);
}
 
Example #11
Source File: CalendarMonthDropHandler.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
@Override
protected void dragAccepted(VDragEvent drag) {
    deEmphasis();
    currentTargetElement = drag.getElementOver();
    currentTargetDay = WidgetUtil.findWidget(currentTargetElement,
            SimpleDayCell.class);
    emphasis();
}
 
Example #12
Source File: VDDVerticalLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void dragEnter(VDragEvent drag) {
    super.dragEnter(drag);
    Slot slot = getSlot(drag.getElementOver(), drag.getCurrentGwtEvent());
    if (slot != null) {
        getLayout().updateDragDetails(slot, drag);
    } else {
        getLayout().updateDragDetails(getLayout(), drag);
    }
    getLayout().postEnterHook(drag);
}
 
Example #13
Source File: CubaMainTabSheetWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void updateDragDetails(VDragEvent event) {
    if (event == null) {
        return;
    }
    super.updateDragDetails(event);
}
 
Example #14
Source File: VDDAbsoluteLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public boolean drop(VDragEvent drag) {
    if (super.drop(drag)) {
        getLayout().updateDragDetails(drag);
        return getLayout().postDropHook(drag);
    }
    return false;
}
 
Example #15
Source File: CalendarWeekDropHandler.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
@Override
public void dragOver(final VDragEvent drag) {
    if (isLocationValid(drag.getElementOver())) {
        validate(new VAcceptCallback() {
            @Override
            public void accepted(VDragEvent event) {
                dragAccepted(drag);
            }
        }, drag);
    }
}
 
Example #16
Source File: CalendarWeekDropHandler.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
@Override
public boolean drop(VDragEvent drag) {
    if (isLocationValid(drag.getElementOver())) {
        updateDropDetails(drag);
        deEmphasis();
        return super.drop(drag);

    } else {
        deEmphasis();
        return false;
    }
}
 
Example #17
Source File: VDDCssLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void dragEnter(VDragEvent drag) {
    super.dragEnter(drag);
    getLayout().attachDragImageToLayout(drag);
    getLayout().updateDragDetails(drag);
    getLayout().postEnterHook(drag);
}
 
Example #18
Source File: VDDHorizontalLayout.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 * 
 * @param widget
 *            The container which we are hovering over
 * @param event
 *            The drag event
 */
protected void updateDragDetails(Widget widget, VDragEvent event) {
    if (widget == null) {
        return;
    }

    /*
     * The horizontal position within the cell{
     */
    event.getDropDetails().put(
            Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION,
            getHorizontalDropLocation(widget, event));

    /*
     * The index over which the drag is. Can be used by a client side
     * criteria to verify that a drag is over a certain index.
     */
    int index = -1;
    if (widget instanceof Slot) {
        WidgetCollection captionsAndSlots = getChildren();
        index = VDragDropUtil.findSlotIndex(captionsAndSlots,
                (Slot) widget);
    }

    event.getDropDetails().put(Constants.DROP_DETAIL_TO, index);

    // Add mouse event details
    MouseEventDetails details = MouseEventDetailsBuilder
            .buildMouseEventDetails(event.getCurrentGwtEvent(),
                    getElement());
    event.getDropDetails().put(Constants.DROP_DETAIL_MOUSE_EVENT,
            details.serialize());
}
 
Example #19
Source File: VDDFormLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void dragEnter(VDragEvent drag) {
    getLayout().emphasis(null, null);

    Widget c = getTableRowWidgetFromDragEvent(drag);
    if (c != null) {
        getLayout().updateDragDetails(c, drag);
    } else {
        getLayout().updateDragDetails(getLayout(), drag);
    }

    getLayout().postEnterHook(drag);

    super.dragEnter(drag);
}
 
Example #20
Source File: ViewClientCriterionTest.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@Description("Check multi row drag decoration with a single item dragged while a multi selection is active in table")
public void processMultiRowDragDecorationMultiSelectionNotDragged() {
    final ViewClientCriterion cut = new ViewClientCriterion();

    // prepare table
    final VScrollTable table = Mockito.spy(new VScrollTable());
    table.selectedRowKeys.add("one");
    table.selectedRowKeys.add("two");
    table.focusedRow = Mockito.mock(VScrollTable.VScrollTableBody.VScrollTableRow.class);
    when(table.focusedRow.getKey()).thenReturn("another");

    // prepare drag-event with table widget:
    final VDragEvent dragEvent = CriterionTestHelper.createMockedVDragEvent("thisId", table);

    // prepare document
    final Document document = Document.get();
    final Element ele = Mockito.mock(Element.class);
    when(document.getElementById(ViewClientCriterion.SP_DRAG_COUNT)).thenReturn(ele);

    try {
        // act
        cut.setMultiRowDragDecoration(dragEvent);

        // assure that multi-row decoration for the table was processed
        verify(document).getElementById(ViewClientCriterion.SP_DRAG_COUNT);

        // assure that no multi selection was detected
        verify(ele).removeFromParent();
    } finally {
        reset(Document.get());
    }
}
 
Example #21
Source File: CalendarWeekDropHandler.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
@Override
protected void dragAccepted(VDragEvent drag) {
    deEmphasis();
    currentTargetElement = drag.getElementOver();
    currentTargetDay = WidgetUtil.findWidget(currentTargetElement,
            DateCell.class);
    emphasis();
}
 
Example #22
Source File: VDDGridLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public boolean drop(VDragEvent drag) {

    // Update the detail of the drop
    getLayout().updateDragDetails(drag);

    // Remove emphasis
    getLayout().deEmphasis();

    return getLayout().postDropHook(drag);
}
 
Example #23
Source File: VDDHorizontalLayout.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * 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;

    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);
}
 
Example #24
Source File: CriterionTestHelper.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
static VDragEvent createMockedVDragEvent(String dragSourceId, Widget widget) {
    com.google.gwt.user.client.Element element = Mockito.mock(com.google.gwt.user.client.Element.class);
    when(element.getId()).thenReturn(dragSourceId);
    when(widget.getElement()).thenReturn(element);
    ComponentConnector dragSource = Mockito.mock(ComponentConnector.class);
    when(dragSource.getWidget()).thenReturn(widget);
    VTransferable transferable = Mockito.mock(VTransferable.class);
    when(transferable.getDragSource()).thenReturn(dragSource);
    VDragEvent dragEvent = Mockito.mock(VDragEvent.class);
    when(dragEvent.getTransferable()).thenReturn(transferable);

    return dragEvent;
}
 
Example #25
Source File: VDDVerticalSplitPanel.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example #26
Source File: VDDVerticalSplitPanelDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public boolean drop(VDragEvent drag) {

    // Un-emphasis any selections
    getLayout().deEmphasis();

    // Update the details
    getLayout().updateDragDetails(drag);
    return getLayout().postDropHook(drag) && super.drop(drag);
}
 
Example #27
Source File: VDDFormLayout.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #28
Source File: VDDPanelDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected void dragAccepted(VDragEvent drag) {
    dragOver(drag);
}
 
Example #29
Source File: VDDFormLayoutDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected void dragAccepted(VDragEvent drag) {
    dragOver(drag);
}
 
Example #30
Source File: VDDAccordionDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public void dragEnter(VDragEvent drag) {
    super.dragEnter(drag);
    getLayout().updateDragDetails(drag);
    getLayout().postEnterHook(drag);
}