Example usage for com.vaadin.client.ui.aria AriaHelper bindCaption

List of usage examples for com.vaadin.client.ui.aria AriaHelper bindCaption

Introduction

In this page you can find the example usage for com.vaadin.client.ui.aria AriaHelper bindCaption.

Prototype

public static void bindCaption(Widget widget, Element captionElement) 

Source Link

Document

Binds a caption (label in HTML speak) to the form element as required by WAI-ARIA specification.

Usage

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

License:Apache License

@Override
protected void updateCaptionInternal(ComponentConnector child) {
    // CAUTION copied from superclass
    CubaOrderedLayoutSlot slot = (CubaOrderedLayoutSlot) getWidget().getSlot(child.getWidget());

    String caption = child.getState().caption;
    URLReference iconUrl = child.getState().resources.get(ComponentConstants.ICON_RESOURCE);
    String iconUrlString = iconUrl != null ? iconUrl.getURL() : null;
    Icon icon = child.getConnection().getIcon(iconUrlString);

    List<String> styles = child.getState().styles;
    String error = child.getState().errorMessage;
    boolean showError = error != null;
    if (child.getState() instanceof AbstractFieldState) {
        AbstractFieldState abstractFieldState = (AbstractFieldState) child.getState();
        showError = showError && !abstractFieldState.hideErrors;
    }/*from  w ww.  j a  v  a  2 s .  com*/
    boolean required = false;
    if (child instanceof AbstractFieldConnector) {
        required = ((AbstractFieldConnector) child).isRequired();
    }
    boolean enabled = child.isEnabled();

    if (slot.hasCaption() && null == caption) {
        slot.setCaptionResizeListener(null);
    }

    // Haulmont API
    boolean contextHelpIconEnabled = isContextHelpIconEnabled(child.getState());

    // Haulmont API
    slot.setCaption(caption, contextHelpIconEnabled, icon, styles, error, showError, required, enabled,
            child.getState().captionAsHtml);

    AriaHelper.handleInputRequired(child.getWidget(), required);
    AriaHelper.handleInputInvalid(child.getWidget(), showError);
    AriaHelper.bindCaption(child.getWidget(), slot.getCaptionElement());

    if (slot.hasCaption()) {
        CaptionPosition pos = slot.getCaptionPosition();
        slot.setCaptionResizeListener(slotCaptionResizeListener);
        if (child.isRelativeHeight() && (pos == CaptionPosition.TOP || pos == CaptionPosition.BOTTOM)) {
            getWidget().updateCaptionOffset(slot.getCaptionElement());
        } else if (child.isRelativeWidth() && (pos == CaptionPosition.LEFT || pos == CaptionPosition.RIGHT)) {
            getWidget().updateCaptionOffset(slot.getCaptionElement());
        }
    }
}

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

License:Apache License

@Override
protected void updateCaptionInternal(ComponentConnector child) {
    // CAUTION copied from superclass
    CubaOrderedLayoutSlot slot = (CubaOrderedLayoutSlot) getWidget().getSlot(child.getWidget());

    String caption = child.getState().caption;
    URLReference iconUrl = child.getState().resources.get(ComponentConstants.ICON_RESOURCE);
    String iconUrlString = iconUrl != null ? iconUrl.getURL() : null;
    Icon icon = child.getConnection().getIcon(iconUrlString);

    List<String> styles = child.getState().styles;
    String error = child.getState().errorMessage;
    boolean showError = error != null;
    if (child.getState() instanceof AbstractFieldState) {
        AbstractFieldState abstractFieldState = (AbstractFieldState) child.getState();
        // vaadin8 rework
        //            showError = showError && !abstractFieldState.hideErrors;
    }/* w w w .  j  a v  a  2  s .  c om*/
    boolean required = false;
    if (child instanceof AbstractFieldConnector) {
        required = ((AbstractFieldConnector) child).isRequiredIndicatorVisible();
    }
    boolean enabled = child.isEnabled();

    if (slot.hasCaption() && null == caption) {
        slot.setCaptionResizeListener(null);
    }

    // Haulmont API
    boolean contextHelpIconEnabled = isContextHelpIconEnabled(child.getState());

    // Haulmont API
    slot.setCaption(caption, contextHelpIconEnabled, icon, styles, error, showError, required, enabled,
            child.getState().captionAsHtml);

    AriaHelper.handleInputRequired(child.getWidget(), required);
    AriaHelper.handleInputInvalid(child.getWidget(), showError);
    AriaHelper.bindCaption(child.getWidget(), slot.getCaptionElement());

    if (slot.hasCaption()) {
        CaptionPosition pos = slot.getCaptionPosition();
        slot.setCaptionResizeListener(slotCaptionResizeListener);
        if (child.isRelativeHeight() && (pos == CaptionPosition.TOP || pos == CaptionPosition.BOTTOM)) {
            getWidget().updateCaptionOffset(slot.getCaptionElement());
        } else if (child.isRelativeWidth() && (pos == CaptionPosition.LEFT || pos == CaptionPosition.RIGHT)) {
            getWidget().updateCaptionOffset(slot.getCaptionElement());
        }
    }
}

From source file:info.magnolia.ui.vaadin.gwt.client.actionbar.widget.ActionbarItemWidget.java

License:Open Source License

private void constructDOM() {
    setElement(root);//from w  ww  . ja v  a2  s .co  m
    setStyleName(CLASSNAME);

    text.addClassName("v-text");
    icon.addClassName("v-icon");
    root.appendChild(iconImage == null ? icon : iconImage.getElement());
    root.appendChild(text);
    AriaHelper.bindCaption(this, text);
}

From source file:info.magnolia.ui.vaadin.gwt.client.form.widget.FormFieldWrapper.java

License:Open Source License

public void setField(Widget child) {
    if (this.field != null) {
        remove(field);/*from  ww w .  j ava2 s .  com*/
    }
    this.field = child;
    if (child != null) {
        child.removeFromParent();
        AriaHelper.bindCaption(child, label);
        getChildren().add(child);
        fieldWrapper.insertBefore(child.getElement(), helpButton.getElement());
        adopt(child);
    }
}