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