Search in sources :

Example 1 with WList

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

the class WListExample method preparePaintComponent.

/**
 * Override preparePaintComponent to perform initialisation the first time through.
 *
 * @param request the request being responded to.
 */
@Override
public void preparePaintComponent(final Request request) {
    if (!isInitialised()) {
        List<SimpleTableBean> items = new ArrayList<>();
        items.add(new SimpleTableBean("A", "none", "thing"));
        items.add(new SimpleTableBean("B", "some", "thing2"));
        items.add(new SimpleTableBean("C", "little", "thing3"));
        items.add(new SimpleTableBean("D", "lots", "thing4"));
        for (WList list : lists) {
            list.setData(items);
        }
        setInitialised(true);
    }
}
Also used : ArrayList(java.util.ArrayList) SimpleTableBean(com.github.bordertech.wcomponents.examples.common.SimpleTableBean) WList(com.github.bordertech.wcomponents.WList)

Example 2 with WList

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

the class WListExample method addList.

/**
 * Adds a list to the example.
 *
 * @param type the list type.
 * @param separator the list item separator.
 * @param renderBorder true to render a border around the list, false otherwise.
 * @param renderer the component to use to render items in the list.
 */
private void addList(final WList.Type type, final WList.Separator separator, final boolean renderBorder, final WComponent renderer) {
    WList list = new WList(type);
    if (separator != null) {
        list.setSeparator(separator);
    }
    list.setRenderBorder(renderBorder);
    list.setRepeatedComponent(renderer);
    add(list);
    lists.add(list);
}
Also used : WList(com.github.bordertech.wcomponents.WList)

Example 3 with WList

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

the class WListRenderer method doRender.

/**
 * Paints the given WList.
 *
 * @param component the WList to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WList list = (WList) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WList.Type type = list.getType();
    WList.Separator separator = list.getSeparator();
    Size gap = list.getSpace();
    String gapString = gap == null ? null : gap.toString();
    xml.appendTagOpen("ui:panel");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("type", list.isRenderBorder(), "box");
    xml.appendClose();
    // Render margin
    MarginRendererUtil.renderMargin(list, renderContext);
    xml.appendTagOpen("ui:listlayout");
    xml.appendOptionalAttribute("gap", gapString);
    if (type != null) {
        switch(type) {
            case FLAT:
                xml.appendAttribute("type", "flat");
                break;
            case STACKED:
                xml.appendAttribute("type", "stacked");
                break;
            case STRIPED:
                xml.appendAttribute("type", "striped");
                break;
            default:
                throw new SystemException("Unknown list type: " + type);
        }
    }
    if (separator != null) {
        switch(separator) {
            case BAR:
                xml.appendAttribute("separator", "bar");
                break;
            case DOT:
                xml.appendAttribute("separator", "dot");
                break;
            case NONE:
                break;
            default:
                throw new SystemException("Unknown list type: " + type);
        }
    }
    xml.appendClose();
    paintRows(list, renderContext);
    xml.appendEndTag("ui:listlayout");
    xml.appendEndTag("ui:panel");
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) Size(com.github.bordertech.wcomponents.Size) WList(com.github.bordertech.wcomponents.WList) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 4 with WList

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

the class WListRenderer_Test method testRenderedFormatNoBorder.

@Test
public void testRenderedFormatNoBorder() throws IOException, SAXException {
    // non-empty list, no border
    WList list = new WList(WList.Type.STRIPED);
    list.setRepeatedComponent(new WText());
    setActiveContext(createUIContext());
    list.setData(Arrays.asList(new String[] { "row1", "row2", "row3" }));
    assertSchemaMatch(list);
}
Also used : WText(com.github.bordertech.wcomponents.WText) WList(com.github.bordertech.wcomponents.WList) Test(org.junit.Test)

Example 5 with WList

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

the class WListOptionsExample method applySettings.

/**
 * Apply settings is responsible for building the list to be displayed and adding it to the container.
 */
private void applySettings() {
    container.reset();
    WList list = new WList((com.github.bordertech.wcomponents.WList.Type) ddType.getSelected());
    List<String> selected = (List<String>) cgBeanFields.getSelected();
    SimpleListRenderer renderer = new SimpleListRenderer(selected, cbRenderUsingFieldLayout.isSelected());
    list.setRepeatedComponent(renderer);
    list.setSeparator((Separator) ddSeparator.getSelected());
    list.setRenderBorder(cbRenderBorder.isSelected());
    container.add(list);
    List<SimpleTableBean> items = new ArrayList<>();
    items.add(new SimpleTableBean("A", "none", "thing"));
    items.add(new SimpleTableBean("B", "some", "thing2"));
    items.add(new SimpleTableBean("C", "little", "thing3"));
    items.add(new SimpleTableBean("D", "lots", "thing4"));
    list.setData(items);
    list.setVisible(cbVisible.isSelected());
}
Also used : ArrayList(java.util.ArrayList) SimpleTableBean(com.github.bordertech.wcomponents.examples.common.SimpleTableBean) ArrayList(java.util.ArrayList) List(java.util.List) WList(com.github.bordertech.wcomponents.WList) WList(com.github.bordertech.wcomponents.WList)

Aggregations

WList (com.github.bordertech.wcomponents.WList)12 Test (org.junit.Test)8 WText (com.github.bordertech.wcomponents.WText)7 SimpleTableBean (com.github.bordertech.wcomponents.examples.common.SimpleTableBean)2 ArrayList (java.util.ArrayList)2 Margin (com.github.bordertech.wcomponents.Margin)1 Size (com.github.bordertech.wcomponents.Size)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1 List (java.util.List)1