Search in sources :

Example 6 with NativePreviewHandler

use of com.google.gwt.user.client.Event.NativePreviewHandler in project gwt-test-utils by gwt-test-utils.

the class BrowserTest method click_firesNativePreviewHandler.

@Test
public void click_firesNativePreviewHandler() {
    // Given
    Button b = new Button();
    FocusPanel focusPanel = new FocusPanel();
    focusPanel.add(b);
    RootPanel.get().add(focusPanel);
    final StringBuilder sb = new StringBuilder();
    Event.addNativePreviewHandler(new NativePreviewHandler() {

        public void onPreviewNativeEvent(NativePreviewEvent event) {
            Event nativeEvent = Event.as(event.getNativeEvent());
            int eventType = DOM.eventGetType(nativeEvent);
            if (eventType == Event.ONCLICK) {
                sb.append("click!");
            }
        }
    });
    // When
    Browser.click(b);
    // Then
    assertThat(sb.toString()).isEqualTo("click!");
}
Also used : NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) Event(com.google.gwt.user.client.Event) SubmitCompleteEvent(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitEvent(com.google.gwt.user.client.ui.FormPanel.SubmitEvent) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) Test(org.junit.Test)

Example 7 with NativePreviewHandler

use of com.google.gwt.user.client.Event.NativePreviewHandler in project rstudio by rstudio.

the class ModifyKeyboardShortcutsWidget method createMainWidget.

@Override
protected Widget createMainWidget() {
    resetState();
    setEscapeDisabled(true);
    setEnterDisabled(true);
    previewHandler_ = Event.addNativePreviewHandler(new NativePreviewHandler() {

        @Override
        public void onPreviewNativeEvent(NativePreviewEvent preview) {
            if (swallowNextKeyUpEvent_ && preview.getTypeInt() == Event.ONKEYUP) {
                swallowNextKeyUpEvent_ = false;
                preview.cancel();
                preview.getNativeEvent().stopPropagation();
                preview.getNativeEvent().preventDefault();
            } else if (preview.getTypeInt() == Event.ONKEYDOWN) {
                int keyCode = preview.getNativeEvent().getKeyCode();
                if (keyCode == KeyCodes.KEY_ESCAPE || keyCode == KeyCodes.KEY_ENTER) {
                    // If the DataGrid (or an underlying element) has focus, let it
                    // handle the escape / enter key.
                    Element target = preview.getNativeEvent().getEventTarget().cast();
                    Element foundTable = DomUtils.findParentElement(target, new ElementPredicate() {

                        @Override
                        public boolean test(Element el) {
                            return el.equals(table_.getElement());
                        }
                    });
                    if (foundTable != null)
                        return;
                    // the widget.
                    if (filterWidget_.isFocused()) {
                        if (keyCode == KeyCodes.KEY_ENTER) {
                            table_.setKeyboardSelectedRow(0);
                            table_.setKeyboardSelectedColumn(0);
                            return;
                        } else if (keyCode == KeyCodes.KEY_ESCAPE) {
                            focusOkButton();
                            return;
                        }
                    }
                    // Otherwise, handle Enter / Escape 'modally' as we might normally do.
                    preview.cancel();
                    preview.getNativeEvent().stopPropagation();
                    preview.getNativeEvent().preventDefault();
                    if (keyCode == KeyCodes.KEY_ENTER) {
                        clickOkButton();
                        return;
                    } else if (keyCode == KeyCodes.KEY_ESCAPE) {
                        closeDialog();
                        return;
                    }
                }
            }
        }
    });
    addAttachHandler(new AttachEvent.Handler() {

        @Override
        public void onAttachOrDetach(AttachEvent event) {
            if (event.isAttached())
                ;
            else
                previewHandler_.removeHandler();
        }
    });
    VerticalPanel container = new VerticalPanel();
    FlowPanel headerPanel = new FlowPanel();
    Label radioLabel = new Label("Show:");
    radioLabel.getElement().getStyle().setFloat(Style.Float.LEFT);
    radioLabel.getElement().getStyle().setMarginRight(8, Unit.PX);
    headerPanel.add(radioLabel);
    headerPanel.add(radioAll_);
    radioAll_.setValue(true);
    headerPanel.add(radioCustomized_);
    filterWidget_.getElement().getStyle().setFloat(Style.Float.LEFT);
    filterWidget_.getElement().getStyle().setMarginLeft(10, Unit.PX);
    filterWidget_.getElement().getStyle().setMarginTop(-1, Unit.PX);
    headerPanel.add(filterWidget_);
    HelpLink link = new HelpLink("Customizing Keyboard Shortcuts", "custom_keyboard_shortcuts");
    link.getElement().getStyle().setFloat(Style.Float.RIGHT);
    headerPanel.add(link);
    container.add(headerPanel);
    FlowPanel spacer = new FlowPanel();
    spacer.setWidth("100%");
    spacer.setHeight("4px");
    container.add(spacer);
    DockPanel dockPanel = new DockPanel();
    dockPanel.add(table_, DockPanel.CENTER);
    container.add(dockPanel);
    return container;
}
Also used : NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) AttachEvent(com.google.gwt.event.logical.shared.AttachEvent) DockPanel(com.google.gwt.user.client.ui.DockPanel) Element(com.google.gwt.dom.client.Element) TableRowElement(com.google.gwt.dom.client.TableRowElement) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) Label(com.google.gwt.user.client.ui.Label) HelpLink(org.rstudio.studio.client.common.HelpLink) ElementPredicate(org.rstudio.core.client.dom.DomUtils.ElementPredicate)

Example 8 with NativePreviewHandler

use of com.google.gwt.user.client.Event.NativePreviewHandler in project rstudio by rstudio.

the class RCompletionToolTip method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    if (nativePreviewReg_ != null) {
        nativePreviewReg_.removeHandler();
        nativePreviewReg_ = null;
    }
    nativePreviewReg_ = Event.addNativePreviewHandler(new NativePreviewHandler() {

        public void onPreviewNativeEvent(NativePreviewEvent e) {
            int eventType = e.getTypeInt();
            if (eventType == Event.ONKEYDOWN || eventType == Event.ONMOUSEDOWN) {
                // dismiss if we've left our anchor zone
                // (defer this so the current key has a chance to 
                // enter the editor and affect the cursor)
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                    @Override
                    public void execute() {
                        Position cursorPos = docDisplay_.getCursorPosition();
                        if (anchor_ != null) {
                            Range anchorRange = anchor_.getRange();
                            if (cursorPos.isBeforeOrEqualTo(anchorRange.getStart()) || cursorPos.isAfterOrEqualTo(anchorRange.getEnd())) {
                                anchor_.detach();
                                anchor_ = null;
                                hide();
                            }
                        }
                    }
                });
            }
        }
    });
}
Also used : NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) Range(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)

Aggregations

NativePreviewEvent (com.google.gwt.user.client.Event.NativePreviewEvent)8 NativePreviewHandler (com.google.gwt.user.client.Event.NativePreviewHandler)8 Element (com.google.gwt.dom.client.Element)3 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)3 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 Range (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)2 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)1 NativeEvent (com.google.gwt.dom.client.NativeEvent)1 TableRowElement (com.google.gwt.dom.client.TableRowElement)1 AttachEvent (com.google.gwt.event.logical.shared.AttachEvent)1 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)1 Event (com.google.gwt.user.client.Event)1 DockPanel (com.google.gwt.user.client.ui.DockPanel)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 SubmitCompleteEvent (com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent)1 SubmitEvent (com.google.gwt.user.client.ui.FormPanel.SubmitEvent)1 Label (com.google.gwt.user.client.ui.Label)1 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)1 Test (org.junit.Test)1