Search in sources :

Example 6 with WComponent

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));
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) UIContext(com.github.bordertech.wcomponents.UIContext) GroupedDiagnositcs(com.github.bordertech.wcomponents.validation.WValidationErrors.GroupedDiagnositcs) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 7 with WComponent

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");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) SystemException(com.github.bordertech.wcomponents.util.SystemException) ArrayList(java.util.ArrayList) WDefinitionList(com.github.bordertech.wcomponents.WDefinitionList) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 8 with WComponent

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();
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WEditableImage(com.github.bordertech.wcomponents.WEditableImage) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 9 with WComponent

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();
        }
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) UIContext(com.github.bordertech.wcomponents.UIContext) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 10 with WComponent

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();
}
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)

Aggregations

WComponent (com.github.bordertech.wcomponents.WComponent)107 Test (org.junit.Test)35 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)30 UIContext (com.github.bordertech.wcomponents.UIContext)20 SystemException (com.github.bordertech.wcomponents.util.SystemException)16 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)14 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)8 WApplication (com.github.bordertech.wcomponents.WApplication)8 WLabel (com.github.bordertech.wcomponents.WLabel)8 AbstractWComponent (com.github.bordertech.wcomponents.AbstractWComponent)7 IOException (java.io.IOException)6 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)5 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)5 PrintWriter (java.io.PrintWriter)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 Size (com.github.bordertech.wcomponents.Size)4 WRepeater (com.github.bordertech.wcomponents.WRepeater)4 WText (com.github.bordertech.wcomponents.WText)4 WTextField (com.github.bordertech.wcomponents.WTextField)4