Search in sources :

Example 56 with WButton

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

the class WDialogExample_Test method testModalDialogCloseOnCancel.

@Test
public void testModalDialogCloseOnCancel() {
    // Launch the web browser to the LDE
    SeleniumWComponentsWebDriver driver = getDriver();
    WDialogExample example = (WDialogExample) getUi();
    String expectedText = example.getModalText();
    final WButton testButton = example.getModalButton();
    // Display the modal dialog
    driver.findElement(byWComponent(testButton)).click();
    Assert.assertTrue("Dialog must be open.", driver.getDialog().isOpen());
    driver.getDialog().close();
    Assert.assertFalse("Should not be displaying the dialog", driver.isOpenDialog());
    Assert.assertFalse("Should not be displaying the dialog", driver.getPageSource().contains(expectedText));
}
Also used : SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 57 with WButton

use of com.github.bordertech.wcomponents.WButton 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)

Example 58 with WButton

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

the class WDataTableRenderer method paintTableActions.

/**
 * Paints the table actions of the table.
 *
 * @param table the table to paint the table actions for.
 * @param renderContext the RenderContext to paint to.
 */
private void paintTableActions(final WDataTable table, final WebXmlRenderContext renderContext) {
    XmlStringBuilder xml = renderContext.getWriter();
    List<WButton> tableActions = table.getActions();
    if (!tableActions.isEmpty()) {
        boolean hasActions = false;
        for (WButton button : tableActions) {
            if (!button.isVisible()) {
                continue;
            }
            if (!hasActions) {
                hasActions = true;
                xml.appendTag("ui:actions");
            }
            xml.appendTag("ui:action");
            List<WDataTable.ActionConstraint> constraints = table.getActionConstraints(button);
            if (constraints != null) {
                for (WDataTable.ActionConstraint constraint : constraints) {
                    int minRows = constraint.getMinSelectedRowCount();
                    int maxRows = constraint.getMaxSelectedRowCount();
                    String message = constraint.getMessage();
                    String type = constraint.isError() ? "error" : "warning";
                    xml.appendTagOpen("ui:condition");
                    xml.appendOptionalAttribute("minSelectedRows", minRows > 0, minRows);
                    xml.appendOptionalAttribute("maxSelectedRows", maxRows > 0, maxRows);
                    xml.appendAttribute("type", type);
                    xml.appendAttribute("message", I18nUtilities.format(null, message));
                    xml.appendEnd();
                }
            }
            button.paint(renderContext);
            xml.appendEndTag("ui:action");
        }
        if (hasActions) {
            xml.appendEndTag("ui:actions");
        }
    }
}
Also used : WDataTable(com.github.bordertech.wcomponents.WDataTable) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WButton(com.github.bordertech.wcomponents.WButton)

Example 59 with WButton

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

the class WPanelRenderer method doRender.

/**
 * Paints the given container.
 *
 * @param component the container to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WPanel panel = (WPanel) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WButton submitButton = panel.getDefaultSubmitButton();
    String submitId = submitButton == null ? null : submitButton.getId();
    String titleText = panel.getTitleText();
    boolean renderChildren = isRenderContent(panel);
    xml.appendTagOpen("ui:panel");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    if (PanelMode.LAZY.equals(panel.getMode())) {
        xml.appendOptionalAttribute("hidden", !renderChildren, "true");
    } else {
        xml.appendOptionalAttribute("hidden", component.isHidden(), "true");
    }
    xml.appendOptionalAttribute("buttonId", submitId);
    xml.appendOptionalAttribute("title", titleText);
    xml.appendOptionalAttribute("accessKey", Util.upperCase(panel.getAccessKeyAsString()));
    xml.appendOptionalAttribute("type", getPanelType(panel));
    xml.appendOptionalAttribute("mode", getPanelMode(panel));
    xml.appendClose();
    // Render margin
    MarginRendererUtil.renderMargin(panel, renderContext);
    if (renderChildren) {
        renderChildren(panel, renderContext);
    } else {
        // Content will be loaded via AJAX
        xml.append("<ui:content/>");
    }
    xml.appendEndTag("ui:panel");
}
Also used : WPanel(com.github.bordertech.wcomponents.WPanel) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WButton(com.github.bordertech.wcomponents.WButton)

Example 60 with WButton

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

the class WNumberFieldRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WNumberField numberField = new WNumberField();
    WButton button = new WButton("Test");
    WContainer root = new WContainer();
    root.add(numberField);
    root.add(button);
    assertSchemaMatch(numberField);
    assertXpathEvaluatesTo(numberField.getId(), "//ui:numberfield/@id", numberField);
    assertXpathNotExists("//ui:numberfield/@disabled", numberField);
    assertXpathNotExists("//ui:numberfield/@hidden", numberField);
    assertXpathNotExists("//ui:numberfield/@required", numberField);
    assertXpathNotExists("//ui:numberfield/@readOnly", numberField);
    assertXpathNotExists("//ui:numberfield/@toolTip", numberField);
    assertXpathNotExists("//ui:numberfield/@accessibleText", numberField);
    assertXpathNotExists("//ui:numberfield/@min", numberField);
    assertXpathNotExists("//ui:numberfield/@max", numberField);
    assertXpathNotExists("//ui:numberfield/@step", numberField);
    assertXpathNotExists("//ui:numberfield/@decimals", numberField);
    assertXpathNotExists("//ui:numberfield/@buttonId", numberField);
    numberField.setDisabled(true);
    assertSchemaMatch(numberField);
    assertXpathEvaluatesTo("true", "//ui:numberfield/@disabled", numberField);
    setFlag(numberField, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(numberField);
    assertXpathEvaluatesTo("true", "//ui:numberfield/@hidden", numberField);
    numberField.setMandatory(true);
    assertSchemaMatch(numberField);
    assertXpathEvaluatesTo("true", "//ui:numberfield/@required", numberField);
    numberField.setToolTip("toolTip");
    assertSchemaMatch(numberField);
    assertXpathEvaluatesTo(numberField.getToolTip(), "//ui:numberfield/@toolTip", numberField);
    numberField.setAccessibleText("accessibleText");
    assertSchemaMatch(numberField);
    assertXpathEvaluatesTo(numberField.getAccessibleText(), "//ui:numberfield/@accessibleText", numberField);
    numberField.setMinValue(45);
    assertSchemaMatch(numberField);
    assertXpathEvaluatesTo("45", "//ui:numberfield/@min", numberField);
    numberField.setMaxValue(50);
    assertSchemaMatch(numberField);
    assertXpathEvaluatesTo("50", "//ui:numberfield/@max", numberField);
    numberField.setStep(0.5);
    assertSchemaMatch(numberField);
    assertXpathEvaluatesTo("0.5", "//ui:numberfield/@step", numberField);
    numberField.setDecimalPlaces(2);
    assertSchemaMatch(numberField);
    assertXpathEvaluatesTo("2", "//ui:numberfield/@decimals", numberField);
    numberField.setDefaultSubmitButton(button);
    assertSchemaMatch(numberField);
    assertXpathEvaluatesTo(button.getId(), "//ui:numberfield/@buttonId", numberField);
    numberField.setNumber(123);
    assertSchemaMatch(numberField);
    assertXpathEvaluatesTo("123", "normalize-space(//ui:numberfield)", numberField);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WNumberField(com.github.bordertech.wcomponents.WNumberField) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Aggregations

WButton (com.github.bordertech.wcomponents.WButton)76 Test (org.junit.Test)39 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)25 Action (com.github.bordertech.wcomponents.Action)20 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)18 WTextField (com.github.bordertech.wcomponents.WTextField)17 WHeading (com.github.bordertech.wcomponents.WHeading)16 WContainer (com.github.bordertech.wcomponents.WContainer)14 WPanel (com.github.bordertech.wcomponents.WPanel)13 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)11 ValidatingAction (com.github.bordertech.wcomponents.validation.ValidatingAction)10 WLabel (com.github.bordertech.wcomponents.WLabel)9 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)8 UIContext (com.github.bordertech.wcomponents.UIContext)7 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)7 WText (com.github.bordertech.wcomponents.WText)6 WDataTable (com.github.bordertech.wcomponents.WDataTable)5 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)5 WTable (com.github.bordertech.wcomponents.WTable)5 AdapterBasicTableModel (com.github.bordertech.wcomponents.AdapterBasicTableModel)4