Search in sources :

Example 1 with WCollapsible

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

the class WCollapsibleRenderer method doRender.

/**
 * Paints the given WCollapsible.
 *
 * @param component the WCollapsible to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WCollapsible collapsible = (WCollapsible) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WComponent content = collapsible.getContent();
    boolean collapsed = collapsible.isCollapsed();
    xml.appendTagOpen("ui:collapsible");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendAttribute("groupName", collapsible.getGroupName());
    xml.appendOptionalAttribute("collapsed", collapsed, "true");
    xml.appendOptionalAttribute("hidden", collapsible.isHidden(), "true");
    switch(collapsible.getMode()) {
        case CLIENT:
            xml.appendAttribute("mode", "client");
            break;
        case LAZY:
            xml.appendAttribute("mode", "lazy");
            break;
        case EAGER:
            xml.appendAttribute("mode", "eager");
            break;
        case DYNAMIC:
            xml.appendAttribute("mode", "dynamic");
            break;
        case SERVER:
            xml.appendAttribute("mode", "server");
            break;
        default:
            throw new SystemException("Unknown collapsible mode: " + collapsible.getMode());
    }
    HeadingLevel level = collapsible.getHeadingLevel();
    if (level != null) {
        xml.appendAttribute("level", level.getLevel());
    }
    xml.appendClose();
    // Render margin
    MarginRendererUtil.renderMargin(collapsible, renderContext);
    // Label
    collapsible.getDecoratedLabel().paint(renderContext);
    // Content
    xml.appendTagOpen("ui:content");
    xml.appendAttribute("id", component.getId() + "-content");
    xml.appendClose();
    // Render content if not EAGER Mode or is EAGER and is the current AJAX trigger
    if (CollapsibleMode.EAGER != collapsible.getMode() || AjaxHelper.isCurrentAjaxTrigger(collapsible)) {
        // Visibility of content set in prepare paint
        content.paint(renderContext);
    }
    xml.appendEndTag("ui:content");
    xml.appendEndTag("ui:collapsible");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WCollapsible(com.github.bordertech.wcomponents.WCollapsible) SystemException(com.github.bordertech.wcomponents.util.SystemException) HeadingLevel(com.github.bordertech.wcomponents.HeadingLevel) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 2 with WCollapsible

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

the class WCollapsibleRenderer_Test method testDoRenderLazyCollapse.

@Test
public void testDoRenderLazyCollapse() throws IOException, SAXException, XpathException {
    WCollapsible collapsible = new WCollapsible(new WText(COLLAPSIBLE_CONTENT), COLLAPSIBLE_HEADING, WCollapsible.CollapsibleMode.LAZY);
    assertSchemaMatch(collapsible);
    assertXpathEvaluatesTo("lazy", "//ui:collapsible/@mode", collapsible);
    assertRenderContentCorrectly(collapsible, false, true);
}
Also used : WCollapsible(com.github.bordertech.wcomponents.WCollapsible) WText(com.github.bordertech.wcomponents.WText) Test(org.junit.Test)

Example 3 with WCollapsible

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

the class WCollapsibleRenderer_Test method testRenderedWithHeadingLevel.

@Test
public void testRenderedWithHeadingLevel() throws IOException, SAXException, XpathException {
    WCollapsible collapsible = new WCollapsible(new WText(COLLAPSIBLE_CONTENT), COLLAPSIBLE_HEADING, WCollapsible.CollapsibleMode.EAGER);
    assertSchemaMatch(collapsible);
    assertXpathNotExists("//ui:collapsible/@level", collapsible);
    // Set level
    collapsible.setHeadingLevel(HeadingLevel.H1);
    assertSchemaMatch(collapsible);
    assertXpathEvaluatesTo("1", "//ui:collapsible/@level", collapsible);
}
Also used : WCollapsible(com.github.bordertech.wcomponents.WCollapsible) WText(com.github.bordertech.wcomponents.WText) Test(org.junit.Test)

Example 4 with WCollapsible

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

the class WCollapsibleRenderer_Test method testDoRenderDynamicCollapse.

@Test
public void testDoRenderDynamicCollapse() throws IOException, SAXException, XpathException {
    WCollapsible collapsible = new WCollapsible(new WText(COLLAPSIBLE_CONTENT), COLLAPSIBLE_HEADING, WCollapsible.CollapsibleMode.DYNAMIC);
    assertSchemaMatch(collapsible);
    assertXpathEvaluatesTo("dynamic", "//ui:collapsible/@mode", collapsible);
    assertRenderContentCorrectly(collapsible, false, true);
}
Also used : WCollapsible(com.github.bordertech.wcomponents.WCollapsible) WText(com.github.bordertech.wcomponents.WText) Test(org.junit.Test)

Example 5 with WCollapsible

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

the class WCollapsibleOptionsExample method applySettings.

/**
 * applySettings creates the WCollapsible, and loads it into the container.
 */
private void applySettings() {
    // reset the container.
    container.reset();
    // create the new collapsible.
    WText component1 = new WText("Here is some text that is collapsible via ajax.");
    WCollapsible collapsible1 = new WCollapsible(component1, "Collapsible", (CollapsibleMode) rbCollapsibleSelect.getSelected());
    collapsible1.setCollapsed(cbCollapsed.isSelected());
    collapsible1.setVisible(cbVisible.isSelected());
    if (collapsible1.getMode() == CollapsibleMode.DYNAMIC) {
        component1.setText(component1.getText() + "\u00a0Generated on " + new Date());
    }
    if (drpHeadingLevels.getSelected() != null) {
        collapsible1.setHeadingLevel((HeadingLevel) drpHeadingLevels.getSelected());
    }
    // add the new collapsible to the container.
    container.add(collapsible1);
}
Also used : WCollapsible(com.github.bordertech.wcomponents.WCollapsible) WText(com.github.bordertech.wcomponents.WText) Date(java.util.Date)

Aggregations

WCollapsible (com.github.bordertech.wcomponents.WCollapsible)11 WText (com.github.bordertech.wcomponents.WText)10 Test (org.junit.Test)9 HeadingLevel (com.github.bordertech.wcomponents.HeadingLevel)1 Margin (com.github.bordertech.wcomponents.Margin)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1 Date (java.util.Date)1