use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class WValidationErrors_Test method testGetGroupedErrors.
@Test
public void testGetGroupedErrors() {
wValidationErrors.setLocked(true);
UIContext uic = createUIContext();
setActiveContext(uic);
errors.clear();
List<GroupedDiagnositcs> groupedErrors = wValidationErrors.getGroupedErrors();
Assert.assertTrue("Should not have any groups by default", groupedErrors.isEmpty());
WComponent component1 = new WTextField();
WComponent component2 = new WTextField();
Diagnostic component1Error1 = new DiagnosticImpl(Diagnostic.ERROR, component1, "Error 1");
Diagnostic component2Error1 = new DiagnosticImpl(Diagnostic.ERROR, component2, "Error 2");
Diagnostic component2Error2 = new DiagnosticImpl(Diagnostic.ERROR, component2, "Error 3");
errors.add(component1Error1);
errors.add(component2Error1);
errors.add(component2Error2);
wValidationErrors.setErrors(errors);
groupedErrors = wValidationErrors.getGroupedErrors();
Assert.assertEquals("Incorrect number of groups", 2, groupedErrors.size());
GroupedDiagnositcs group1 = groupedErrors.get(0);
GroupedDiagnositcs group2 = groupedErrors.get(1);
Assert.assertEquals("Incorrect number of errors for group 1", 1, group1.getDiagnostics().size());
Assert.assertSame("Incorrect diagnostic in group 1", component1Error1, group1.getDiagnostics().get(0));
Assert.assertEquals("Incorrect number of errors for group 2", 2, group2.getDiagnostics().size());
Assert.assertSame("Incorrect diagnostic in group 2", component2Error1, group2.getDiagnostics().get(0));
Assert.assertSame("Incorrect diagnostic in group 2", component2Error2, group2.getDiagnostics().get(1));
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class WDefinitionListRenderer method doRender.
/**
* Paints the given definition list.
*
* @param component the list to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WDefinitionList list = (WDefinitionList) component;
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen("ui:definitionlist");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
switch(list.getType()) {
case FLAT:
xml.appendAttribute("type", "flat");
break;
case COLUMN:
xml.appendAttribute("type", "column");
break;
case STACKED:
xml.appendAttribute("type", "stacked");
break;
case NORMAL:
break;
default:
throw new SystemException("Unknown layout type: " + list.getType());
}
xml.appendClose();
// Render margin
MarginRendererUtil.renderMargin(list, renderContext);
for (Duplet<String, ArrayList<WComponent>> term : list.getTerms()) {
xml.appendTagOpen("ui:term");
xml.appendAttribute("text", I18nUtilities.format(null, term.getFirst()));
xml.appendClose();
for (WComponent data : term.getSecond()) {
xml.appendTag("ui:data");
data.paint(renderContext);
xml.appendEndTag("ui:data");
}
xml.appendEndTag("ui:term");
}
xml.appendEndTag("ui:definitionlist");
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class WEditableImageRenderer method doRender.
/**
* Paints the given {@link WEditableImage}.
*
* @param component the WEditableImage to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WEditableImage editableImage = (WEditableImage) component;
XmlStringBuilder xml = renderContext.getWriter();
// No image set
if (editableImage.getImage() == null && editableImage.getImageUrl() == null) {
return;
}
WImageRenderer.renderTagOpen(editableImage, xml);
WComponent uploader = editableImage.getEditUploader();
if (uploader != null) {
xml.appendAttribute("data-wc-editor", uploader.getId());
}
xml.appendEnd();
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class WListRenderer method paintRows.
/**
* Paints the rows.
*
* @param list the WList to paint the rows for.
* @param renderContext the RenderContext to paint to.
*/
protected void paintRows(final WList list, final WebXmlRenderContext renderContext) {
List<?> beanList = list.getBeanList();
WComponent row = list.getRepeatedComponent();
XmlStringBuilder xml = renderContext.getWriter();
for (int i = 0; i < beanList.size(); i++) {
Object rowData = beanList.get(i);
// Each row has its own context. This is why we can reuse the same
// WComponent instance for each row.
UIContext rowContext = list.getRowContext(rowData, i);
UIContextHolder.pushContext(rowContext);
try {
xml.appendTag("ui:cell");
row.paint(renderContext);
xml.appendEndTag("ui:cell");
} finally {
UIContextHolder.popContext();
}
}
}
use of com.github.bordertech.wcomponents.WComponent 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();
}
Aggregations