Search in sources :

Example 6 with KeyPressHandler

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

Example 7 with KeyPressHandler

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

the class CustomDataTypeTextBoxTest method testSetup.

@Test
public void testSetup() {
    when(textBox.getKeyCodeFromKeyPressEvent(any(KeyPressEvent.class))).thenReturn(64);
    when(keyPressEvent.isControlKeyDown()).thenReturn(false);
    when(keyPressEvent.isShiftKeyDown()).thenReturn(true);
    when(keyPressEvent.getCharCode()).thenReturn('@');
    when(textBox.getCursorPos()).thenReturn(4);
    when(textBox.getSelectionLength()).thenReturn(0);
    when(textBox.getValue()).thenReturn("ab12");
    when(textBox.getText()).thenReturn("ab12@");
    textBox.setup();
    verify(textBox, times(1)).addBlurHandler(blurCaptor.capture());
    verify(textBox, times(1)).addKeyPressHandler(keyPressCaptor.capture());
    BlurHandler blurHandler = blurCaptor.getValue();
    blurHandler.onBlur(blurEvent);
    verify(textBox, times(1)).isValidValue("ab12@", true);
    verify(textBox, times(1)).makeValidValue("ab12@");
    verify(textBox, times(1)).setValue("ab12");
    KeyPressHandler keyPressHandler = keyPressCaptor.getValue();
    keyPressHandler.onKeyPress(keyPressEvent);
    verify(keyPressEvent, times(1)).preventDefault();
    verify(textBox, times(1)).isValidValue("ab12@", false);
    verify(textBox, times(1)).fireValidationError(ERROR_REMOVED + ": @");
    verify(textBox, times(1)).fireValidationError(ERROR_TYPED + ": @");
}
Also used : BlurHandler(com.google.gwt.event.dom.client.BlurHandler) KeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) Test(org.junit.Test)

Example 8 with KeyPressHandler

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

the class VariableNameTextBoxTest method testKeyEnter.

@Test
public void testKeyEnter() {
    when(textBox.getKeyCodeFromKeyPressEvent(any(KeyPressEvent.class))).thenReturn(KeyCodes.KEY_ENTER);
    when(keyPressEvent.isControlKeyDown()).thenReturn(false);
    when(keyPressEvent.isShiftKeyDown()).thenReturn(false);
    when(keyPressEvent.getCharCode()).thenReturn((char) 13);
    when(textBox.getCursorPos()).thenReturn(4);
    when(textBox.getSelectionLength()).thenReturn(0);
    when(textBox.getValue()).thenReturn("ab12");
    when(textBox.getText()).thenReturn("ab12" + (char) 13);
    textBox.setup();
    verify(textBox, times(1)).addBlurHandler(blurCaptor.capture());
    verify(textBox, times(1)).addKeyPressHandler(keyPressCaptor.capture());
    BlurHandler blurHandler = blurCaptor.getValue();
    blurHandler.onBlur(blurEvent);
    verify(textBox, times(1)).isValidValue("ab12" + (char) 13, true);
    verify(textBox, times(1)).makeValidValue("ab12" + (char) 13);
    verify(textBox, times(1)).setValue("ab12");
    KeyPressHandler keyPressHandler = keyPressCaptor.getValue();
    keyPressHandler.onKeyPress(keyPressEvent);
}
Also used : BlurHandler(com.google.gwt.event.dom.client.BlurHandler) KeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) Test(org.junit.Test)

Example 9 with KeyPressHandler

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

the class AttributeValueTextBoxTest method testSetup.

@Test
public void testSetup() {
    when(textBox.getKeyCodeFromKeyPressEvent(any(KeyPressEvent.class))).thenReturn(64);
    when(keyPressEvent.isControlKeyDown()).thenReturn(false);
    when(keyPressEvent.isShiftKeyDown()).thenReturn(true);
    when(keyPressEvent.getCharCode()).thenReturn('@');
    when(textBox.getCursorPos()).thenReturn(4);
    when(textBox.getSelectionLength()).thenReturn(0);
    when(textBox.getValue()).thenReturn("ab12");
    when(textBox.getText()).thenReturn("ab12@");
    textBox.setup();
    verify(textBox, times(1)).addBlurHandler(blurCaptor.capture());
    verify(textBox, times(1)).addKeyPressHandler(keyPressCaptor.capture());
    BlurHandler blurHandler = blurCaptor.getValue();
    blurHandler.onBlur(blurEvent);
    verify(textBox, times(1)).isValidValue("ab12@", true);
    verify(textBox, times(1)).makeValidValue("ab12@");
    verify(textBox, times(1)).setValue("ab12");
    KeyPressHandler keyPressHandler = keyPressCaptor.getValue();
    keyPressHandler.onKeyPress(keyPressEvent);
    verify(keyPressEvent, times(1)).preventDefault();
    verify(textBox, times(1)).isValidValue("ab12@", false);
    verify(textBox, times(1)).fireValidationError(ERROR_REMOVED + ": @");
    verify(textBox, times(1)).fireValidationError(ERROR_TYPED + ": @");
}
Also used : BlurHandler(com.google.gwt.event.dom.client.BlurHandler) KeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) Test(org.junit.Test)

Example 10 with KeyPressHandler

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

the class AttributeValueTextBoxTest method testKeyEnter.

@Test
public void testKeyEnter() {
    when(textBox.getKeyCodeFromKeyPressEvent(any(KeyPressEvent.class))).thenReturn(KeyCodes.KEY_ENTER);
    when(keyPressEvent.isControlKeyDown()).thenReturn(false);
    when(keyPressEvent.isShiftKeyDown()).thenReturn(false);
    when(keyPressEvent.getCharCode()).thenReturn((char) 13);
    when(textBox.getCursorPos()).thenReturn(4);
    when(textBox.getSelectionLength()).thenReturn(0);
    when(textBox.getValue()).thenReturn("ab12");
    when(textBox.getText()).thenReturn("ab12" + (char) 13);
    textBox.setup();
    verify(textBox, times(1)).addBlurHandler(blurCaptor.capture());
    verify(textBox, times(1)).addKeyPressHandler(keyPressCaptor.capture());
    BlurHandler blurHandler = blurCaptor.getValue();
    blurHandler.onBlur(blurEvent);
    verify(textBox, times(1)).isValidValue("ab12" + (char) 13, true);
    verify(textBox, times(1)).makeValidValue("ab12" + (char) 13);
    verify(textBox, times(1)).setValue("ab12");
    KeyPressHandler keyPressHandler = keyPressCaptor.getValue();
    keyPressHandler.onKeyPress(keyPressEvent);
}
Also used : BlurHandler(com.google.gwt.event.dom.client.BlurHandler) KeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) Test(org.junit.Test)

Aggregations

KeyPressEvent (com.google.gwt.event.dom.client.KeyPressEvent)20 KeyPressHandler (com.google.gwt.event.dom.client.KeyPressHandler)20 BlurHandler (com.google.gwt.event.dom.client.BlurHandler)9 Test (org.junit.Test)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 KeyUpHandler (com.google.gwt.event.dom.client.KeyUpHandler)4 Button (com.google.gwt.user.client.ui.Button)4 HintTextBox (com.google.gerrit.client.ui.HintTextBox)3 BlurEvent (com.google.gwt.event.dom.client.BlurEvent)3 KeyDownEvent (com.google.gwt.event.dom.client.KeyDownEvent)3 KeyDownHandler (com.google.gwt.event.dom.client.KeyDownHandler)3 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)3 TextBox (org.gwtbootstrap3.client.ui.TextBox)3 OnEditEnabler (com.google.gerrit.client.ui.OnEditEnabler)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)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