Search in sources :

Example 1 with WRepeater

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

the class TreeUtil_Test method initTree.

@Before
public void initTree() {
    root = new WApplication();
    containerChild = new WContainer();
    simpleChild = new WTextField();
    repeatedComponent = new WText();
    repeaterChild = new WRepeater(repeatedComponent);
    grandChild = new WTextArea();
    cardManager = new WCardManager();
    card1 = new WText();
    card2 = new WText();
    root.add(containerChild);
    root.add(simpleChild);
    root.add(repeaterChild);
    root.add(cardManager);
    containerChild.add(grandChild);
    cardManager.add(card1);
    cardManager.add(card2);
    root.setLocked(true);
    setActiveContext(new UIContextImpl());
    repeaterChild.setData(Arrays.asList(new String[] { "1", "2", "3" }));
}
Also used : WTextArea(com.github.bordertech.wcomponents.WTextArea) WContainer(com.github.bordertech.wcomponents.WContainer) WApplication(com.github.bordertech.wcomponents.WApplication) WText(com.github.bordertech.wcomponents.WText) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) WCardManager(com.github.bordertech.wcomponents.WCardManager) WTextField(com.github.bordertech.wcomponents.WTextField) WRepeater(com.github.bordertech.wcomponents.WRepeater) Before(org.junit.Before)

Example 2 with WRepeater

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

the class WRepeaterRenderer method doRender.

/**
 * Paints the given WText.
 *
 * @param component the WText to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WRepeater repeater = (WRepeater) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("ui:panel");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendClose();
    xml.appendTag("ui:content");
    paintRows(repeater, renderContext);
    xml.appendEndTag("ui:content");
    xml.appendEndTag("ui:panel");
}
Also used : WRepeater(com.github.bordertech.wcomponents.WRepeater) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 3 with WRepeater

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

the class WTableRowRendererRenderer method renderChildren.

/**
 * @param renderer the WTableRowRenderer to paint.
 * @param renderContext the RenderContext to paint to.
 * @param children the children ids
 */
private void renderChildren(final WTableRowRenderer renderer, final WebXmlRenderContext renderContext, final List<RowIdWrapper> children) {
    XmlStringBuilder xml = renderContext.getWriter();
    WTable table = renderer.getTable();
    WRepeater repeater = table.getRepeater();
    TableModel dataModel = table.getTableModel();
    // If there is a renderer specified by any child, we only paint content that has a specified renderer
    boolean rendererPresent = false;
    for (RowIdWrapper child : children) {
        if (dataModel.getRendererClass(child.getRowIndex()) != null) {
            rendererPresent = true;
            break;
        }
    }
    // Paint immediate children only.
    if (rendererPresent) {
        xml.appendTagOpen("ui:content");
        // Always span all columns
        xml.appendAttribute("spanAllCols", "true");
        xml.appendClose();
        for (RowIdWrapper child : children) {
            UIContext nodeContext = repeater.getRowContext(child, child.getPosition());
            WComponent expandedRenderer = renderer.getExpandedTreeNodeRenderer(dataModel.getRendererClass(child.getRowIndex()));
            if (expandedRenderer != null) {
                UIContextHolder.pushContext(nodeContext);
                try {
                    expandedRenderer.paint(renderContext);
                } finally {
                    UIContextHolder.popContext();
                }
            }
        }
        xml.appendEndTag("ui:content");
    } else {
        for (RowIdWrapper child : children) {
            UIContext nodeContext = repeater.getRowContext(child, child.getPosition());
            UIContextHolder.pushContext(nodeContext);
            try {
                render(renderer, renderContext);
            } finally {
                UIContextHolder.popContext();
            }
        }
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) RowIdWrapper(com.github.bordertech.wcomponents.WTable.RowIdWrapper) WTable(com.github.bordertech.wcomponents.WTable) UIContext(com.github.bordertech.wcomponents.UIContext) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WRepeater(com.github.bordertech.wcomponents.WRepeater) TableModel(com.github.bordertech.wcomponents.WTable.TableModel)

Example 4 with WRepeater

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

the class WDataTableRowRendererRenderer method doRender.

/**
 * Paints the given WDataTableRowRenderer.
 *
 * @param component the WDataTableRowRenderer to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WDataTableRowRenderer renderer = (WDataTableRowRenderer) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WDataTable table = renderer.getTable();
    TableDataModel dataModel = table.getDataModel();
    UIContext uic = UIContextHolder.getCurrent();
    final int numCols = table.getColumnCount();
    int[] columnOrder = table.getColumnOrder();
    int rowIndex = getRowIndex(table, (SubUIContext) uic);
    boolean unselectable = table.getSelectMode() != SelectMode.NONE && !dataModel.isSelectable(rowIndex);
    xml.appendTagOpen("ui:tr");
    xml.appendAttribute("rowIndex", rowIndex);
    xml.appendOptionalAttribute("unselectable", unselectable, "true");
    xml.appendOptionalAttribute("selected", table.getSelectedRows().contains(rowIndex), "true");
    xml.appendOptionalAttribute("filterValues", getFilterValues(dataModel, rowIndex));
    if (table.getExpandMode() != WDataTable.ExpandMode.NONE && dataModel instanceof TreeTableDataModel) {
        TableTreeNode node = ((TreeTableDataModel) dataModel).getNodeAtLine(rowIndex);
        boolean expandable = !node.isLeaf() && !node.isExpanded();
        xml.appendOptionalAttribute("expandable", expandable, "true");
    }
    xml.appendClose();
    if (table.isShowRowHeaders()) {
        xml.appendTag("ui:th");
        renderer.getRowHeader().paint(renderContext);
        xml.appendEndTag("ui:th");
    }
    for (int i = 0; i < numCols; i++) {
        int colIndex = columnOrder == null ? i : columnOrder[i];
        WTableColumn col = table.getColumn(colIndex);
        if (col.isVisible()) {
            xml.appendTag("ui:td");
            renderer.getRenderer(colIndex).paint(renderContext);
            xml.appendEndTag("ui:td");
        }
    }
    if (table.getExpandMode() != WDataTable.ExpandMode.NONE && dataModel instanceof TreeTableDataModel) {
        TreeTableDataModel treeModel = (TreeTableDataModel) dataModel;
        TableTreeNode node = treeModel.getNodeAtLine(rowIndex);
        if (!node.isLeaf()) {
            xml.appendTagOpen("ui:subtr");
            xml.appendOptionalAttribute("open", node.isExpanded(), "true");
            xml.appendClose();
            if (node.isExpanded() || table.getExpandMode() == ExpandMode.CLIENT) {
                WRepeater repeater = table.getRepeater();
                // If there a renderer specified by any child, we only paint content that has a specified renderer
                boolean rendererPresent = false;
                for (Iterator<TreeNode> i = node.children(); !rendererPresent && i.hasNext(); ) {
                    TableTreeNode child = (TableTreeNode) i.next();
                    if (child.getRendererClass() != null) {
                        rendererPresent = true;
                    }
                }
                // Paint immediate children only.
                if (rendererPresent) {
                    xml.appendTagOpen("ui:content");
                    xml.appendOptionalAttribute("spanAllCols", node.isRendererSpansAllCols(), "true");
                    xml.appendClose();
                    for (Iterator<TreeNode> i = node.children(); i.hasNext(); ) {
                        TableTreeNode child = (TableTreeNode) i.next();
                        Integer rowId = child.getRowIndex() - 1;
                        UIContext nodeContext = repeater.getRowContext(rowId);
                        WComponent expandedRenderer = renderer.getExpandedTreeNodeRenderer(child.getRendererClass());
                        if (expandedRenderer != null) {
                            UIContextHolder.pushContext(nodeContext);
                            try {
                                expandedRenderer.paint(renderContext);
                            } finally {
                                UIContextHolder.popContext();
                            }
                        }
                    }
                    xml.appendEndTag("ui:content");
                } else {
                    for (Iterator<TreeNode> i = node.children(); i.hasNext(); ) {
                        TableTreeNode child = (TableTreeNode) i.next();
                        Integer rowId = child.getRowIndex() - 1;
                        UIContext nodeContext = repeater.getRowContext(rowId);
                        UIContextHolder.pushContext(nodeContext);
                        try {
                            render(component, renderContext);
                        } finally {
                            UIContextHolder.popContext();
                        }
                    }
                }
            }
            xml.appendEndTag("ui:subtr");
        }
    }
    xml.appendEndTag("ui:tr");
}
Also used : TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) UIContext(com.github.bordertech.wcomponents.UIContext) SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WRepeater(com.github.bordertech.wcomponents.WRepeater) WComponent(com.github.bordertech.wcomponents.WComponent) WDataTable(com.github.bordertech.wcomponents.WDataTable) TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) TreeNode(com.github.bordertech.wcomponents.util.TreeNode) WDataTableRowRenderer(com.github.bordertech.wcomponents.WDataTableRowRenderer) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 5 with WRepeater

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

the class WRepeaterRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WRepeater repeater = new WRepeater();
    repeater.setRepeatedComponent(new WTextField());
    repeater.setBeanList(Arrays.asList(ROW_DATA));
    // Should have 3 inputs
    assertXpathEvaluatesTo("3", "count(//ui:textfield)", repeater);
    assertXpathEvaluatesTo(ROW_DATA[0], "//ui:textfield[1]/text()", repeater);
    assertXpathEvaluatesTo(ROW_DATA[1], "//ui:textfield[2]/text()", repeater);
    assertXpathEvaluatesTo(ROW_DATA[2], "//ui:textfield[3]/text()", repeater);
}
Also used : WRepeater(com.github.bordertech.wcomponents.WRepeater) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Aggregations

WRepeater (com.github.bordertech.wcomponents.WRepeater)9 UIContext (com.github.bordertech.wcomponents.UIContext)5 WComponent (com.github.bordertech.wcomponents.WComponent)4 WCardManager (com.github.bordertech.wcomponents.WCardManager)3 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)3 Container (com.github.bordertech.wcomponents.Container)2 TableDataModel (com.github.bordertech.wcomponents.TableDataModel)2 TableTreeNode (com.github.bordertech.wcomponents.TableTreeNode)2 TreeTableDataModel (com.github.bordertech.wcomponents.TreeTableDataModel)2 WInvisibleContainer (com.github.bordertech.wcomponents.WInvisibleContainer)2 WTextField (com.github.bordertech.wcomponents.WTextField)2 Test (org.junit.Test)2 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)1 WApplication (com.github.bordertech.wcomponents.WApplication)1 WContainer (com.github.bordertech.wcomponents.WContainer)1 WDataTable (com.github.bordertech.wcomponents.WDataTable)1 WDataTableRowRenderer (com.github.bordertech.wcomponents.WDataTableRowRenderer)1 SubUIContext (com.github.bordertech.wcomponents.WRepeater.SubUIContext)1 WRepeatRoot (com.github.bordertech.wcomponents.WRepeater.WRepeatRoot)1 WTable (com.github.bordertech.wcomponents.WTable)1