use of com.github.bordertech.wcomponents.util.SystemException 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();
}
}
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class VelocityRenderer method addToContext.
/**
* Adds a name/value pair to the Velocity context. If the name parameter ends with {@link #LIST_SUFFIX}
*
* @param context the context to add to.
* @param name the name
* @param value the value
*/
private void addToContext(final VelocityContext context, final String name, final Object value) {
if (name.endsWith(LIST_SUFFIX)) {
// We want to use lists
Object already = context.get(name);
if (already != null && !(already instanceof List)) {
throw new SystemException("VelocityContext contained " + already + " instead of List under " + name);
}
List list = (List) context.get(name);
if (list == null) {
list = new ArrayList();
context.put(name, list);
}
list.add(value);
} else {
context.put(name, value);
}
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class WCollapsibleRenderer method doRender.
/**
* Paints the given WCollapsible.
*
* @param component the WCollapsible to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WCollapsible collapsible = (WCollapsible) component;
XmlStringBuilder xml = renderContext.getWriter();
WComponent content = collapsible.getContent();
boolean collapsed = collapsible.isCollapsed();
xml.appendTagOpen("ui:collapsible");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendAttribute("groupName", collapsible.getGroupName());
xml.appendOptionalAttribute("collapsed", collapsed, "true");
xml.appendOptionalAttribute("hidden", collapsible.isHidden(), "true");
switch(collapsible.getMode()) {
case CLIENT:
xml.appendAttribute("mode", "client");
break;
case LAZY:
xml.appendAttribute("mode", "lazy");
break;
case EAGER:
xml.appendAttribute("mode", "eager");
break;
case DYNAMIC:
xml.appendAttribute("mode", "dynamic");
break;
case SERVER:
xml.appendAttribute("mode", "server");
break;
default:
throw new SystemException("Unknown collapsible mode: " + collapsible.getMode());
}
HeadingLevel level = collapsible.getHeadingLevel();
if (level != null) {
xml.appendAttribute("level", level.getLevel());
}
xml.appendClose();
// Render margin
MarginRendererUtil.renderMargin(collapsible, renderContext);
// Label
collapsible.getDecoratedLabel().paint(renderContext);
// Content
xml.appendTagOpen("ui:content");
xml.appendAttribute("id", component.getId() + "-content");
xml.appendClose();
// Render content if not EAGER Mode or is EAGER and is the current AJAX trigger
if (CollapsibleMode.EAGER != collapsible.getMode() || AjaxHelper.isCurrentAjaxTrigger(collapsible)) {
// Visibility of content set in prepare paint
content.paint(renderContext);
}
xml.appendEndTag("ui:content");
xml.appendEndTag("ui:collapsible");
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class UIManager method findRendererFactory.
/**
* Finds the renderer factory for the given package.
*
* @param packageName the package name to find the renderer factory for.
* @return the RendererFactory for the given package, or null if not found.
*/
private synchronized RendererFactory findRendererFactory(final String packageName) {
RendererFactory factory = factoriesByPackage.get(packageName);
if (factory == null) {
try {
factory = (RendererFactory) Class.forName(packageName + ".RendererFactoryImpl").newInstance();
factoriesByPackage.put(packageName, factory);
} catch (Exception e) {
throw new SystemException("Failed to create layout manager factory for " + packageName, e);
}
}
return factory;
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class UIManager method createRenderer.
/**
* Attempts to create a Renderer with the given name.
*
* @param rendererName the name of the Renderer
* @return a Renderer of the given type, or null if the class was not found.
*/
private static Renderer createRenderer(final String rendererName) {
if (rendererName.endsWith(".vm")) {
// This is a velocity template, so use a VelocityLayout
return new VelocityRenderer(rendererName);
}
try {
Class<?> managerClass = Class.forName(rendererName);
Object manager = managerClass.newInstance();
if (!(manager instanceof Renderer)) {
throw new SystemException(rendererName + " is not a Renderer");
}
return (Renderer) manager;
} catch (ClassNotFoundException e) {
// Legal - there might not a manager implementation in a given theme
return null;
} catch (InstantiationException e) {
throw new SystemException("Failed to instantiate " + rendererName, e);
} catch (IllegalAccessException e) {
throw new SystemException("Failed to access " + rendererName, e);
}
}
Aggregations