Search in sources :

Example 11 with WComponent

use of com.github.bordertech.wcomponents.WComponent 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 12 with WComponent

use of com.github.bordertech.wcomponents.WComponent 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");
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WContainer(com.github.bordertech.wcomponents.WContainer) DiagnosticImpl(com.github.bordertech.wcomponents.validation.DiagnosticImpl) WValidationErrors(com.github.bordertech.wcomponents.validation.WValidationErrors) GroupedDiagnositcs(com.github.bordertech.wcomponents.validation.WValidationErrors.GroupedDiagnositcs) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 13 with WComponent

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

the class InterceptorComponent_Test method testGetId.

@Test
public void testGetId() {
    WComponent backing = new WLabel();
    setActiveContext(createUIContext());
    InterceptorComponent interceptor = new InterceptorComponent(backing);
    Assert.assertEquals("Incorrect id returned", backing.getId(), interceptor.getId());
    interceptor = new InterceptorComponent(interceptor);
    Assert.assertEquals("Incorrect id returned for nested interceptor", backing.getId(), interceptor.getId());
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 14 with WComponent

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

the class InterceptorComponent_Test method testReplaceInterceptor.

@Test
public void testReplaceInterceptor() {
    WComponent ui = new WLabel();
    InterceptorComponent interceptor1 = new InterceptorComponent();
    InterceptorComponent interceptor2 = new FormInterceptor();
    InterceptorComponent interceptor3 = new HeadLineInterceptor();
    InterceptorComponent replacement = new PageShellInterceptor();
    // Build chain
    interceptor1.attachUI(ui);
    interceptor2.setBackingComponent(interceptor1);
    interceptor3.setBackingComponent(interceptor2);
    // Replace interceptor2
    InterceptorComponent newChain = InterceptorComponent.replaceInterceptor(interceptor2.getClass(), replacement, interceptor3);
    Assert.assertSame("Incorrect head of chain", interceptor3, newChain);
    Assert.assertSame("Incorrect replacement", replacement, newChain.getBackingComponent());
    Assert.assertSame("Incorrect tail of chain", interceptor1, replacement.getBackingComponent());
    Assert.assertSame("Incorrect UI", ui, newChain.getUI());
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 15 with WComponent

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

the class InterceptorComponent_Test method testAttachUI.

@Test
public void testAttachUI() {
    WComponent ui = new WLabel();
    InterceptorComponent interceptor = new InterceptorComponent(ui);
    Assert.assertSame("Incorrect UI returned", ui, interceptor.getUI());
    // Test nested interceptors
    interceptor = new InterceptorComponent();
    InterceptorComponent parentInterceptor = new InterceptorComponent(interceptor);
    parentInterceptor.attachUI(ui);
    Assert.assertSame("Incorrect UI returned by parent interceptor", ui, parentInterceptor.getUI());
    Assert.assertSame("Incorrect UI returned by child interceptor", ui, interceptor.getUI());
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

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