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

The following examples show how to use com.google.gwt.user.client.ui.HasEnabled. 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: WavesMixin.java    From gwt-material with Apache License 2.0 6 votes vote down vote up
@Override
public void setWaves(WavesType waves) {
    uiObject.removeStyleName(Waves.WAVES_STYLE);
    if (this.waves != null) {
        uiObject.removeStyleName(this.waves.getCssName());
    }

    this.waves = waves;

    if (waves != null) {
        boolean enabled = !(uiObject instanceof HasEnabled) || ((HasEnabled) uiObject).isEnabled();
        if (enabled) {
            uiObject.addStyleName(Waves.WAVES_STYLE);
        }

        uiObject.addStyleName(waves.getCssName());
        if (enabled) {
            Waves.detectAndApply(uiObject);
        }
    }
}
 
Example #2
Source File: ReadOnlyMixin.java    From gwt-material with Apache License 2.0 6 votes vote down vote up
@Override
public void setReadOnly(boolean readOnly) {
    uiObject.removeStyleName(CssName.READ_ONLY);
    if (readOnly) {
        if (uiObject instanceof HasEnabled) {
            ((HasEnabled) uiObject).setEnabled(false);
        }
        uiObject.addStyleName(CssName.READ_ONLY);
        target.getElement().setAttribute("readonly", "");
    } else {
        if (uiObject instanceof HasEnabled) {
            ((HasEnabled) uiObject).setEnabled(true);
        }
        target.getElement().removeAttribute("readonly");
        uiObject.removeStyleName(CssName.READ_ONLY);
    }

    if (callback != null) {
        callback.call(readOnly);
    }
}
 
Example #3
Source File: ReadOnlyMixin.java    From gwt-material with Apache License 2.0 6 votes vote down vote up
@Override
public void setToggleReadOnly(boolean value) {
    uiObject.removeStyleName(CssName.READ_ONLY_TOGGLE);
    if (value) {
        uiObject.addStyleName(CssName.READ_ONLY_TOGGLE);
        if (uiObject instanceof HasEnabled && !((HasEnabled) uiObject).isEnabled()) {
            ((HasEnabled) uiObject).setEnabled(true);
        }
        $(uiObject).off("mousedown").mousedown((e, param1) -> {
            setReadOnly(false);
            return true;
        });

        $(target).off("blur").blur((e, param1) -> {
            setReadOnly(true);
            return true;
        });
    } else {
        $(uiObject).off("mousedown");
        $(target).off("blur");
    }
}
 
Example #4
Source File: MaterialWidgetTestCase.java    From gwt-material with Apache License 2.0 6 votes vote down vote up
protected <H extends HasAllKeyHandlers & HasEnabled> void checkKeyEvents(H widget) {
    // Key Down
    final boolean[] isKeyDownFired = {false};
    widget.addKeyDownHandler(keyDownEvent -> isKeyDownFired[0] = true);
    fireKeyDownEvent(widget);

    // Key Up
    final boolean[] isKeyUpFired = {false};
    widget.addKeyUpHandler(keyUpEvent -> isKeyUpFired[0] = true);
    fireKeyUpEvent(widget);

    // Key Press
    final boolean[] isKeyPressFired = {false};
    widget.addKeyPressHandler(keyPressEvent -> isKeyPressFired[0] = true);
    fireKeyPressEvent(widget);

    assertEquals(widget.isEnabled(), isKeyDownFired[0]);
    assertEquals(widget.isEnabled(), isKeyUpFired[0]);
    assertEquals(widget.isEnabled(), isKeyPressFired[0]);
}
 
Example #5
Source File: MaterialWidgetTestCase.java    From gwt-material with Apache License 2.0 6 votes vote down vote up
protected <H extends UIObject & HasEnabled> void checkEnabled(HasEnabled widget, H target, boolean checkElement) {
    final Element element = target.getElement();
    if(checkElement) {
        assertFalse(element.hasClassName(CssName.DISABLED));
        assertFalse(element.hasAttribute(CssName.DISABLED));
    }
    widget.setEnabled(true);
    if(checkElement) {
        assertFalse(element.hasClassName(CssName.DISABLED));
        assertFalse(element.hasAttribute(CssName.DISABLED));
    }
    assertEquals(widget.isEnabled(), true);
    widget.setEnabled(false);
    if(checkElement) {
        assertTrue(element.hasClassName(CssName.DISABLED));
        assertTrue(element.hasAttribute(CssName.DISABLED));
    }
    assertEquals(target.isEnabled(), false);
}
 
Example #6
Source File: CubaOptionGroupWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void updateEnabledState() {
    for (Widget w : panel) {
        if (w instanceof HasEnabled) {
            HasEnabled hasEnabled = (HasEnabled) w;
            hasEnabled.setEnabled(isEnabled());

            w.setStyleName("v-readonly", isReadonly());
        }
    }
}
 
Example #7
Source File: EnabledMixin.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
public void setEnabled(MaterialWidget widget, boolean enabled) {
    setEnabled(enabled);

    if(isPropagateToChildren()) {
        for (Widget child : widget.getChildren()) {
            if (child instanceof MaterialWidget) {
                ((MaterialWidget) child).setEnabled(enabled);
            } else if (child instanceof HasEnabled) {
                ((HasEnabled) child).setEnabled(enabled);
            }
        }
    }
}
 
Example #8
Source File: ResetFieldMixin.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
@Override
public void resetFields() {
    if (allowResettingFields) {
        if (content instanceof HasEnabled) {
            ((HasEnabled) content).setEnabled(true);
        }

        reset(content);
    }
}
 
Example #9
Source File: MaterialDropDown.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
@Override
public HandlerRegistration addSelectionHandler(final SelectionHandler<Widget> handler) {
    return addHandler((SelectionHandler<Widget>) event -> {
        Widget widget = event.getSelectedItem();
        if (widget instanceof HasEnabled && ((HasEnabled) widget).isEnabled() && isEnabled()) {
            handler.onSelection(event);
        }
    }, SelectionEvent.getType());
}
 
Example #10
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 #11
Source File: AbstractButtonTest.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
@Override
protected <H extends UIObject & HasEnabled> void checkEnabled(HasEnabled widget, H target) {
    super.checkEnabled(widget, target);

    widget.setEnabled(false);
    assertTrue(target.getElement().hasAttribute("onclick"));
    assertEquals("return false", target.getElement().getAttribute("onclick"));

    widget.setEnabled(true);
    assertFalse(target.getElement().hasAttribute("onclick"));
}
 
Example #12
Source File: MaterialWidgetTestCase.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
protected <H extends HasAllFocusHandlers & HasEnabled> void checkFocusAndBlurEvents(H widget) {
    // Check Focus
    final boolean[] isFocusFired = {false};
    widget.addFocusHandler(focusEvent -> isFocusFired[0] = true);
    fireFocusEvent(widget);

    // Check Blur
    final boolean[] isBlurFired = {false};
    widget.addBlurHandler(blurEvent -> isBlurFired[0] = true);
    fireBlurEvent(widget);

    assertEquals(widget.isEnabled(), isFocusFired[0]);
    assertEquals(widget.isEnabled(), isBlurFired[0]);
}
 
Example #13
Source File: MaterialWidgetTestCase.java    From gwt-material with Apache License 2.0 4 votes vote down vote up
protected <H extends UIObject & HasEnabled> void checkEnabled(HasEnabled widget, H target) {
    checkEnabled(widget, target, true);
}