use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class UIRegistryClassLoaderImpl_Test method testGetUIRegistered.
/**
* Test getUI - successfully get a component already registered.
*/
@Test
public void testGetUIRegistered() {
final String key = "test123";
WComponent component = new DefaultWComponent();
UIRegistryClassLoaderImpl reg = new UIRegistryClassLoaderImpl();
reg.register(key, component);
Assert.assertSame("should return component registered", component, reg.getUI(key));
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class UIRegistryClassLoaderImpl_Test method testRegisterSuccess.
/**
* Test register - success.
*/
@Test
public void testRegisterSuccess() {
final String key = "test123";
WComponent component = new DefaultWComponent();
UIRegistryClassLoaderImpl reg = new UIRegistryClassLoaderImpl();
reg.register(key, component);
Assert.assertTrue("should have been successfully registered", reg.isRegistered(key));
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class UIRegistryClassLoaderImpl_Test method testRegisterFail.
/**
* Test register - exception on register with key already in use.
*/
@Test
public void testRegisterFail() {
final String key = "test123";
WComponent component = new DefaultWComponent();
UIRegistryClassLoaderImpl reg = new UIRegistryClassLoaderImpl();
reg.register(key, component);
try {
reg.register(key, component);
Assert.fail("attempted registration with key already used should have thrown an exception");
} catch (SystemException e) {
String expectedMessage = "Cannot re-register a component. Key = " + key;
Assert.assertEquals("exceptions hould have contained message expected", expectedMessage, e.getMessage());
}
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class UicStats method detectRootWCs.
/**
* @param uuic the user context
*/
private void detectRootWCs(final UIContext uuic) {
rootWCsDetected = new HashSet<>();
WComponent root = WebUtilities.getTop(uuic.getUI());
rootWCsDetected.add(root);
// Find any other root components that are storing information in the context.
for (Iterator it = uuic.getComponents().iterator(); it.hasNext(); ) {
WComponent wc = (WComponent) it.next();
root = WebUtilities.getTop(wc);
rootWCsDetected.add(root);
}
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class AbstractWFieldIndicatorRenderer method doRender.
/**
* Paints the given AbstractWFieldIndicator.
*
* @param component the WFieldErrorIndicator to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
AbstractWFieldIndicator fieldIndicator = (AbstractWFieldIndicator) component;
XmlStringBuilder xml = renderContext.getWriter();
WComponent validationTarget = fieldIndicator.getTargetComponent();
// Diagnosables takes care of thieir own messaging.
if (validationTarget == null || (validationTarget instanceof Diagnosable && !(validationTarget instanceof Input))) {
return;
}
if (validationTarget instanceof Input && !((Input) validationTarget).isReadOnly()) {
return;
}
List<Diagnostic> diags = fieldIndicator.getDiagnostics();
if (diags != null && !diags.isEmpty()) {
xml.appendTagOpen("ui:fieldindicator");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
switch(fieldIndicator.getFieldIndicatorType()) {
case INFO:
xml.appendAttribute("type", "info");
break;
case WARN:
xml.appendAttribute("type", "warn");
break;
case ERROR:
xml.appendAttribute("type", "error");
break;
default:
throw new SystemException("Cannot paint field indicator due to an invalid field indicator type: " + fieldIndicator.getFieldIndicatorType());
}
xml.appendAttribute("for", fieldIndicator.getRelatedFieldId());
xml.appendClose();
for (Diagnostic diag : diags) {
xml.appendTag("ui:message");
xml.appendEscaped(diag.getDescription());
xml.appendEndTag("ui:message");
}
xml.appendEndTag("ui:fieldindicator");
}
}
Aggregations