Search in sources :

Example 56 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project openremote by openremote.

the class PopupPanel method previewNativeEvent.

/**
 * Preview the {@link NativePreviewEvent}.
 *
 * @param event the {@link NativePreviewEvent}
 */
private void previewNativeEvent(NativePreviewEvent event) {
    // If the event has been canceled or consumed, ignore it
    if (event.isCanceled() || (!previewAllNativeEvents && event.isConsumed())) {
        // that popups lower on the stack do not auto hide
        if (modal) {
            event.cancel();
        }
        return;
    }
    // Fire the event hook and return if the event is canceled
    onPreviewNativeEvent(event);
    if (event.isCanceled()) {
        return;
    }
    // If the event targets the popup or the partner, consume it
    Event nativeEvent = Event.as(event.getNativeEvent());
    boolean eventTargetsPopupOrPartner = eventTargetsPopup(nativeEvent) || eventTargetsPartner(nativeEvent);
    if (eventTargetsPopupOrPartner) {
        event.consume();
    }
    // event can be both canceled and consumed.
    if (modal) {
        event.cancel();
    }
    // Switch on the event type
    int type = nativeEvent.getTypeInt();
    switch(type) {
        case Event.ONKEYDOWN:
            {
                if (!onKeyDownPreview((char) nativeEvent.getKeyCode(), KeyboardListenerCollection.getKeyboardModifiers(nativeEvent))) {
                    event.cancel();
                }
                return;
            }
        case Event.ONKEYUP:
            {
                if (!onKeyUpPreview((char) nativeEvent.getKeyCode(), KeyboardListenerCollection.getKeyboardModifiers(nativeEvent))) {
                    event.cancel();
                }
                return;
            }
        case Event.ONKEYPRESS:
            {
                if (!onKeyPressPreview((char) nativeEvent.getKeyCode(), KeyboardListenerCollection.getKeyboardModifiers(nativeEvent))) {
                    event.cancel();
                }
                return;
            }
        case Event.ONMOUSEDOWN:
        case Event.ONTOUCHSTART:
            // interfere with dialog dragging, for example.
            if (DOM.getCaptureElement() != null) {
                event.consume();
                return;
            }
            if (!eventTargetsPopupOrPartner && autoHide) {
                hide(true);
                return;
            }
            break;
        case Event.ONMOUSEUP:
        case Event.ONMOUSEMOVE:
        case Event.ONCLICK:
        case Event.ONDBLCLICK:
        case Event.ONTOUCHEND:
            {
                // interfere with dialog dragging, for example.
                if (DOM.getCaptureElement() != null) {
                    event.consume();
                    return;
                }
                break;
            }
        case Event.ONFOCUS:
            {
                Element target = nativeEvent.getTarget();
                if (modal && !eventTargetsPopupOrPartner && (target != null)) {
                    blur(target);
                    event.cancel();
                    return;
                }
                break;
            }
    }
}
Also used : Element(com.google.gwt.dom.client.Element) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) NativeEvent(com.google.gwt.dom.client.NativeEvent) CloseEvent(com.google.gwt.event.logical.shared.CloseEvent) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) ResizeEvent(com.google.gwt.event.logical.shared.ResizeEvent)

Example 57 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project ovirt-engine by oVirt.

the class DraggableVirtualNumaPanel method onDragStart.

@UiHandler("container")
void onDragStart(DragStartEvent event) {
    if (!dragEnabled) {
        return;
    }
    // IE strikes again, for some unknown reason, in IE you can only put 'Text' as the setData first
    // parameter. So if you want to pass multiple values, you have to collect them in one string, then parse
    // the string on the other end instead of passing different values.
    // $NON-NLS-1$
    String aggregatedString = "VM_GID=" + nodeModel.getVm().getId().toString();
    // $NON-NLS-1$
    aggregatedString += "|PINNED=" + String.valueOf(nodeModel.isPinned());
    // $NON-NLS-1$
    aggregatedString += "|INDEX=" + String.valueOf(nodeModel.getIndex());
    // $NON-NLS-1$
    event.setData("Text", aggregatedString);
    // show a ghost of the widget under cursor.
    NativeEvent nativeEvent = event.getNativeEvent();
    int x = nativeEvent.getClientX() - getAbsoluteLeft();
    int y = nativeEvent.getClientY() - getAbsoluteTop();
    event.getDataTransfer().setDragImage(getElement(), x, y);
}
Also used : NativeEvent(com.google.gwt.dom.client.NativeEvent) UiHandler(com.google.gwt.uibinder.client.UiHandler)

Example 58 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project ovirt-engine by oVirt.

the class ColumnResizeHandler method onPreviewNativeEvent.

@Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
    NativeEvent nativeEvent = event.getNativeEvent();
    nativeEvent.preventDefault();
    nativeEvent.stopPropagation();
    if (BrowserEvents.MOUSEMOVE.equals(nativeEvent.getType())) {
        // Calculate display-relative column width
        int clientX = nativeEvent.getClientX();
        int displayColumnWidth = clientX - columnAbsoluteLeft + DRAG_AREA_OFFSET;
        // Adjust column width as necessary
        int minimumColumnWidth = table.getMinimumColumnWidth(column);
        displayColumnWidth = displayColumnWidth < minimumColumnWidth ? minimumColumnWidth : displayColumnWidth;
        // Resize the column
        table.resizeColumn(column, displayColumnWidth);
    } else if (BrowserEvents.MOUSEUP.equals(nativeEvent.getType())) {
        // Release native event handler
        eventHandler.removeHandler();
        // Indicate resize end
        table.onResizeEnd(column, headerElement);
    }
}
Also used : NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 59 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project kie-wb-common by kiegroup.

the class YearsMonthsSelectorViewTest method testOnYearsInputBlur.

@Test
public void testOnYearsInputBlur() {
    final BlurEvent blurEvent = mock(BlurEvent.class);
    final NativeEvent nativeEvent = mock(NativeEvent.class);
    final EventTarget eventTarget = mock(EventTarget.class);
    when(blurEvent.getNativeEvent()).thenReturn(nativeEvent);
    when(nativeEvent.getRelatedEventTarget()).thenReturn(eventTarget);
    view.onYearsInputBlur(blurEvent);
    verify(view).handle(blurEvent);
}
Also used : BlurEvent(com.google.gwt.event.dom.client.BlurEvent) EventTarget(com.google.gwt.dom.client.EventTarget) NativeEvent(com.google.gwt.dom.client.NativeEvent) Test(org.junit.Test)

Example 60 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project kie-wb-common by kiegroup.

the class DecisionNavigatorTreeViewTest method testTreeItemOnInputTextKeyPressWhenKeyIsNotEnter.

@Test
public void testTreeItemOnInputTextKeyPressWhenKeyIsNotEnter() {
    final KeyDownEvent event = mock(KeyDownEvent.class);
    final NativeEvent nativeEvent = mock(NativeEvent.class);
    when(event.getNativeEvent()).thenReturn(nativeEvent);
    when(nativeEvent.getKeyCode()).thenReturn(99);
    treeItem.onInputTextKeyPress(event);
    verify(treeItem, never()).save();
}
Also used : KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) NativeEvent(com.google.gwt.dom.client.NativeEvent) Test(org.junit.Test)

Aggregations

NativeEvent (com.google.gwt.dom.client.NativeEvent)72 Element (com.google.gwt.dom.client.Element)20 Test (org.junit.Test)12 Column (com.google.gwt.user.cellview.client.Column)8 ValueUpdater (com.google.gwt.cell.client.ValueUpdater)6 EventTarget (com.google.gwt.dom.client.EventTarget)6 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)5 MonacoStandaloneCodeEditor (org.uberfire.client.views.pfly.monaco.jsinterop.MonacoStandaloneCodeEditor)5 AbstractCell (com.google.gwt.cell.client.AbstractCell)4 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)4 Context (com.google.gwt.cell.client.Cell.Context)3 JsArrayString (com.google.gwt.core.client.JsArrayString)3 Scheduler (com.google.gwt.core.client.Scheduler)3 Style (com.google.gwt.dom.client.Style)3 TableRowElement (com.google.gwt.dom.client.TableRowElement)3 BlurEvent (com.google.gwt.event.dom.client.BlurEvent)3 Widget (com.google.gwt.user.client.ui.Widget)3 HTMLButtonElement (elemental2.dom.HTMLButtonElement)3 Button (org.gwtbootstrap3.client.ui.Button)3 Icon (org.gwtbootstrap3.client.ui.Icon)3