Search in sources :

Example 1 with KeyPressEvent

use of com.google.gwt.event.dom.client.KeyPressEvent in project gwt-test-utils by gwt-test-utils.

the class TextBoxTest method pressKey.

@Test
public void pressKey() {
    // Given
    final List<KeyPressEventData> events = new ArrayList<KeyPressEventData>();
    TextBox tb = new TextBox();
    tb.addKeyPressHandler(new KeyPressHandler() {

        public void onKeyPress(KeyPressEvent event) {
            KeyPressEventData data = new KeyPressEventData();
            data.keyCode = event.getNativeEvent().getKeyCode();
            data.charCode = event.getCharCode();
            events.add(data);
        }
    });
    // When
    Browser.fillText(tb, "gael");
    // Then
    assertThat(tb.getValue()).isEqualTo("gael");
    assertThat(events).hasSize(4);
    assertThat(events.get(0).charCode).isEqualTo('g');
    assertThat(events.get(0).keyCode).isEqualTo(103);
    assertThat(events.get(1).charCode).isEqualTo('a');
    assertThat(events.get(1).keyCode).isEqualTo(97);
    assertThat(events.get(2).charCode).isEqualTo('e');
    assertThat(events.get(2).keyCode).isEqualTo(101);
    assertThat(events.get(3).charCode).isEqualTo('l');
    assertThat(events.get(3).keyCode).isEqualTo(108);
}
Also used : KeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) ArrayList(java.util.ArrayList) TextBox(com.google.gwt.user.client.ui.TextBox) Test(org.junit.Test)

Example 2 with KeyPressEvent

use of com.google.gwt.event.dom.client.KeyPressEvent in project gerrit by GerritCodeReview.

the class MyWatchedProjectsScreen method createWidgets.

protected void createWidgets() {
    nameBox = new RemoteSuggestBox(new ProjectNameSuggestOracle());
    nameBox.setVisibleLength(50);
    nameBox.setHintText(Util.C.defaultProjectName());
    nameBox.addSelectionHandler(new SelectionHandler<String>() {

        @Override
        public void onSelection(SelectionEvent<String> event) {
            doAddNew();
        }
    });
    filterTxt = new HintTextBox();
    filterTxt.setVisibleLength(50);
    filterTxt.setHintText(Util.C.defaultFilter());
    filterTxt.addKeyPressHandler(new KeyPressHandler() {

        @Override
        public void onKeyPress(KeyPressEvent event) {
            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                doAddNew();
            }
        }
    });
    addNew = new Button(Util.C.buttonWatchProject());
    addNew.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(final ClickEvent event) {
            doAddNew();
        }
    });
    browse = new Button(Util.C.buttonBrowseProjects());
    browse.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(final ClickEvent event) {
            // under page header
            int top = grid.getAbsoluteTop() - 50;
            // Try to place it to the right of everything else, but not
            // right justified
            int left = 5 + Math.max(grid.getAbsoluteLeft() + grid.getOffsetWidth(), watchesTab.getAbsoluteLeft() + watchesTab.getOffsetWidth());
            projectsPopup.setPreferredCoordinates(top, left);
            projectsPopup.displayPopup();
        }
    });
    watchesTab = new MyWatchesTable();
    delSel = new Button(Util.C.buttonDeleteSshKey());
    delSel.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(final ClickEvent event) {
            watchesTab.deleteChecked();
        }
    });
}
Also used : HintTextBox(com.google.gerrit.client.ui.HintTextBox) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) KeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) Button(com.google.gwt.user.client.ui.Button) ProjectNameSuggestOracle(com.google.gerrit.client.ui.ProjectNameSuggestOracle) RemoteSuggestBox(com.google.gerrit.client.ui.RemoteSuggestBox)

Example 3 with KeyPressEvent

use of com.google.gwt.event.dom.client.KeyPressEvent 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 4 with KeyPressEvent

use of com.google.gwt.event.dom.client.KeyPressEvent 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)

Example 5 with KeyPressEvent

use of com.google.gwt.event.dom.client.KeyPressEvent in project gerrit by GerritCodeReview.

the class NpIntTextBox method init.

private void init() {
    addKeyDownHandler(new KeyDownHandler() {

        @Override
        public void onKeyDown(KeyDownEvent event) {
            int code = event.getNativeKeyCode();
            onKey(event, code, code);
        }
    });
    addKeyPressHandler(new KeyPressHandler() {

        @Override
        public void onKeyPress(KeyPressEvent event) {
            int charCode = event.getCharCode();
            int keyCode = event.getNativeEvent().getKeyCode();
            onKey(event, charCode, keyCode);
        }
    });
}
Also used : KeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) KeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler)

Aggregations

KeyPressEvent (com.google.gwt.event.dom.client.KeyPressEvent)19 KeyPressHandler (com.google.gwt.event.dom.client.KeyPressHandler)11 KeyCommand (com.google.gwtexpui.globalkey.client.KeyCommand)7 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)5 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 KeyUpEvent (com.google.gwt.event.dom.client.KeyUpEvent)4 Button (com.google.gwt.user.client.ui.Button)4 HintTextBox (com.google.gerrit.client.ui.HintTextBox)3 KeyDownEvent (com.google.gwt.event.dom.client.KeyDownEvent)3 KeyUpHandler (com.google.gwt.event.dom.client.KeyUpHandler)3 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)3 KeyCommandSet (com.google.gwtexpui.globalkey.client.KeyCommandSet)3 OnEditEnabler (com.google.gerrit.client.ui.OnEditEnabler)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 KeyDownHandler (com.google.gwt.event.dom.client.KeyDownHandler)2 Event (com.google.gwt.user.client.Event)2 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)2 Grid (com.google.gwt.user.client.ui.Grid)2 TextBox (com.google.gwt.user.client.ui.TextBox)2 NpTextBox (com.google.gwtexpui.globalkey.client.NpTextBox)2