Search in sources :

Example 26 with Action

use of com.github.bordertech.wcomponents.Action in project wcomponents by BorderTech.

the class WConfirmationButtonExample method addAjaxExample.

/**
 * This is used to reproduce a WComponents bug condition to make sure we do not re-create it once it is fixed.
 * See https://github.com/BorderTech/wcomponents/issues/1266.
 */
private void addAjaxExample() {
    add(new WHeading(HeadingLevel.H2, "Confirm as ajax trigger"));
    final String before = "Before";
    final String after = "After";
    final WText ajaxContent = new WText("Before");
    final WPanel target = new WPanel(WPanel.Type.BOX);
    add(target);
    target.add(ajaxContent);
    WButton confirmWithAjax = new WButton("Replace");
    confirmWithAjax.setMessage("Are you sure?");
    confirmWithAjax.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            ajaxContent.setText(before.equals(ajaxContent.getText()) ? after : before);
        }
    });
    add(confirmWithAjax);
    add(new WAjaxControl(confirmWithAjax, target));
}
Also used : Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) WText(com.github.bordertech.wcomponents.WText) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading)

Example 27 with Action

use of com.github.bordertech.wcomponents.Action in project wcomponents by BorderTech.

the class WRadioButtonSelectExample method makeSimpleExample.

/**
 * Make a simple editable example. The label for this example is used to get the example for use in the unit tests.
 */
private void makeSimpleExample() {
    add(new WHeading(HeadingLevel.H3, "Simple WRadioButtonSelect"));
    WPanel examplePanel = new WPanel();
    examplePanel.setLayout(new FlowLayout(FlowLayout.VERTICAL, Size.MEDIUM));
    add(examplePanel);
    /**
     * The radio button select.
     */
    final WRadioButtonSelect rbSelect = new WRadioButtonSelect("australian_state");
    final WTextField text = new WTextField();
    text.setReadOnly(true);
    text.setText(NO_SELECTION);
    WButton update = new WButton("Update");
    update.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            text.setText("The selected item is: " + rbSelect.getSelected());
        }
    });
    // setting the default submit button improves usability. It can be set on a WPanel or the WRadioButtonSelect directly
    examplePanel.setDefaultSubmitButton(update);
    examplePanel.add(new WLabel("Select a state or territory", rbSelect));
    examplePanel.add(rbSelect);
    examplePanel.add(text);
    examplePanel.add(update);
    add(new WAjaxControl(update, text));
}
Also used : ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 28 with Action

use of com.github.bordertech.wcomponents.Action in project wcomponents by BorderTech.

the class WButtonRenderer method doRender.

/**
 * Paints the given WButton.
 *
 * @param component the WButton to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    XmlStringBuilder xml = renderContext.getWriter();
    WButton button = (WButton) component;
    String text = button.getText();
    String imageUrl = button.getImageUrl();
    String accessibleText = button.getAccessibleText();
    String toolTip = button.getToolTip();
    if (Util.empty(text) && imageUrl == null && Util.empty(accessibleText) && Util.empty(toolTip)) {
        throw new SystemException("WButton text or imageUrl must be specified");
    }
    xml.appendTagOpen(getTagName(button));
    String buttonId = button.getId();
    ImagePosition pos = button.getImagePosition();
    if (Util.empty(text) && Util.empty(toolTip) && Util.empty(accessibleText)) {
        // If the button has an imageUrl but no text equivalent get the text equivalent off of the image
        WImage imgHolder = button.getImageHolder();
        if (null != imgHolder) {
            toolTip = imgHolder.getAlternativeText();
        }
    }
    xml.appendAttribute("id", buttonId);
    xml.appendAttribute("name", buttonId);
    xml.appendAttribute("value", "x");
    xml.appendAttribute("type", getButtonType(button));
    xml.appendAttribute("class", geHtmlClassName(button));
    xml.appendOptionalAttribute("disabled", button.isDisabled(), "disabled");
    xml.appendOptionalAttribute("hidden", button.isHidden(), "hidden");
    xml.appendOptionalAttribute("title", toolTip);
    xml.appendOptionalAttribute("aria-label", accessibleText);
    xml.appendOptionalAttribute("aria-haspopup", button.isPopupTrigger(), "true");
    xml.appendOptionalAttribute("accesskey", Util.upperCase(button.getAccessKeyAsString()));
    xml.appendOptionalAttribute("data-wc-btnmsg", button.getMessage());
    if (button.isCancel()) {
        xml.appendAttribute("formnovalidate", "formnovalidate");
    } else {
        Action action = button.getAction();
        if (action instanceof ValidatingAction) {
            WComponent validationTarget = ((ValidatingAction) action).getComponentToValidate();
            xml.appendAttribute("data-wc-validate", validationTarget.getId());
        }
    }
    xml.appendClose();
    if (imageUrl != null) {
        xml.appendTagOpen("span");
        String imageHolderClass = "wc_nti";
        if (pos != null) {
            StringBuffer imageHolderClassBuffer = new StringBuffer("wc_btn_img wc_btn_img");
            switch(pos) {
                case NORTH:
                    imageHolderClassBuffer.append("n");
                    break;
                case EAST:
                    imageHolderClassBuffer.append("e");
                    break;
                case SOUTH:
                    imageHolderClassBuffer.append("s");
                    break;
                case WEST:
                    imageHolderClassBuffer.append("w");
                    break;
                default:
                    throw new SystemException("Unknown image position: " + pos);
            }
            imageHolderClass = imageHolderClassBuffer.toString();
        }
        xml.appendAttribute("class", imageHolderClass);
        xml.appendClose();
        if (pos != null && text != null) {
            xml.appendTag("span");
            xml.appendEscaped(text);
            xml.appendEndTag("span");
        }
        xml.appendTagOpen("img");
        xml.appendUrlAttribute("src", imageUrl);
        String alternateText = pos == null ? text : "";
        xml.appendAttribute("alt", alternateText);
        xml.appendEnd();
        xml.appendEndTag("span");
    } else if (text != null) {
        xml.appendEscaped(text);
    }
    xml.appendEndTag(getTagName(button));
    if (button.isAjax()) {
        paintAjax(button, xml);
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) Action(com.github.bordertech.wcomponents.Action) SystemException(com.github.bordertech.wcomponents.util.SystemException) ImagePosition(com.github.bordertech.wcomponents.WButton.ImagePosition) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) WImage(com.github.bordertech.wcomponents.WImage) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WButton(com.github.bordertech.wcomponents.WButton)

Aggregations

Action (com.github.bordertech.wcomponents.Action)28 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)27 WButton (com.github.bordertech.wcomponents.WButton)20 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)15 WHeading (com.github.bordertech.wcomponents.WHeading)12 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)8 WTextField (com.github.bordertech.wcomponents.WTextField)7 WPanel (com.github.bordertech.wcomponents.WPanel)6 ValidatingAction (com.github.bordertech.wcomponents.validation.ValidatingAction)6 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)4 WContainer (com.github.bordertech.wcomponents.WContainer)4 WLabel (com.github.bordertech.wcomponents.WLabel)4 WMenu (com.github.bordertech.wcomponents.WMenu)4 WMenuItem (com.github.bordertech.wcomponents.WMenuItem)4 WRadioButtonSelect (com.github.bordertech.wcomponents.WRadioButtonSelect)4 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)4 Margin (com.github.bordertech.wcomponents.Margin)3 WText (com.github.bordertech.wcomponents.WText)3 Equal (com.github.bordertech.wcomponents.subordinate.Equal)3 Rule (com.github.bordertech.wcomponents.subordinate.Rule)3