Search in sources :

Example 26 with WPanel

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

the class WAjaxControlRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WContainer root = new WContainer();
    WButton trigger = new WButton("x");
    WPanel target1 = new WPanel();
    WPanel target2 = new WPanel();
    WPanel target3 = new WPanel();
    WAjaxControl control = new WAjaxControl(trigger);
    root.add(trigger);
    root.add(target1);
    root.add(target2);
    root.add(target3);
    root.add(control);
    // No Targets
    assertSchemaMatch(root);
    assertXpathEvaluatesTo("0", "count(//ui:ajaxtrigger)", root);
    // With Targets
    control.addTargets(new AjaxTarget[] { target1, target2, target3 });
    setActiveContext(createUIContext());
    assertSchemaMatch(root);
    assertXpathEvaluatesTo(trigger.getId(), "//ui:ajaxtrigger/@triggerId", root);
    assertXpathNotExists("//ui:ajaxtrigger/@loadOnce", root);
    assertXpathNotExists("//ui:ajaxtrigger/@delay", root);
    assertXpathEvaluatesTo("3", "count(//ui:ajaxtrigger/ui:ajaxtargetid)", root);
    assertXpathEvaluatesTo(target1.getId(), "//ui:ajaxtrigger/ui:ajaxtargetid[1]/@targetId", root);
    assertXpathEvaluatesTo(target2.getId(), "//ui:ajaxtrigger/ui:ajaxtargetid[2]/@targetId", root);
    assertXpathEvaluatesTo(target3.getId(), "//ui:ajaxtrigger/ui:ajaxtargetid[3]/@targetId", root);
    control.setLoadOnce(true);
    assertSchemaMatch(root);
    assertXpathEvaluatesTo("true", "//ui:ajaxtrigger/@loadOnce", root);
    // remove loadOnce then reset it using loadCount
    control.setLoadOnce(false);
    assertSchemaMatch(root);
    assertXpathNotExists("//ui:ajaxtrigger/@loadOnce", root);
    // With Targets and optional attributes
    // any number greateer than 0...
    control.setLoadCount(6);
    control.setDelay(1000);
    assertSchemaMatch(root);
    assertXpathEvaluatesTo(trigger.getId(), "//ui:ajaxtrigger/@triggerId", root);
    assertXpathEvaluatesTo("true", "//ui:ajaxtrigger/@loadOnce", root);
    assertXpathEvaluatesTo("1000", "//ui:ajaxtrigger/@delay", root);
    assertXpathEvaluatesTo("3", "count(//ui:ajaxtrigger/ui:ajaxtargetid)", root);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) WPanel(com.github.bordertech.wcomponents.WPanel) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 27 with WPanel

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

the class ColumnLayoutRenderer method doRender.

/**
 * Paints the given WPanel's children.
 *
 * @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();
    ColumnLayout layout = (ColumnLayout) panel.getLayout();
    int childCount = panel.getChildCount();
    Size hgap = layout.getHorizontalGap();
    String hgapString = hgap == null ? null : hgap.toString();
    Size vgap = layout.getVerticalGap();
    String vgapString = vgap == null ? null : vgap.toString();
    int cols = layout.getColumnCount();
    xml.appendTagOpen("ui:columnlayout");
    xml.appendOptionalAttribute("hgap", hgapString);
    xml.appendOptionalAttribute("vgap", vgapString);
    xml.appendClose();
    // Column Definitions
    for (int col = 0; col < cols; col++) {
        xml.appendTagOpen("ui:column");
        int width = layout.getColumnWidth(col);
        xml.appendOptionalAttribute("width", width > 0, width);
        switch(layout.getColumnAlignment(col)) {
            case LEFT:
                // left is assumed if omitted
                break;
            case RIGHT:
                xml.appendAttribute("align", "right");
                break;
            case CENTER:
                xml.appendAttribute("align", "center");
                break;
            default:
                throw new IllegalArgumentException("Invalid alignment: " + layout.getColumnAlignment(col));
        }
        xml.appendEnd();
    }
    for (int i = 0; i < childCount; i++) {
        xml.appendTag("ui:cell");
        WComponent child = panel.getChildAt(i);
        child.paint(renderContext);
        xml.appendEndTag("ui:cell");
    }
    xml.appendEndTag("ui:columnlayout");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Size(com.github.bordertech.wcomponents.Size) WPanel(com.github.bordertech.wcomponents.WPanel) ColumnLayout(com.github.bordertech.wcomponents.layout.ColumnLayout) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 28 with WPanel

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

the class WButtonRenderer_Test method testAllOptions.

@Test
public void testAllOptions() throws IOException, SAXException, XpathException {
    WButton button = new WButton("All");
    button.setDisabled(true);
    setFlag(button, ComponentModel.HIDE_FLAG, true);
    button.setToolTip("Title");
    button.setAccessKey('T');
    button.setImageUrl("http://localhost/image.png");
    button.setImagePosition(ImagePosition.EAST);
    button.setRenderAsLink(true);
    button.setAjaxTarget(new WTextField());
    button.setPopupTrigger(true);
    setActiveContext(createUIContext());
    WPanel validationComponent = new WPanel();
    button.setAction(new ValidatingAction(new WValidationErrors(), validationComponent) {

        @Override
        public void executeOnValid(final ActionEvent event) {
        // Do nothing
        }
    });
    WContainer root = new WContainer();
    root.add(button);
    root.add(validationComponent);
    assertXpathExists("//html:button[@id]", button);
    assertXpathExists("//html:button[contains(@class, 'wc-linkbutton')]", button);
    assertXpathEvaluatesTo(button.getText(), "//html:button", button);
    assertXpathEvaluatesTo("disabled", "//html:button/@disabled", button);
    assertXpathEvaluatesTo("hidden", "//html:button/@hidden", button);
    assertXpathEvaluatesTo(button.getToolTip(), "//html:button/@title", button);
    assertXpathUrlEvaluatesTo(button.getImageUrl(), "//html:button//html:img/@src", button);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imge')]", button);
    assertXpathEvaluatesTo(button.getAccessKeyAsString(), "//html:button/@accesskey", button);
    assertXpathEvaluatesTo("true", "//html:button/@aria-haspopup", button);
    assertXpathEvaluatesTo(validationComponent.getId(), "//html:button/@data-wc-validate", button);
    assertXpathEvaluatesTo(button.getId(), "//ui:ajaxtrigger/@triggerId", button);
    button.setImagePosition(ImagePosition.NORTH);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgn')]", button);
    button.setImagePosition(ImagePosition.SOUTH);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgs')]", button);
    button.setImagePosition(ImagePosition.WEST);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgw')]", button);
    button.setClientCommandOnly(true);
    assertXpathEvaluatesTo("button", "//html:button/@type", button);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) WValidationErrors(com.github.bordertech.wcomponents.validation.WValidationErrors) WButton(com.github.bordertech.wcomponents.WButton) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 29 with WPanel

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

the class WFieldErrorIndicatorRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WContainer root = new WContainer();
    WPanel target = new WPanel();
    WFieldErrorIndicator indicator = new WFieldErrorIndicator(target);
    root.add(indicator);
    root.add(target);
    List<Diagnostic> diags = new ArrayList<>();
    diags.add(new DiagnosticImpl(Diagnostic.ERROR, target, getMaliciousContent()));
    root.showErrorIndicators(diags);
    assertSafeContent(root);
}
Also used : WFieldErrorIndicator(com.github.bordertech.wcomponents.validation.WFieldErrorIndicator) WContainer(com.github.bordertech.wcomponents.WContainer) DiagnosticImpl(com.github.bordertech.wcomponents.validation.DiagnosticImpl) WPanel(com.github.bordertech.wcomponents.WPanel) ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) Test(org.junit.Test)

Example 30 with WPanel

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

the class WFieldWarningIndicatorRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WContainer root = new WContainer();
    WPanel target = new WPanel();
    WFieldWarningIndicator indicator = new WFieldWarningIndicator(target);
    root.add(target);
    root.add(indicator);
    // Simulate Warning Message
    setActiveContext(createUIContext());
    List<Diagnostic> diags = new ArrayList<>();
    diags.add(new DiagnosticImpl(Diagnostic.WARNING, target, "Test Warning"));
    root.showWarningIndicators(diags);
    // Validate Schema
    assertSchemaMatch(root);
    // Check Attributes
    assertXpathEvaluatesTo(indicator.getId(), "//ui:fieldindicator/@id", root);
    assertXpathEvaluatesTo("warn", "//ui:fieldindicator/@type", root);
    assertXpathEvaluatesTo(target.getId(), "//ui:fieldindicator/@for", root);
    // Check Message
    assertXpathEvaluatesTo("Test Warning", "//ui:fieldindicator/ui:message", root);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) DiagnosticImpl(com.github.bordertech.wcomponents.validation.DiagnosticImpl) WPanel(com.github.bordertech.wcomponents.WPanel) ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) WFieldWarningIndicator(com.github.bordertech.wcomponents.validation.WFieldWarningIndicator) Test(org.junit.Test)

Aggregations

WPanel (com.github.bordertech.wcomponents.WPanel)77 Test (org.junit.Test)39 WHeading (com.github.bordertech.wcomponents.WHeading)17 WText (com.github.bordertech.wcomponents.WText)17 FlowLayout (com.github.bordertech.wcomponents.layout.FlowLayout)16 WButton (com.github.bordertech.wcomponents.WButton)13 ColumnLayout (com.github.bordertech.wcomponents.layout.ColumnLayout)10 WContainer (com.github.bordertech.wcomponents.WContainer)9 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)9 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)8 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)8 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)7 WLabel (com.github.bordertech.wcomponents.WLabel)7 Action (com.github.bordertech.wcomponents.Action)6 WTextField (com.github.bordertech.wcomponents.WTextField)6 ArrayList (java.util.ArrayList)6 Size (com.github.bordertech.wcomponents.Size)5 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)5 BorderLayout (com.github.bordertech.wcomponents.layout.BorderLayout)5 Alignment (com.github.bordertech.wcomponents.layout.ColumnLayout.Alignment)5