Java源码示例:com.vaadin.client.ui.dd.VDragEvent

示例1
@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;
}
 
示例2
@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);
}
 
示例3
@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();
}
 
示例4
/**
 * 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;
}
 
示例5
@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);
}
 
示例6
@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);
}
 
示例7
/**
 * 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;
}
 
示例8
/**
 * 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());
    }
}
 
示例9
@Override
protected void dragAccepted(VDragEvent drag) {
    deEmphasis();
    currentTargetElement = drag.getElementOver();
    currentTargetDay = WidgetUtil.findWidget(currentTargetElement,
            DateCell.class);
    emphasis();
}
 
示例10
@Override
public void dragOver(final VDragEvent drag) {
    if (isLocationValid(drag.getElementOver())) {
        validate(new VAcceptCallback() {
            @Override
            public void accepted(VDragEvent event) {
                dragAccepted(drag);
            }
        }, drag);
    }
}
 
示例11
@Override
public boolean drop(VDragEvent drag) {
    if (isLocationValid(drag.getElementOver())) {
        updateDropDetails(drag);
        deEmphasis();
        return super.drop(drag);

    } else {
        deEmphasis();
        return false;
    }
}
 
示例12
/**
 * 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);
}
 
示例13
@Override
protected void dragAccepted(VDragEvent drag) {
    deEmphasis();
    currentTargetElement = drag.getElementOver();
    currentTargetDay = WidgetUtil.findWidget(currentTargetElement,
            SimpleDayCell.class);
    emphasis();
}
 
示例14
@Override
protected void updateDragDetails(VDragEvent event) {
    if (event == null) {
        return;
    }
    super.updateDragDetails(event);
}
 
示例15
@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);
}
 
示例16
@Override
public boolean drop(VDragEvent drag) {
    if (super.drop(drag)) {
        getLayout().updateDragDetails(drag);
        return getLayout().postDropHook(drag);
    }
    return false;
}
 
示例17
@Override
public void dragEnter(VDragEvent drag) {
    super.dragEnter(drag);
    getLayout().attachDragImageToLayout(drag);
    getLayout().updateDragDetails(drag);
    getLayout().postEnterHook(drag);
}
 
示例18
/**
 * 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());
}
 
示例19
@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);
}
 
示例20
@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);
}
 
示例21
@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());
    }
}
 
示例22
@Override
public boolean drop(VDragEvent drag) {

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

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

    return getLayout().postDropHook(drag);
}
 
示例23
/**
 * 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);
}
 
示例24
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;
}
 
示例25
/**
 * 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());
}
 
示例26
@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);
}
 
示例27
/**
 * 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);
    }
}
 
示例28
@Override
protected void dragAccepted(VDragEvent drag) {
    dragOver(drag);
}
 
示例29
@Override
public void dragLeave(VDragEvent drag) {
    getLayout().emphasis(null, drag);
    getLayout().postLeaveHook(drag);
}
 
示例30
@Override
public void dragLeave(VDragEvent drag) {
    deEmphasis();
    super.dragLeave(drag);
}