Search in sources :

Example 11 with Event

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

the class Browser method prepareEvents.

private static void prepareEvents(IsWidget target, Event... events) {
    for (Event event : events) {
        Element effectiveTarget = JavaScriptObjects.getObject(event, JsoProperties.EVENT_TARGET);
        if (effectiveTarget == null) {
            effectiveTarget = target.asWidget().getElement();
            JavaScriptObjects.setProperty(event, JsoProperties.EVENT_TARGET, effectiveTarget);
        }
    }
}
Also used : Element(com.google.gwt.dom.client.Element) Event(com.google.gwt.user.client.Event) ColumnSortEvent(com.google.gwt.user.cellview.client.ColumnSortEvent)

Example 12 with Event

use of com.google.gwt.user.client.Event 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 13 with Event

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

the class CompositeTest method fireNativeEvent_Wrapped.

@Test
public void fireNativeEvent_Wrapped() {
    // Given
    label.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            labelCount++;
            assertThat(event.getSource()).isEqualTo(label);
            assertThat(event.getRelativeElement()).isEqualTo(label.getElement());
        }
    });
    composite.addDomHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            compositeCount++;
            assertThat(event.getSource()).isEqualTo(composite);
            assertThat(event.getRelativeElement()).isEqualTo(label.getElement());
        }
    }, ClickEvent.getType());
    Event clickEvent = EventBuilder.create(Event.ONCLICK).build();
    // When
    DomEvent.fireNativeEvent(clickEvent, label, label.getElement());
    // Then
    assertThat(labelCount).isEqualTo(1);
    assertThat(compositeCount).isEqualTo(0);
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) DomEvent(com.google.gwt.event.dom.client.DomEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Event(com.google.gwt.user.client.Event) Test(org.junit.Test)

Example 14 with Event

use of com.google.gwt.user.client.Event in project gerrit by GerritCodeReview.

the class CreateGroupScreen method addCreateGroupPanel.

private void addCreateGroupPanel() {
    VerticalPanel addPanel = new VerticalPanel();
    addPanel.setStyleName(Gerrit.RESOURCES.css().addSshKeyPanel());
    addPanel.add(new SmallHeading(AdminConstants.I.headingCreateGroup()));
    addTxt = new NpTextBox() {

        @Override
        public void onBrowserEvent(Event event) {
            super.onBrowserEvent(event);
            if (event.getTypeInt() == Event.ONPASTE) {
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                    @Override
                    public void execute() {
                        if (addTxt.getValue().trim().length() != 0) {
                            addNew.setEnabled(true);
                        }
                    }
                });
            }
        }
    };
    addTxt.sinkEvents(Event.ONPASTE);
    addTxt.setVisibleLength(60);
    addTxt.addKeyPressHandler(new KeyPressHandler() {

        @Override
        public void onKeyPress(KeyPressEvent event) {
            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                doCreateGroup();
            }
        }
    });
    addPanel.add(addTxt);
    addNew = new Button(AdminConstants.I.buttonCreateGroup());
    addNew.setEnabled(false);
    addNew.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(final ClickEvent event) {
            doCreateGroup();
        }
    });
    addPanel.add(addNew);
    add(addPanel);
    new OnEditEnabler(addNew, addTxt);
}
Also used : SmallHeading(com.google.gerrit.client.ui.SmallHeading) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) KeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) Button(com.google.gwt.user.client.ui.Button) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Event(com.google.gwt.user.client.Event) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) OnEditEnabler(com.google.gerrit.client.ui.OnEditEnabler) NpTextBox(com.google.gwtexpui.globalkey.client.NpTextBox)

Example 15 with Event

use of com.google.gwt.user.client.Event in project gerrit by GerritCodeReview.

the class CreateProjectScreen method initCreateTxt.

private void initCreateTxt() {
    project = new NpTextBox() {

        @Override
        public void onBrowserEvent(Event event) {
            super.onBrowserEvent(event);
            if (event.getTypeInt() == Event.ONPASTE) {
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                    @Override
                    public void execute() {
                        if (project.getValue().trim().length() != 0) {
                            create.setEnabled(true);
                        }
                    }
                });
            }
        }
    };
    project.sinkEvents(Event.ONPASTE);
    project.setVisibleLength(50);
    project.addKeyPressHandler(new KeyPressHandler() {

        @Override
        public void onKeyPress(KeyPressEvent event) {
            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                doCreateProject();
            }
        }
    });
    new OnEditEnabler(create, project);
}
Also used : KeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Event(com.google.gwt.user.client.Event) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) OnEditEnabler(com.google.gerrit.client.ui.OnEditEnabler) NpTextBox(com.google.gwtexpui.globalkey.client.NpTextBox)

Aggregations

Event (com.google.gwt.user.client.Event)31 EventListener (com.google.gwt.user.client.EventListener)12 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)10 ColumnSortEvent (com.google.gwt.user.cellview.client.ColumnSortEvent)7 SpanElement (com.google.gwt.dom.client.SpanElement)5 KeyDownEvent (com.google.gwt.event.dom.client.KeyDownEvent)5 KeyboardEvent (elemental.events.KeyboardEvent)5 BlurEvent (com.google.gwt.event.dom.client.BlurEvent)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 KeyUpEvent (com.google.gwt.event.dom.client.KeyUpEvent)4 Test (org.junit.Test)4 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)3 KeyPressEvent (com.google.gwt.event.dom.client.KeyPressEvent)3 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)3 PositionCallback (com.google.gwt.user.client.ui.PopupPanel.PositionCallback)3 PatchMethod (com.googlecode.gwt.test.patchers.PatchMethod)3 ImageResource2x (org.rstudio.core.client.resources.ImageResource2x)3 ToolbarPopupMenu (org.rstudio.core.client.widget.ToolbarPopupMenu)3 OnEditEnabler (com.google.gerrit.client.ui.OnEditEnabler)2 Element (com.google.gwt.dom.client.Element)2