Search in sources :

Example 1 with RowIdWrapper

use of com.github.bordertech.wcomponents.WTable.RowIdWrapper in project wcomponents by BorderTech.

the class WTableRenderer method doPaintRows.

/**
 * Override paintRow so that we only paint the first-level nodes for tree-tables.
 *
 * @param table the table to paint the rows for.
 * @param renderContext the RenderContext to paint to.
 */
private void doPaintRows(final WTable table, final WebXmlRenderContext renderContext) {
    TableRepeater repeater = table.getRepeater();
    WComponent row = repeater.getRepeatedComponent();
    List<RowIdWrapper> wrappers = repeater.getBeanList();
    Set<?> otherSelectedRows = new HashSet<>(table.getSelectedRows());
    int index = -1;
    for (RowIdWrapper wrapper : wrappers) {
        index++;
        Object rowKey = wrapper.getRowKey();
        if (table.getSelectedRows().contains(rowKey)) {
            otherSelectedRows.remove(rowKey);
        }
        // Child rows handled by the layout, so dont paint the row
        if (wrapper.getParent() != null) {
            continue;
        }
        // Each row has its own context. This is why we can reuse the same
        // WComponent instance for each row.
        UIContext rowContext = repeater.getRowContext(wrapper, index);
        UIContextHolder.pushContext(rowContext);
        try {
            row.paint(renderContext);
        } finally {
            UIContextHolder.popContext();
        }
    }
    this.selectedOnOther = otherSelectedRows.size();
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) TableRepeater(com.github.bordertech.wcomponents.WTable.TableRepeater) RowIdWrapper(com.github.bordertech.wcomponents.WTable.RowIdWrapper) UIContext(com.github.bordertech.wcomponents.UIContext) HashSet(java.util.HashSet)

Example 2 with RowIdWrapper

use of com.github.bordertech.wcomponents.WTable.RowIdWrapper 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 3 with RowIdWrapper

use of com.github.bordertech.wcomponents.WTable.RowIdWrapper in project wcomponents by BorderTech.

the class WTableRowRendererRenderer method doRender.

/**
 * Paints the given WTableRowRenderer.
 *
 * @param component the WTableRowRenderer to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WTableRowRenderer renderer = (WTableRowRenderer) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WTable table = renderer.getTable();
    TableModel dataModel = table.getTableModel();
    int[] columnOrder = table.getColumnOrder();
    final int numCols = columnOrder == null ? table.getColumnCount() : columnOrder.length;
    // Get current row details
    RowIdWrapper wrapper = renderer.getCurrentRowIdWrapper();
    List<Integer> rowIndex = wrapper.getRowIndex();
    boolean tableSelectable = table.getSelectMode() != SelectMode.NONE;
    boolean rowSelectable = tableSelectable && dataModel.isSelectable(rowIndex);
    boolean rowSelected = rowSelectable && table.getSelectedRows().contains(wrapper.getRowKey());
    boolean tableExpandable = table.getExpandMode() != WTable.ExpandMode.NONE;
    boolean rowExpandable = tableExpandable && dataModel.isExpandable(rowIndex) && wrapper.hasChildren();
    boolean rowExpanded = rowExpandable && table.getExpandedRows().contains(wrapper.getRowKey());
    String rowIndexAsString = TableUtil.rowIndexListToString(rowIndex);
    xml.appendTagOpen("ui:tr");
    xml.appendAttribute("rowIndex", rowIndexAsString);
    xml.appendOptionalAttribute("unselectable", !rowSelectable, "true");
    xml.appendOptionalAttribute("selected", rowSelected, "true");
    xml.appendOptionalAttribute("expandable", rowExpandable && !rowExpanded, "true");
    xml.appendClose();
    // wrote the column cell.
    // need this before we get into the loop
    boolean isRowHeader = table.isRowHeaders();
    for (int i = 0; i < numCols; i++) {
        int colIndex = columnOrder == null ? i : columnOrder[i];
        WTableColumn col = table.getColumn(colIndex);
        String cellTag = "ui:td";
        if (col.isVisible()) {
            if (isRowHeader) {
                // The first rendered column will be the row header.
                cellTag = "ui:th";
                // only set one col as the row header.
                isRowHeader = false;
            }
            xml.appendTag(cellTag);
            renderer.getRenderer(colIndex).paint(renderContext);
            xml.appendEndTag(cellTag);
        }
    }
    if (rowExpandable) {
        xml.appendTagOpen("ui:subtr");
        xml.appendOptionalAttribute("open", rowExpanded, "true");
        xml.appendClose();
        if (rowExpanded || table.getExpandMode() == ExpandMode.CLIENT) {
            renderChildren(renderer, renderContext, wrapper.getChildren());
        }
        xml.appendEndTag("ui:subtr");
    }
    xml.appendEndTag("ui:tr");
}
Also used : RowIdWrapper(com.github.bordertech.wcomponents.WTable.RowIdWrapper) WTableRowRenderer(com.github.bordertech.wcomponents.WTableRowRenderer) WTable(com.github.bordertech.wcomponents.WTable) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) TableModel(com.github.bordertech.wcomponents.WTable.TableModel)

Example 4 with RowIdWrapper

use of com.github.bordertech.wcomponents.WTable.RowIdWrapper in project wcomponents by BorderTech.

the class WTableRowRenderer method getCurrentRowIdWrapper.

/**
 * Retrieve the current {@link RowIdWrapper}.
 * <p>
 * Intended for internal use only.
 * </p>
 *
 * @return the current row id wrapper, or null if not found
 */
public RowIdWrapper getCurrentRowIdWrapper() {
    UIContext uic = UIContextHolder.getCurrent();
    if (uic instanceof SubUIContext) {
        int index = ((SubUIContext) uic).getRowIndex();
        RowIdWrapper wrapper = table.getRepeater().getBeanList().get(index);
        return wrapper;
    }
    return null;
}
Also used : SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) RowIdWrapper(com.github.bordertech.wcomponents.WTable.RowIdWrapper) SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext)

Example 5 with RowIdWrapper

use of com.github.bordertech.wcomponents.WTable.RowIdWrapper in project wcomponents by BorderTech.

the class TableUtil method getCurrentRowIndex.

/**
 * This can be used by column components on a {@link WTable} to determine the current row index.
 *
 * @param component the column component
 * @return the row index for the current row, or null if no row details
 */
public static List<Integer> getCurrentRowIndex(final WComponent component) {
    UIContext uic = UIContextHolder.getCurrent();
    // Check have correct context
    if (!(uic instanceof SubUIContext)) {
        return null;
    }
    // Find the table
    WTable table = WebUtilities.getAncestorOfClass(WTable.class, component);
    if (table == null) {
        return null;
    }
    int repeaterIdx = ((SubUIContext) uic).getRowIndex();
    RowIdWrapper wrapper = table.getRepeater().getBeanList().get(repeaterIdx);
    return wrapper.getRowIndex();
}
Also used : SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) RowIdWrapper(com.github.bordertech.wcomponents.WTable.RowIdWrapper) SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) UIContext(com.github.bordertech.wcomponents.UIContext) WTable(com.github.bordertech.wcomponents.WTable)

Aggregations

RowIdWrapper (com.github.bordertech.wcomponents.WTable.RowIdWrapper)7 UIContext (com.github.bordertech.wcomponents.UIContext)3 WTable (com.github.bordertech.wcomponents.WTable)3 WComponent (com.github.bordertech.wcomponents.WComponent)2 SubUIContext (com.github.bordertech.wcomponents.WRepeater.SubUIContext)2 TableModel (com.github.bordertech.wcomponents.WTable.TableModel)2 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)2 HashSet (java.util.HashSet)2 WRepeater (com.github.bordertech.wcomponents.WRepeater)1 TableRepeater (com.github.bordertech.wcomponents.WTable.TableRepeater)1 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)1 WTableRowRenderer (com.github.bordertech.wcomponents.WTableRowRenderer)1 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)1 Test (org.junit.Test)1