com.google.gwt.user.client.ui.HasValue Java Examples

The following examples show how to use com.google.gwt.user.client.ui.HasValue. 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: DefaultDirtyValidator.java    From gwt-material with Apache License 2.0 6 votes vote down vote up
/**
 * Will check all components that extends to {@link HasValue} and
 * registers a {@link com.google.gwt.event.logical.shared.ValueChangeEvent}.
 * Once value has been changed then we mark that our content wrapping it is dirty.
 */
protected void detectDirtyFields(Widget parent) {
    if (parent instanceof HasWidgets) {
        for (Widget widget : (HasWidgets) parent) {
            if (widget instanceof HasValue) {
                HasValue valueWidget = (HasValue) widget;
                registrations.add(valueWidget.addValueChangeHandler(event -> {
                    if (valueWidget.getValue() != null && ! valueWidget.getValue().equals("")) {
                        setDirty(true);
                    }
                }));
            } else {
                if (propagateToChildren) {
                    detectDirtyFields(widget);
                }
            }
        }
    }
}
 
Example #2
Source File: UTCDateTimeRangeController.java    From gwt-traction with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a controller that will manage the date/time range
 * consisting of 2 date/time controls and an optional
 * allDayCheckbox.
 */
public UTCDateTimeRangeController(UTCDateBox startDate, UTCTimeBox startTime, UTCDateBox endDate, UTCTimeBox endTime, HasValue<Boolean> allDayCheckbox) {
    this.startDate = startDate;
    this.startTime = startTime;
    this.endDate = endDate;
    this.endTime = endTime;
    this.allDayCheckbox = allDayCheckbox;
    updateInterval();

    // attach the event handlers
    if (allDayCheckbox != null) {
        allDayCheckbox.addValueChangeHandler(new AllDayCheckboxHandler());
    }
    
    StartDateTimeHandler startHandler = new StartDateTimeHandler();
    EndDateTimeHandler endHandler = new EndDateTimeHandler();
    
    startDate.addValueChangeHandler(startHandler);
    startTime.addValueChangeHandler(startHandler);
    
    endDate.addValueChangeHandler(endHandler);
    endTime.addValueChangeHandler(endHandler);
}
 
Example #3
Source File: MaterialCollectionItem.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
@Override
protected void onLoad() {
    super.onLoad();

    HandlerRegistration handlerRegistration = addClickHandler(event -> {
        // Stop propagation of event when checkbox / other elements has
        // been clicked to avoid duplicate events.
        if (Element.as(event.getNativeEvent().getEventTarget()) != getElement()) {
            if (getType() == CollectionType.CHECKBOX) {
                event.stopPropagation();
                event.preventDefault();
            }
        }
        for (Widget w : MaterialCollectionItem.this) {
            if (w instanceof MaterialCollectionSecondary) {
                for (Widget a : (MaterialCollectionSecondary) w) {
                    if (a instanceof HasValue) {
                        try {
                            @SuppressWarnings("unchecked")
                            HasValue<Boolean> cb = (HasValue<Boolean>) a;
                            if (cb.getValue()) {
                                cb.setValue(false);
                            } else {
                                cb.setValue(true);
                            }
                        } catch (ClassCastException ex) {
                            // Ignore non-boolean has value handlers.
                        }
                    }
                }
            }
        }
    });
    registerHandler(handlerRegistration);

    JsMaterialElement.initDismissableCollection();
}
 
Example #4
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());
}
 
Example #5
Source File: FieldMatchValidator.java    From gwt-material with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor.
 *
 * @param verifyField the verify field
 */
public FieldMatchValidator(final HasValue<T> verifyField) {
    this(verifyField, new Object[0]);
}
 
Example #6
Source File: FieldMatchValidator.java    From gwt-material with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor.
 *
 * @param verifyField        the verify field
 * @param invalidMessageArgs the invalid message args
 */
public FieldMatchValidator(final HasValue<T> verifyField, final Object... invalidMessageArgs) {
    super(Keys.FIELD_MATCH, invalidMessageArgs);
    this.verifyField = verifyField;
    assert this.verifyField != null;
}
 
Example #7
Source File: FieldMatchValidator.java    From gwt-material with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor.
 *
 * @param verifyField            the field to verify matches with this one.
 * @param invalidMessageOverride the invalid message override
 */
public FieldMatchValidator(final HasValue<T> verifyField, final String invalidMessageOverride) {
    super(invalidMessageOverride);
    this.verifyField = verifyField;
    assert this.verifyField != null;
}