use of com.github.bordertech.wcomponents.ComponentWithContext in project wcomponents by BorderTech.
the class TreeUtil_Test method testCollateVisibles.
@Test
public void testCollateVisibles() {
// Simple case - everything visible.
List<ComponentWithContext> visibles = TreeUtil.collateVisibles(root);
UIContext uic = UIContextHolder.getCurrent();
Assert.assertEquals("Incorrect number of visible components", 10, visibles.size());
Assert.assertTrue("List should contain root", isInList(visibles, root, uic));
Assert.assertTrue("List should contain containerChild", isInList(visibles, containerChild, uic));
Assert.assertTrue("List should contain simpleChild", isInList(visibles, simpleChild, uic));
Assert.assertTrue("List should contain repeaterChild", isInList(visibles, repeaterChild, uic));
Assert.assertTrue("List should contain grandChild", isInList(visibles, grandChild, uic));
Assert.assertTrue("List should contain repeatedComponent row 1", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("1")));
Assert.assertTrue("List should contain repeatedComponent row 2", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("2")));
Assert.assertTrue("List should contain repeatedComponent row 3", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("3")));
Assert.assertTrue("List should contain card manager", isInList(visibles, cardManager, uic));
Assert.assertTrue("List should contain visible card", isInList(visibles, card1, uic));
// Make grandChild invisible - should only remove it
grandChild.setVisible(false);
visibles = TreeUtil.collateVisibles(root);
Assert.assertEquals("Incorrect number of visible components", 9, visibles.size());
Assert.assertTrue("List should contain root", isInList(visibles, root, uic));
Assert.assertTrue("List should contain containerChild", isInList(visibles, containerChild, uic));
Assert.assertTrue("List should contain simpleChild", isInList(visibles, simpleChild, uic));
Assert.assertTrue("List should contain repeaterChild", isInList(visibles, repeaterChild, uic));
Assert.assertTrue("List should contain repeatedComponent row 1", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("1")));
Assert.assertTrue("List should contain repeatedComponent row 2", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("2")));
Assert.assertTrue("List should contain repeatedComponent row 3", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("3")));
Assert.assertTrue("List should contain card manager", isInList(visibles, cardManager, uic));
Assert.assertTrue("List should contain visible card", isInList(visibles, card1, uic));
grandChild.setVisible(true);
// Make containerChild invisible - should remove it and grandChild
containerChild.setVisible(false);
visibles = TreeUtil.collateVisibles(root);
Assert.assertEquals("Incorrect number of visible components", 8, visibles.size());
Assert.assertTrue("List should contain root", isInList(visibles, root, uic));
Assert.assertTrue("List should contain simpleChild", isInList(visibles, simpleChild, uic));
Assert.assertTrue("List should contain repeaterChild", isInList(visibles, repeaterChild, uic));
Assert.assertTrue("List should contain repeatedComponent row 1", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("1")));
Assert.assertTrue("List should contain repeatedComponent row 2", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("2")));
Assert.assertTrue("List should contain repeatedComponent row 3", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("3")));
Assert.assertTrue("List should contain card manager", isInList(visibles, cardManager, uic));
Assert.assertTrue("List should contain visible card", isInList(visibles, card1, uic));
containerChild.setVisible(true);
// Make repeaterChild invisible - should remove it and its 3 rows
repeaterChild.setVisible(false);
visibles = TreeUtil.collateVisibles(root);
Assert.assertEquals("Incorrect number of visible components", 6, visibles.size());
Assert.assertTrue("List should contain root", isInList(visibles, root, uic));
Assert.assertTrue("List should contain containerChild", isInList(visibles, containerChild, uic));
Assert.assertTrue("List should contain simpleChild", isInList(visibles, simpleChild, uic));
Assert.assertTrue("List should contain grandChild", isInList(visibles, grandChild, uic));
Assert.assertTrue("List should contain card manager", isInList(visibles, cardManager, uic));
Assert.assertTrue("List should contain visible card", isInList(visibles, card1, uic));
repeaterChild.setVisible(true);
// Make 2nd row of repeater invisible
setActiveContext(repeaterChild.getRowContext("2"));
repeatedComponent.setVisible(false);
setActiveContext(uic);
visibles = TreeUtil.collateVisibles(root);
Assert.assertEquals("Incorrect number of visible components", 9, visibles.size());
Assert.assertTrue("List should contain root", isInList(visibles, root, uic));
Assert.assertTrue("List should contain containerChild", isInList(visibles, containerChild, uic));
Assert.assertTrue("List should contain simpleChild", isInList(visibles, simpleChild, uic));
Assert.assertTrue("List should contain repeaterChild", isInList(visibles, repeaterChild, uic));
Assert.assertTrue("List should contain grandChild", isInList(visibles, grandChild, uic));
Assert.assertTrue("List should contain repeatedComponent row 1", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("1")));
Assert.assertTrue("List should contain repeatedComponent row 3", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("3")));
Assert.assertTrue("List should contain card manager", isInList(visibles, cardManager, uic));
Assert.assertTrue("List should contain visible card", isInList(visibles, card1, uic));
// Switch active cards
cardManager.makeVisible(card2);
visibles = TreeUtil.collateVisibles(root);
Assert.assertEquals("Incorrect number of visible components", 9, visibles.size());
Assert.assertTrue("List should contain root", isInList(visibles, root, uic));
Assert.assertTrue("List should contain containerChild", isInList(visibles, containerChild, uic));
Assert.assertTrue("List should contain simpleChild", isInList(visibles, simpleChild, uic));
Assert.assertTrue("List should contain repeaterChild", isInList(visibles, repeaterChild, uic));
Assert.assertTrue("List should contain grandChild", isInList(visibles, grandChild, uic));
Assert.assertTrue("List should contain repeatedComponent row 1", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("1")));
Assert.assertTrue("List should contain repeatedComponent row 3", isInList(visibles, repeatedComponent, repeaterChild.getRowContext("3")));
Assert.assertTrue("List should contain card manager", isInList(visibles, cardManager, uic));
Assert.assertTrue("List should contain visible card", isInList(visibles, card2, uic));
// Make root invisible - should be an empty list
root.setVisible(false);
visibles = TreeUtil.collateVisibles(root);
Assert.assertEquals("Incorrect number of visible components", 0, visibles.size());
}
use of com.github.bordertech.wcomponents.ComponentWithContext in project wcomponents by BorderTech.
the class AjaxInterceptor method paintResponse.
/**
* Paint the ajax response.
*
* @param renderContext the render context
* @param operation the ajax operation
*/
private void paintResponse(final RenderContext renderContext, final AjaxOperation operation) {
WebXmlRenderContext webRenderContext = (WebXmlRenderContext) renderContext;
XmlStringBuilder xml = webRenderContext.getWriter();
// Get trigger's context
ComponentWithContext trigger = AjaxHelper.getCurrentTriggerAndContext();
if (trigger == null) {
throw new SystemException("No context available for trigger " + operation.getTriggerId());
}
for (String targetId : operation.getTargets()) {
ComponentWithContext target;
if (targetId.equals(operation.getTriggerId())) {
target = trigger;
} else {
target = WebUtilities.getComponentById(targetId, true);
if (target == null) {
LOG.warn("Could not find ajax target to render [" + targetId + "]");
continue;
}
}
UIContextHolder.pushContext(target.getContext());
try {
xml.appendTagOpen("ui:ajaxtarget");
xml.appendAttribute("id", targetId);
xml.appendAttribute("action", operation.getAction().getDesc());
xml.appendClose();
target.getComponent().paint(renderContext);
xml.appendEndTag("ui:ajaxtarget");
} finally {
UIContextHolder.popContext();
}
}
}
use of com.github.bordertech.wcomponents.ComponentWithContext in project wcomponents by BorderTech.
the class TargetableInterceptor method paint.
/**
* {@inheritDoc}
*/
@Override
public void paint(final RenderContext renderContext) {
ComponentWithContext target = WebUtilities.getComponentById(targetId, true);
if (target == null) {
throw new SystemException("No target component found for id " + targetId);
}
UIContextHolder.pushContext(target.getContext());
try {
super.paint(renderContext);
} finally {
UIContextHolder.popContext();
}
}
use of com.github.bordertech.wcomponents.ComponentWithContext in project wcomponents by BorderTech.
the class WWindowInterceptor method preparePaint.
/**
* Temporarily replaces the environment while the UI prepares to render.
*
* @param request the request being responded to.
*/
@Override
public void preparePaint(final Request request) {
if (windowId == null) {
super.preparePaint(request);
} else {
// Get the window component
ComponentWithContext target = WebUtilities.getComponentById(windowId, true);
if (target == null) {
throw new SystemException("No window component for id " + windowId);
}
UIContext uic = UIContextHolder.getCurrentPrimaryUIContext();
Environment originalEnvironment = uic.getEnvironment();
uic.setEnvironment(new EnvironmentDelegate(originalEnvironment, windowId, target));
UIContextHolder.pushContext(target.getContext());
try {
super.preparePaint(request);
} finally {
uic.setEnvironment(originalEnvironment);
UIContextHolder.popContext();
}
}
}
use of com.github.bordertech.wcomponents.ComponentWithContext in project wcomponents by BorderTech.
the class WWindowInterceptor method paint.
/**
* Temporarily replaces the environment while the UI is being rendered.
*
* @param renderContext the context to render to.
*/
@Override
public void paint(final RenderContext renderContext) {
if (windowId == null) {
super.paint(renderContext);
} else {
// Get the window component
ComponentWithContext target = WebUtilities.getComponentById(windowId, true);
if (target == null) {
throw new SystemException("No window component for id " + windowId);
}
UIContext uic = UIContextHolder.getCurrentPrimaryUIContext();
Environment originalEnvironment = uic.getEnvironment();
uic.setEnvironment(new EnvironmentDelegate(originalEnvironment, windowId, target));
UIContextHolder.pushContext(target.getContext());
try {
super.paint(renderContext);
} finally {
uic.setEnvironment(originalEnvironment);
UIContextHolder.popContext();
}
}
}
Aggregations