Search in sources :

Example 1 with HasValue

use of com.google.gwt.user.client.ui.HasValue in project gwt-material by GwtMaterialDesign.

the class MaterialCollectionItem method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    HandlerRegistration handlerRegistration = addClickHandler(event -> {
        // 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();
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) Widget(com.google.gwt.user.client.ui.Widget) HasValue(com.google.gwt.user.client.ui.HasValue)

Aggregations

HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)1 HasValue (com.google.gwt.user.client.ui.HasValue)1 Widget (com.google.gwt.user.client.ui.Widget)1