Search in sources :

Example 1 with WSelectToggle

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

the class WSelectToggleRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    // Client-side
    WCheckBox target = new WCheckBox();
    WSelectToggle toggle = new WSelectToggle(true);
    toggle.setTarget(target);
    WContainer root = new WContainer();
    root.add(toggle);
    root.add(target);
    assertSchemaMatch(toggle);
    assertXpathNotExists("//ui:selecttoggle/@roundTrip", toggle);
    assertXpathEvaluatesTo(toggle.getId(), "//ui:selecttoggle/@id", toggle);
    assertXpathEvaluatesTo(toggle.getTarget().getId(), "//ui:selecttoggle/@target", toggle);
    assertXpathEvaluatesTo("control", "//ui:selecttoggle/@renderAs", toggle);
    assertXpathEvaluatesTo("none", "//ui:selecttoggle/@selected", toggle);
    // Test Server-side
    toggle.setClientSide(false);
    assertSchemaMatch(toggle);
    assertXpathEvaluatesTo("true", "//ui:selecttoggle/@roundTrip", toggle);
    // Test when selected
    toggle.setState(WSelectToggle.State.ALL);
    assertSchemaMatch(toggle);
    assertXpathEvaluatesTo("all", "//ui:selecttoggle/@selected", toggle);
    // Test when partially selected
    toggle.setState(WSelectToggle.State.SOME);
    assertSchemaMatch(toggle);
    assertXpathEvaluatesTo("some", "//ui:selecttoggle/@selected", toggle);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WSelectToggle(com.github.bordertech.wcomponents.WSelectToggle) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) Test(org.junit.Test)

Example 2 with WSelectToggle

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

the class WSelectToggleRenderer method doRender.

/**
 * Paints the given WSelectToggle.
 *
 * @param component the WSelectToggle to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WSelectToggle toggle = (WSelectToggle) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("ui:selecttoggle");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    State state = toggle.getState();
    if (State.ALL.equals(state)) {
        xml.appendAttribute("selected", "all");
    } else if (State.NONE.equals(state)) {
        xml.appendAttribute("selected", "none");
    } else {
        xml.appendAttribute("selected", "some");
    }
    xml.appendOptionalAttribute("disabled", toggle.isDisabled(), "true");
    xml.appendAttribute("target", toggle.getTarget().getId());
    xml.appendAttribute("renderAs", toggle.isRenderAsText() ? "text" : "control");
    xml.appendOptionalAttribute("roundTrip", !toggle.isClientSide(), "true");
    xml.appendEnd();
}
Also used : State(com.github.bordertech.wcomponents.WSelectToggle.State) WSelectToggle(com.github.bordertech.wcomponents.WSelectToggle) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 3 with WSelectToggle

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

the class WSelectToggleRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WSelectToggle component = new WSelectToggle();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(component) instanceof WSelectToggleRenderer);
}
Also used : WSelectToggle(com.github.bordertech.wcomponents.WSelectToggle) Test(org.junit.Test)

Aggregations

WSelectToggle (com.github.bordertech.wcomponents.WSelectToggle)3 Test (org.junit.Test)2 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)1 WContainer (com.github.bordertech.wcomponents.WContainer)1 State (com.github.bordertech.wcomponents.WSelectToggle.State)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1