use of com.github.bordertech.wcomponents.XmlStringBuilder 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();
}
}
}
}
use of com.github.bordertech.wcomponents.XmlStringBuilder 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");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WTimeoutWarningRenderer method doRender.
/**
* Paints the given WTimeoutWarning if the component's timeout period is greater than 0.
*
* @param component the WTimeoutWarning to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WTimeoutWarning warning = (WTimeoutWarning) component;
XmlStringBuilder xml = renderContext.getWriter();
final int timoutPeriod = warning.getTimeoutPeriod();
if (timoutPeriod > 0) {
xml.appendTagOpen("ui:session");
xml.appendAttribute("timeout", String.valueOf(timoutPeriod));
int warningPeriod = warning.getWarningPeriod();
xml.appendOptionalAttribute("warn", warningPeriod > 0, warningPeriod);
xml.appendEnd();
}
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WTreeRenderer method doRender.
/**
* Paints the given WTree.
*
* @param component the WTree to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WTree tree = (WTree) component;
XmlStringBuilder xml = renderContext.getWriter();
// Check if rendering an open item request
String openId = tree.getOpenRequestItemId();
if (openId != null) {
handleOpenItemRequest(tree, xml, openId);
return;
}
// Check the tree has tree items (WCAG requirement)
TreeItemModel model = tree.getTreeModel();
if (model == null || model.getRowCount() <= 0) {
LOG.warn("Tree not rendered as it has no items.");
return;
}
xml.appendTagOpen("ui:tree");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("htree", WTree.Type.HORIZONTAL == tree.getType(), "true");
xml.appendOptionalAttribute("multiple", WTree.SelectMode.MULTIPLE == tree.getSelectMode(), "true");
xml.appendOptionalAttribute("disabled", tree.isDisabled(), "true");
xml.appendOptionalAttribute("hidden", tree.isHidden(), "true");
xml.appendOptionalAttribute("required", tree.isMandatory(), "true");
switch(tree.getExpandMode()) {
case CLIENT:
xml.appendAttribute("mode", "client");
break;
case DYNAMIC:
xml.appendAttribute("mode", "dynamic");
break;
case LAZY:
xml.appendAttribute("mode", "lazy");
break;
default:
throw new IllegalStateException("Invalid expand mode: " + tree.getType());
}
xml.appendClose();
// Render margin
MarginRendererUtil.renderMargin(tree, renderContext);
if (tree.getCustomTree() == null) {
handlePaintItems(tree, xml);
} else {
handlePaintCustom(tree, xml);
}
DiagnosticRenderUtil.renderDiagnostics(tree, renderContext);
xml.appendEndTag("ui:tree");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WValidationErrorsRenderer method doRender.
/**
* Paints the given {@link WValidationErrors} component.
*
* @param component The {@link WValidationErrors} component to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WValidationErrors errors = (WValidationErrors) component;
XmlStringBuilder xml = renderContext.getWriter();
if (errors.hasErrors()) {
xml.appendTagOpen("ui:validationerrors");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("title", errors.getTitleText());
xml.appendClose();
for (GroupedDiagnositcs nextGroup : errors.getGroupedErrors()) {
// Render each diagnostic message in this group.
for (Diagnostic nextMessage : nextGroup.getDiagnostics()) {
xml.appendTagOpen("ui:error");
WComponent forComponent = nextMessage.getComponent();
if (forComponent != null) {
UIContextHolder.pushContext(nextMessage.getContext());
try {
xml.appendAttribute("for", forComponent.getId());
} finally {
UIContextHolder.popContext();
}
}
xml.appendClose();
// of a WComponent as the message.
if (nextMessage instanceof DiagnosticImpl) {
WComponent messageComponent = ((DiagnosticImpl) nextMessage).createDiagnosticErrorComponent();
// We add the component to a throw-away container so that it renders with the correct ID.
WContainer container = new WContainer() {
@Override
public String getId() {
return component.getId();
}
};
container.add(messageComponent);
messageComponent.paint(renderContext);
container.remove(messageComponent);
container.reset();
} else {
xml.append(nextMessage.getDescription());
}
xml.appendEndTag("ui:error");
}
}
xml.appendEndTag("ui:validationerrors");
}
}
Aggregations