Search in sources :

Example 21 with WComponent

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));
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Example 22 with WComponent

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));
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Example 23 with WComponent

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());
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) SystemException(com.github.bordertech.wcomponents.util.SystemException) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Example 24 with WComponent

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);
    }
}
Also used : AbstractWComponent(com.github.bordertech.wcomponents.AbstractWComponent) WComponent(com.github.bordertech.wcomponents.WComponent) Iterator(java.util.Iterator)

Example 25 with WComponent

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");
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) AbstractWFieldIndicator(com.github.bordertech.wcomponents.validation.AbstractWFieldIndicator) Input(com.github.bordertech.wcomponents.Input) SystemException(com.github.bordertech.wcomponents.util.SystemException) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) Diagnosable(com.github.bordertech.wcomponents.Diagnosable)

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