com.google.gwt.event.logical.shared.HasValueChangeHandlers Java Examples

The following examples show how to use com.google.gwt.event.logical.shared.HasValueChangeHandlers. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WidgetTestCase.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
public static <H extends HasValueChangeHandlers & HasValue & HasEnabled & HasAttachHandlers> void checkValueChangeEvent(
        H widget, Object value, Object secondValue) {
    assertNotSame(value, secondValue);
    // Widget must be enabled before firing the event
    widget.setEnabled(true);
    assertTrue(widget.isEnabled());
    // Ensure the widget is attached to the root panel
    assertTrue(widget.isAttached());
    // Register value change handler that listens when the widget
    // set the value
    final boolean[] isValueChanged = {false};
    widget.addValueChangeHandler(event -> isValueChanged[0] = true);
    // By default setValue(boolean) will not fire the value change event.
    widget.setValue(value);
    assertEquals(value, widget.getValue());
    // Expected result : false
    assertFalse(isValueChanged[0]);
    // Calling setValue(value, fireEvents) with fireEvents set to false
    widget.setValue(secondValue, false);
    // Expected result : secondValue
    assertEquals(secondValue, widget.getValue());
    // Expected result : false
    assertFalse(isValueChanged[0]);
    // Calling setValue(value, fireEvents) with fireEvents set to true
    widget.setValue(value, true);
    // Expected result : true
    assertTrue(isValueChanged[0]);
    // Expected result : value
    assertEquals(value, widget.getValue());
}