Example usage for com.google.gwt.aria.client Roles getTextboxRole

List of usage examples for com.google.gwt.aria.client Roles getTextboxRole

Introduction

In this page you can find the example usage for com.google.gwt.aria.client Roles getTextboxRole.

Prototype

public static TextboxRole getTextboxRole() 

Source Link

Usage

From source file:com.haulmont.cuba.web.toolkit.ui.client.caption.CubaCaptionWidget.java

License:Apache License

@Override
public boolean updateCaption() {
    ComponentConnector owner = getOwner();

    /* CAUTION copied from super class with small changes */
    boolean wasPlacedAfterComponent = placedAfterComponent;

    // Caption is placed after component unless there is some part which
    // moves it above.
    placedAfterComponent = captionPlacedAfterComponentByDefault;

    String style = CLASSNAME;/*from www .  ja  v a 2 s . co  m*/
    if (ComponentStateUtil.hasStyles(owner.getState())) {
        for (String customStyle : owner.getState().styles) {
            style += " " + CLASSNAME + "-" + customStyle;
        }
    }
    if (!owner.isEnabled()) {
        style += " " + StyleConstants.DISABLED;
    }
    setStyleName(style);

    boolean hasIcon = owner.getState().resources.containsKey(ComponentConstants.ICON_RESOURCE);
    boolean showRequired = false;
    boolean showError = owner.getState().errorMessage != null;
    if (owner.getState() instanceof AbstractFieldState) {
        AbstractFieldState abstractFieldState = (AbstractFieldState) owner.getState();
        showError = showError && !abstractFieldState.hideErrors;
    }
    if (owner instanceof AbstractFieldConnector) {
        showRequired = ((AbstractFieldConnector) owner).isRequired();
    }

    if (icon != null) {
        getElement().removeChild(icon.getElement());
        icon = null;
    }
    if (hasIcon) {
        String uri = owner.getState().resources.get(ComponentConstants.ICON_RESOURCE).getURL();

        icon = getOwner().getConnection().getIcon(uri);

        if (icon instanceof ImageIcon) {
            // onload will set appropriate size later
            icon.setWidth("0");
            icon.setHeight("0");
        }

        DOM.insertChild(getElement(), icon.getElement(), getInsertPosition(InsertPosition.ICON));

        // Icon forces the caption to be above the component
        placedAfterComponent = false;
    }

    if (owner.getState().caption != null) {
        // A caption text should be shown if the attribute is set
        // If the caption is null the ATTRIBUTE_CAPTION should not be set to
        // avoid ending up here.

        if (captionText == null) {
            captionText = DOM.createDiv();
            captionText.setClassName("v-captiontext");

            DOM.insertChild(getElement(), captionText, getInsertPosition(InsertPosition.CAPTION));
        }

        // Update caption text
        String c = owner.getState().caption;
        // A text forces the caption to be above the component.
        placedAfterComponent = false;
        if (c == null || c.trim().equals("")) {
            // Not sure if c even can be null. Should not.

            // This is required to ensure that the caption uses space in all
            // browsers when it is set to the empty string. If there is an
            // icon, error indicator or required indicator they will ensure
            // that space is reserved.
            if (!hasIcon && !showRequired && !showError) {
                captionText.setInnerHTML(" ");
            }
        } else {
            setCaptionText(captionText, owner.getState());
        }

    } else if (captionText != null) {
        // Remove existing
        getElement().removeChild(captionText);
        captionText = null;
    }

    if (ComponentStateUtil.hasDescription(owner.getState()) && captionText != null) {
        addStyleDependentName("hasdescription");
    } else {
        removeStyleDependentName("hasdescription");
    }

    AriaHelper.handleInputRequired(owner.getWidget(), showRequired);

    if (showRequired) {
        if (requiredFieldIndicator == null) {
            requiredFieldIndicator = DOM.createDiv();
            requiredFieldIndicator.setClassName("v-required-field-indicator");
            requiredFieldIndicator.setInnerText("*");

            DOM.insertChild(getElement(), requiredFieldIndicator, getInsertPosition(InsertPosition.REQUIRED));

            // Hide the required indicator from assistive device
            Roles.getTextboxRole().setAriaHiddenState(requiredFieldIndicator, true);
        }
    } else if (requiredFieldIndicator != null) {
        // Remove existing
        requiredFieldIndicator.removeFromParent();
        requiredFieldIndicator = null;
    }

    if (isContextHelpIconEnabled(owner.getState())) {
        if (contextHelpIndicatorElement == null) {
            contextHelpIndicatorElement = DOM.createDiv();
            contextHelpIndicatorElement.setClassName(CONTEXT_HELP_CLASSNAME);

            DOM.insertChild(getElement(), contextHelpIndicatorElement, getContextHelpInsertPosition());

            if (clickHandlerRegistration == null) {
                clickHandlerRegistration = addClickHandler(this);
            }
        }
    } else {
        if (contextHelpIndicatorElement != null) {
            contextHelpIndicatorElement.removeFromParent();
            contextHelpIndicatorElement = null;
        }

        if (clickHandlerRegistration != null) {
            clickHandlerRegistration.removeHandler();
            clickHandlerRegistration = null;
        }
    }

    AriaHelper.handleInputInvalid(owner.getWidget(), showError);

    if (showError) {
        if (errorIndicatorElement == null) {
            errorIndicatorElement = DOM.createDiv();

            errorIndicatorElement.setInnerHTML(" ");
            errorIndicatorElement.setClassName("v-errorindicator");

            DOM.insertChild(getElement(), errorIndicatorElement, getInsertPosition(InsertPosition.ERROR));

            // Hide error indicator from assistive devices
            Roles.getTextboxRole().setAriaHiddenState(errorIndicatorElement, true);
        }
    } else if (errorIndicatorElement != null) {
        // Remove existing
        errorIndicatorElement.removeFromParent();
        errorIndicatorElement = null;
    }

    addStyleName(CLASSNAME);

    if (captionHolder != null) {
        captionHolder.captionUpdated(this);
    }
    return (wasPlacedAfterComponent != placedAfterComponent);
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.checkbox.CubaCheckBoxConnector.java

License:Apache License

@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
    getWidget().captionManagedByLayout = getState().captionManagedByLayout;

    super.onStateChanged(stateChangeEvent);

    if (!getWidget().captionManagedByLayout && isContextHelpIconEnabled()) {
        if (getWidget().contextHelpIcon == null) {
            getWidget().contextHelpIcon = DOM.createSpan();
            getWidget().contextHelpIcon.setInnerHTML("?");
            getWidget().contextHelpIcon.setClassName(CONTEXT_HELP_CLASSNAME);
            Roles.getTextboxRole().setAriaHiddenState(getWidget().contextHelpIcon, true);

            getWidget().getElement().appendChild(getWidget().contextHelpIcon);
            DOM.sinkEvents(getWidget().contextHelpIcon, VTooltip.TOOLTIP_EVENTS | Event.ONCLICK);
        } else {// w w w. j  av a  2 s.  c o  m
            getWidget().contextHelpIcon.getStyle().clearDisplay();
        }
    } else if (getWidget().contextHelpIcon != null) {
        getWidget().contextHelpIcon.getStyle().setDisplay(Style.Display.NONE);

        getWidget().setAriaInvalid(false);
    }
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.orderedactionslayout.CubaOrderedLayoutSlot.java

License:Apache License

public void setCaption(String captionText, boolean contextHelpIconEnabled, Icon icon, List<String> styles,
        String error, boolean showError, boolean required, boolean enabled, boolean captionAsHtml) {
    // CAUTION copied from super
    // Caption wrappers
    Widget widget = getWidget();//  w w  w . ja v a2 s  . co m
    final Element focusedElement = WidgetUtil.getFocusedElement();
    // By default focus will not be lost
    boolean focusLost = false;
    if (captionText != null || icon != null || error != null || required || contextHelpIconEnabled) {
        if (caption == null) {
            caption = DOM.createDiv();
            captionWrap = DOM.createDiv();
            captionWrap.addClassName(StyleConstants.UI_WIDGET);
            captionWrap.addClassName("v-has-caption");
            getElement().appendChild(captionWrap);
            orphan(widget);
            captionWrap.appendChild(widget.getElement());
            adopt(widget);

            // Made changes to DOM. Focus can be lost if it was in the
            // widget.
            focusLost = (focusedElement == null ? false : widget.getElement().isOrHasChild(focusedElement));
        }
    } else if (caption != null) {
        orphan(widget);
        getElement().appendChild(widget.getElement());
        adopt(widget);
        captionWrap.removeFromParent();
        caption = null;
        captionWrap = null;

        // Made changes to DOM. Focus can be lost if it was in the widget.
        focusLost = (focusedElement == null ? false : widget.getElement().isOrHasChild(focusedElement));
    }

    // Caption text
    if (captionText != null) {
        if (this.captionText == null) {
            this.captionText = DOM.createSpan();
            this.captionText.addClassName("v-captiontext");

            if (caption != null) {
                caption.appendChild(this.captionText);
            }
        }
        if (captionText.trim().equals("")) {
            this.captionText.setInnerHTML("&nbsp;");
        } else {
            if (captionAsHtml) {
                this.captionText.setInnerHTML(captionText);
            } else {
                this.captionText.setInnerText(captionText);
            }
        }
    } else if (this.captionText != null) {
        this.captionText.removeFromParent();
        this.captionText = null;
    }

    // Icon
    if (this.icon != null) {
        this.icon.getElement().removeFromParent();
    }
    if (icon != null) {
        if (caption != null) {
            caption.insertFirst(icon.getElement());
        }
    }
    this.icon = icon;

    // Required
    if (required) {
        if (requiredIcon == null) {
            requiredIcon = DOM.createSpan();
            // TODO decide something better (e.g. use CSS to insert the
            // character)
            requiredIcon.setInnerHTML("*");
            requiredIcon.setClassName("v-required-field-indicator");

            // The star should not be read by the screen reader, as it is
            // purely visual. Required state is set at the element level for
            // the screen reader.
            Roles.getTextboxRole().setAriaHiddenState(requiredIcon, true);
        }
        if (caption != null) {
            caption.appendChild(requiredIcon);
        }
    } else if (requiredIcon != null) {
        requiredIcon.removeFromParent();
        requiredIcon = null;
    }

    // Context Help
    // Haulmont API
    if (contextHelpIconEnabled) {
        if (contextHelpIcon == null) {
            contextHelpIcon = DOM.createSpan();
            // TODO decide something better (e.g. use CSS to insert the character)
            contextHelpIcon.setInnerHTML("?");
            contextHelpIcon.setClassName(CONTEXT_HELP_CLASSNAME);

            // The question mark should not be read by the screen reader, as it is
            // purely visual. Required state is set at the element level for
            // the screen reader.
            Roles.getTextboxRole().setAriaHiddenState(contextHelpIcon, true);
        }
        if (caption != null) {
            caption.appendChild(contextHelpIcon);

            if (clickHandlerRegistration == null) {
                clickHandlerRegistration = addDomHandler(this, ClickEvent.getType());
            }
        }
    } else {
        if (this.contextHelpIcon != null) {
            this.contextHelpIcon.removeFromParent();
            this.contextHelpIcon = null;
        }

        if (clickHandlerRegistration != null) {
            clickHandlerRegistration.removeHandler();
            clickHandlerRegistration = null;
        }
    }

    // Error
    if (error != null && showError) {
        if (errorIcon == null) {
            errorIcon = DOM.createSpan();
            errorIcon.setClassName("v-errorindicator");
        }
        if (caption != null) {
            caption.appendChild(errorIcon);
        }
    } else if (errorIcon != null) {
        errorIcon.removeFromParent();
        errorIcon = null;
    }

    if (caption != null) {
        // Styles
        caption.setClassName("v-caption");

        if (styles != null) {
            for (String style : styles) {
                caption.addClassName("v-caption-" + style);
            }
        }

        if (enabled) {
            caption.removeClassName("v-disabled");
        } else {
            caption.addClassName("v-disabled");
        }

        // Caption position
        if (captionText != null || icon != null) {
            setCaptionPosition(CaptionPosition.TOP);
        } else {
            setCaptionPosition(CaptionPosition.RIGHT);
        }
    }

    if (focusLost) {
        // Find out what element is currently focused.
        Element currentFocus = WidgetUtil.getFocusedElement();
        if (currentFocus != null && currentFocus.equals(Document.get().getBody())) {
            // Focus has moved to BodyElement and should be moved back to
            // original location. This happened because of adding or
            // removing the captionWrap
            focusedElement.focus();
        } else if (currentFocus != focusedElement) {
            // Focus is either moved somewhere else on purpose or IE has
            // lost it. Investigate further.
            Timer focusTimer = new Timer() {

                @Override
                public void run() {
                    if (WidgetUtil.getFocusedElement() == null) {
                        // This should never become an infinite loop and
                        // even if it does it will be stopped once something
                        // is done with the browser.
                        schedule(25);
                    } else if (WidgetUtil.getFocusedElement().equals(Document.get().getBody())) {
                        // Focus found it's way to BodyElement. Now it can
                        // be restored
                        focusedElement.focus();
                    }
                }
            };
            if (BrowserInfo.get().isIE8()) {
                // IE8 can't fix the focus immediately. It will fail.
                focusTimer.schedule(25);
            } else {
                // Newer IE versions can handle things immediately.
                focusTimer.run();
            }
        }
    }
}

From source file:com.haulmont.cuba.web.widgets.client.caption.CubaCaptionWidget.java

License:Apache License

@Override
public boolean updateCaption() {
    ComponentConnector owner = getOwner();

    // CAUTION copied from super class with small changes
    boolean wasPlacedAfterComponent = placedAfterComponent;

    // Caption is placed after component unless there is some part which
    // moves it above.
    placedAfterComponent = captionPlacedAfterComponentByDefault;

    String style = CLASSNAME;//w ww  .j av a 2s.  c  om
    if (ComponentStateUtil.hasStyles(owner.getState())) {
        for (String customStyle : owner.getState().styles) {
            style += " " + CLASSNAME + "-" + customStyle;
        }
    }
    if (!owner.isEnabled()) {
        style += " " + StyleConstants.DISABLED;
    }
    setStyleName(style);

    boolean hasIcon = owner.getState().resources.containsKey(ComponentConstants.ICON_RESOURCE);
    boolean showRequired = false;
    boolean showError = owner.getState().errorMessage != null;
    if (owner.getState() instanceof AbstractFieldState) {
        AbstractFieldState abstractFieldState = (AbstractFieldState) owner.getState();
        showError = showError && !abstractFieldState.hideErrors;
    }
    if (owner instanceof AbstractFieldConnector) {
        showRequired = ((AbstractFieldConnector) owner).isRequired();
    }

    if (icon != null) {
        getElement().removeChild(icon.getElement());
        icon = null;
    }
    if (hasIcon) {
        String uri = owner.getState().resources.get(ComponentConstants.ICON_RESOURCE).getURL();

        icon = getOwner().getConnection().getIcon(uri);

        if (icon instanceof ImageIcon) {
            // onload will set appropriate size later
            icon.setWidth("0");
            icon.setHeight("0");
        }

        DOM.insertChild(getElement(), icon.getElement(), getInsertPosition(InsertPosition.ICON));

        // Icon forces the caption to be above the component
        placedAfterComponent = false;
    }

    if (owner.getState().caption != null) {
        // A caption text should be shown if the attribute is set
        // If the caption is null the ATTRIBUTE_CAPTION should not be set to
        // avoid ending up here.

        if (captionText == null) {
            captionText = DOM.createDiv();
            captionText.setClassName("v-captiontext");

            DOM.insertChild(getElement(), captionText, getInsertPosition(InsertPosition.CAPTION));
        }

        // Update caption text
        String c = owner.getState().caption;
        // A text forces the caption to be above the component.
        placedAfterComponent = false;
        if (c == null || c.trim().equals("")) {
            // Not sure if c even can be null. Should not.

            // This is required to ensure that the caption uses space in all
            // browsers when it is set to the empty string. If there is an
            // icon, error indicator or required indicator they will ensure
            // that space is reserved.
            if (!hasIcon && !showRequired && !showError) {
                captionText.setInnerHTML("&nbsp;");
            }
        } else {
            setCaptionText(captionText, owner.getState());
        }

    } else if (captionText != null) {
        // Remove existing
        getElement().removeChild(captionText);
        captionText = null;
    }

    if (ComponentStateUtil.hasDescription(owner.getState()) && captionText != null) {
        addStyleDependentName("hasdescription");
    } else {
        removeStyleDependentName("hasdescription");
    }

    AriaHelper.handleInputRequired(owner.getWidget(), showRequired);

    if (showRequired) {
        if (requiredFieldIndicator == null) {
            requiredFieldIndicator = DOM.createDiv();
            requiredFieldIndicator.setClassName("v-required-field-indicator");
            requiredFieldIndicator.setInnerText("*");

            DOM.insertChild(getElement(), requiredFieldIndicator, getInsertPosition(InsertPosition.REQUIRED));

            // Hide the required indicator from assistive device
            Roles.getTextboxRole().setAriaHiddenState(requiredFieldIndicator, true);
        }
    } else if (requiredFieldIndicator != null) {
        // Remove existing
        requiredFieldIndicator.removeFromParent();
        requiredFieldIndicator = null;
    }

    if (isContextHelpIconEnabled(owner.getState())) {
        if (contextHelpIndicatorElement == null) {
            contextHelpIndicatorElement = DOM.createDiv();
            contextHelpIndicatorElement.setClassName(CONTEXT_HELP_CLASSNAME);

            if (hasContextHelpIconListeners(owner.getState())) {
                contextHelpIndicatorElement.addClassName(CONTEXT_HELP_CLICKABLE_CLASSNAME);
            }

            DOM.insertChild(getElement(), contextHelpIndicatorElement, getContextHelpInsertPosition());

            if (clickHandlerRegistration == null) {
                clickHandlerRegistration = addClickHandler(this);
            }
        }
    } else {
        if (contextHelpIndicatorElement != null) {
            contextHelpIndicatorElement.removeFromParent();
            contextHelpIndicatorElement = null;
        }

        if (clickHandlerRegistration != null) {
            clickHandlerRegistration.removeHandler();
            clickHandlerRegistration = null;
        }
    }

    AriaHelper.handleInputInvalid(owner.getWidget(), showError);

    if (showError) {
        if (errorIndicatorElement == null) {
            errorIndicatorElement = DOM.createDiv();

            errorIndicatorElement.setInnerHTML("&nbsp;");
            errorIndicatorElement.setClassName("v-errorindicator");

            DOM.insertChild(getElement(), errorIndicatorElement, getInsertPosition(InsertPosition.ERROR));

            // Hide error indicator from assistive devices
            Roles.getTextboxRole().setAriaHiddenState(errorIndicatorElement, true);
        }
    } else if (errorIndicatorElement != null) {
        // Remove existing
        errorIndicatorElement.removeFromParent();
        errorIndicatorElement = null;
    }

    addStyleName(CLASSNAME);

    if (captionHolder != null) {
        captionHolder.captionUpdated(this);
    }
    return (wasPlacedAfterComponent != placedAfterComponent);
}

From source file:com.haulmont.cuba.web.widgets.client.checkbox.CubaCheckBoxConnector.java

License:Apache License

@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
    getWidget().captionManagedByLayout = getState().captionManagedByLayout;

    super.onStateChanged(stateChangeEvent);

    if (!getWidget().captionManagedByLayout && isContextHelpIconEnabled()) {
        if (getWidget().contextHelpIcon == null) {
            getWidget().contextHelpIcon = DOM.createSpan();
            getWidget().contextHelpIcon.setInnerHTML("?");
            getWidget().contextHelpIcon.setClassName(CONTEXT_HELP_CLASSNAME);

            if (hasContextHelpIconListeners()) {
                getWidget().contextHelpIcon.addClassName(CONTEXT_HELP_CLICKABLE_CLASSNAME);
            }// www.ja  v a2  s.c o m

            Roles.getTextboxRole().setAriaHiddenState(getWidget().contextHelpIcon, true);

            getWidget().getElement().appendChild(getWidget().contextHelpIcon);
            DOM.sinkEvents(getWidget().contextHelpIcon, VTooltip.TOOLTIP_EVENTS | Event.ONCLICK);
        } else {
            getWidget().contextHelpIcon.getStyle().clearDisplay();
        }
    } else if (getWidget().contextHelpIcon != null) {
        getWidget().contextHelpIcon.getStyle().setDisplay(Style.Display.NONE);

        getWidget().setAriaInvalid(false);
    }
}

From source file:com.haulmont.cuba.web.widgets.client.orderedactionslayout.CubaOrderedLayoutSlot.java

License:Apache License

public void setCaption(String captionText, boolean contextHelpIconEnabled, Icon icon, List<String> styles,
        String error, boolean showError, boolean required, boolean enabled, boolean captionAsHtml) {
    // CAUTION copied from super
    // Caption wrappers
    Widget widget = getWidget();//from w  w w  .j av a2 s  . c o  m
    final Element focusedElement = WidgetUtil.getFocusedElement();
    // By default focus will not be lost
    boolean focusLost = false;
    if (captionText != null || icon != null || error != null || required || contextHelpIconEnabled) {
        if (caption == null) {
            caption = DOM.createDiv();
            captionWrap = DOM.createDiv();
            captionWrap.addClassName(StyleConstants.UI_WIDGET);
            captionWrap.addClassName("v-has-caption");
            getElement().appendChild(captionWrap);
            orphan(widget);
            captionWrap.appendChild(widget.getElement());
            adopt(widget);

            // Made changes to DOM. Focus can be lost if it was in the
            // widget.
            focusLost = (focusedElement == null ? false : widget.getElement().isOrHasChild(focusedElement));
        }
    } else if (caption != null) {
        orphan(widget);
        getElement().appendChild(widget.getElement());
        adopt(widget);
        captionWrap.removeFromParent();
        caption = null;
        captionWrap = null;

        // Made changes to DOM. Focus can be lost if it was in the widget.
        focusLost = (focusedElement == null ? false : widget.getElement().isOrHasChild(focusedElement));
    }

    // Caption text
    if (captionText != null) {
        if (this.captionText == null) {
            this.captionText = DOM.createSpan();
            this.captionText.addClassName("v-captiontext");

            if (caption != null) {
                caption.appendChild(this.captionText);
            }
        }
        if (captionText.trim().equals("")) {
            this.captionText.setInnerHTML("&nbsp;");
        } else {
            if (captionAsHtml) {
                this.captionText.setInnerHTML(captionText);
            } else {
                this.captionText.setInnerText(captionText);
            }
        }
    } else if (this.captionText != null) {
        this.captionText.removeFromParent();
        this.captionText = null;
    }

    // Icon
    if (this.icon != null) {
        this.icon.getElement().removeFromParent();
    }
    if (icon != null) {
        if (caption != null) {
            caption.insertFirst(icon.getElement());
        }
    }
    this.icon = icon;

    // Required
    if (required) {
        if (requiredIcon == null) {
            requiredIcon = DOM.createSpan();
            // TODO decide something better (e.g. use CSS to insert the
            // character)
            requiredIcon.setInnerHTML("*");
            requiredIcon.setClassName("v-required-field-indicator");

            // The star should not be read by the screen reader, as it is
            // purely visual. Required state is set at the element level for
            // the screen reader.
            Roles.getTextboxRole().setAriaHiddenState(requiredIcon, true);
        }
        if (caption != null) {
            caption.appendChild(requiredIcon);
        }
    } else if (requiredIcon != null) {
        requiredIcon.removeFromParent();
        requiredIcon = null;
    }

    // Context Help
    // Haulmont API
    if (contextHelpIconEnabled) {
        if (contextHelpIcon == null) {
            contextHelpIcon = DOM.createSpan();
            // TODO decide something better (e.g. use CSS to insert the character)
            contextHelpIcon.setInnerHTML("?");
            contextHelpIcon.setClassName(CONTEXT_HELP_CLASSNAME);

            ComponentConnector componentConnector = Util.findConnectorFor(widget);
            if (hasContextHelpIconListeners(componentConnector.getState())) {
                contextHelpIcon.addClassName(CONTEXT_HELP_CLICKABLE_CLASSNAME);
            }

            // The question mark should not be read by the screen reader, as it is
            // purely visual. Required state is set at the element level for
            // the screen reader.
            Roles.getTextboxRole().setAriaHiddenState(contextHelpIcon, true);
        }
        if (caption != null) {
            caption.appendChild(contextHelpIcon);

            if (clickHandlerRegistration == null) {
                clickHandlerRegistration = addDomHandler(this, ClickEvent.getType());
            }
        }
    } else {
        if (this.contextHelpIcon != null) {
            this.contextHelpIcon.removeFromParent();
            this.contextHelpIcon = null;
        }

        if (clickHandlerRegistration != null) {
            clickHandlerRegistration.removeHandler();
            clickHandlerRegistration = null;
        }
    }

    // Error
    if (error != null && showError) {
        if (errorIcon == null) {
            errorIcon = DOM.createSpan();
            errorIcon.setClassName("v-errorindicator");
        }
        if (caption != null) {
            caption.appendChild(errorIcon);
        }
    } else if (errorIcon != null) {
        errorIcon.removeFromParent();
        errorIcon = null;
    }

    if (caption != null) {
        // Styles
        caption.setClassName("v-caption");

        if (styles != null) {
            for (String style : styles) {
                caption.addClassName("v-caption-" + style);
            }
        }

        if (enabled) {
            caption.removeClassName("v-disabled");
        } else {
            caption.addClassName("v-disabled");
        }

        // Caption position
        if (captionText != null || icon != null) {
            setCaptionPosition(CaptionPosition.TOP);
        } else {
            setCaptionPosition(CaptionPosition.RIGHT);
        }
    }

    if (focusLost) {
        // Find out what element is currently focused.
        Element currentFocus = WidgetUtil.getFocusedElement();
        if (currentFocus != null && currentFocus.equals(Document.get().getBody())) {
            // Focus has moved to BodyElement and should be moved back to
            // original location. This happened because of adding or
            // removing the captionWrap
            focusedElement.focus();
        } else if (currentFocus != focusedElement) {
            // Focus is either moved somewhere else on purpose or IE has
            // lost it. Investigate further.
            Timer focusTimer = new Timer() {

                @Override
                public void run() {
                    if (WidgetUtil.getFocusedElement() == null) {
                        // This should never become an infinite loop and
                        // even if it does it will be stopped once something
                        // is done with the browser.
                        schedule(25);
                    } else if (WidgetUtil.getFocusedElement().equals(Document.get().getBody())) {
                        // Focus found it's way to BodyElement. Now it can
                        // be restored
                        focusedElement.focus();
                    }
                }
            };
            if (BrowserInfo.get().isIE8()) {
                // IE8 can't fix the focus immediately. It will fail.
                focusTimer.schedule(25);
            } else {
                // Newer IE versions can handle things immediately.
                focusTimer.run();
            }
        }
    }
}

From source file:com.vaadin.client.ui.aria.AriaHelper.java

License:Apache License

/**
 * Binds a caption (label in HTML speak) to the form element as required by
 * WAI-ARIA specification./*  w  w  w. j  a va2  s .  c  o  m*/
 * 
 * @param widget
 *            Widget, that should be bound to the caption
 * @param captionElements
 *            Element with of caption to bind
 */
public static void bindCaption(Widget widget, Element captionElement) {
    assert widget != null : "Valid Widget required";

    if (widget instanceof HandlesAriaCaption) {
        // Let the widget handle special cases itself
        if (captionElement == null) {
            ((HandlesAriaCaption) widget).bindAriaCaption(null);
        } else {
            ensureHasId(captionElement);
            ((HandlesAriaCaption) widget).bindAriaCaption(DOM.asOld(captionElement));
        }
    } else if (captionElement != null) {
        // Handle the default case
        ensureHasId(captionElement);
        String ownerId = ensureHasId(widget.getElement());
        captionElement.setAttribute("for", ownerId);

        Roles.getTextboxRole().setAriaLabelledbyProperty(widget.getElement(), Id.of(captionElement));
    } else {
        clearCaption(widget);
    }
}

From source file:com.vaadin.client.ui.aria.AriaHelper.java

License:Apache License

/**
 * Removes a binding to a caption added with bindCaption() from the provided
 * Widget.//from w w w .  j  ava2 s .  c om
 * 
 * @param widget
 *            Widget, that was bound to a caption before
 */
private static void clearCaption(Widget widget) {
    Roles.getTextboxRole().removeAriaLabelledbyProperty(widget.getElement());
}

From source file:com.vaadin.client.ui.aria.AriaHelper.java

License:Apache License

/**
 * Handles the required actions depending of the input element being
 * required or not.//from   w  ww .  j  ava2s  .  c o  m
 * 
 * @param element
 *            Element, typically from an input Widget like TextField
 * @param required
 *            boolean, true when the element is required
 */
public static void handleInputRequired(Element element, boolean required) {
    if (required) {
        Roles.getTextboxRole().setAriaRequiredProperty(element, required);
    } else {
        Roles.getTextboxRole().removeAriaRequiredProperty(element);
    }
}

From source file:com.vaadin.client.ui.aria.AriaHelper.java

License:Apache License

/**
 * Handles the required actions depending of the input element contains
 * unaccepted input.//from w  ww  .  ja va  2s  . c  o  m
 * 
 * @param element
 *            Element, typically an input Widget like TextField
 * @param invalid
 *            boolean, true when the element input has an error
 */
public static void handleInputInvalid(Element element, boolean invalid) {
    if (invalid) {
        Roles.getTextboxRole().setAriaInvalidState(element, InvalidValue.TRUE);
    } else {
        Roles.getTextboxRole().removeAriaInvalidState(element);
    }
}