Search in sources :

Example 46 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class PlainLauncher method createUI.

/**
 * Creates the UI which the launcher displays. If there is misconfiguration or error, a UI containing an error
 * message is returned.
 *
 * @return the UI which the launcher displays.
 */
protected WComponent createUI() {
    // Check if the parameter COMPONENT_TO_LAUNCH_PARAM_KEY has been
    // configured with the name of a component to launch.
    WComponent sharedApp;
    uiClassName = getComponentToLaunchClassName();
    if (uiClassName == null) {
        sharedApp = new WText("You need to set the class name of the WComponent you want to run.<br />" + "Do this by setting the parameter \"" + COMPONENT_TO_LAUNCH_PARAM_KEY + "\" in your \"local_app.properties\" file.<br />" + "Eg.  <code>" + COMPONENT_TO_LAUNCH_PARAM_KEY + "=com.github.bordertech.wcomponents.examples.picker.ExamplePicker</code>");
        ((WText) sharedApp).setEncodeText(false);
    } else {
        UIRegistry registry = UIRegistry.getInstance();
        sharedApp = registry.getUI(uiClassName);
        if (sharedApp == null) {
            sharedApp = new WText("Unable to load the component \"" + uiClassName + "\".<br />" + "Either the component does not exist as a resource in the classpath," + " or is not a WComponent.<br />" + "Check that the parameter \"" + COMPONENT_TO_LAUNCH_PARAM_KEY + "\" is set correctly.");
            ((WText) sharedApp).setEncodeText(false);
        }
    }
    return sharedApp;
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WText(com.github.bordertech.wcomponents.WText) UIRegistry(com.github.bordertech.wcomponents.registry.UIRegistry)

Example 47 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class PlainLauncher_Test method testGetUINonWApplication.

@Test
public void testGetUINonWApplication() {
    Config.getInstance().setProperty(ConfigurationProperties.LDE_PLAINLAUNCHER_COMPONENT_TO_LAUNCH, MyTestComponent.class.getName());
    PlainLauncher plain = new PlainLauncher();
    WComponent ui1 = plain.getUI(new MockHttpServletRequest());
    Assert.assertTrue("Root UI should be a WApplication", ui1 instanceof WApplication);
    ui1 = ((WApplication) ui1).getChildAt(0);
    Assert.assertTrue("UI should be an instance of MyTestComponent", ui1 instanceof MyTestComponent);
    // Call getUI again, the same instance should be returned
    WComponent ui2 = ((WApplication) plain.getUI(new MockHttpServletRequest())).getChildAt(0);
    Assert.assertSame("Should have returned the same UI instance", ui1, ui2);
}
Also used : AbstractWComponent(com.github.bordertech.wcomponents.AbstractWComponent) WComponent(com.github.bordertech.wcomponents.WComponent) WApplication(com.github.bordertech.wcomponents.WApplication) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) Test(org.junit.Test)

Example 48 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class PlainLauncher_Test method testCreateUI.

@Test
public void testCreateUI() {
    Config.getInstance().clearProperty(ConfigurationProperties.LDE_PLAINLAUNCHER_COMPONENT_TO_LAUNCH);
    launcher = new PlainLauncher();
    WComponent ui = launcher.createUI();
    Assert.assertTrue("UI should be an instance of WText", ui instanceof WText);
    Assert.assertTrue("UI should contain instructions on configuring the LDE", ((WText) ui).getText().contains(PlainLauncher.COMPONENT_TO_LAUNCH_PARAM_KEY));
}
Also used : AbstractWComponent(com.github.bordertech.wcomponents.AbstractWComponent) WComponent(com.github.bordertech.wcomponents.WComponent) WText(com.github.bordertech.wcomponents.WText) Test(org.junit.Test)

Example 49 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class ByWComponentPath method findElements.

/**
 * {@inheritDoc}
 */
@Override
public List<WebElement> findElements(final SearchContext searchContext) {
    List<WebElement> result = new ArrayList<>();
    ComponentWithContext[] components = null;
    UIContextHolder.pushContext(getContext());
    try {
        components = TreeUtil.findWComponents(getComponent(), path, visibleOnly);
    } finally {
        UIContextHolder.popContext();
    }
    if (components.length != 0) {
        componentClass = components[0].getComponent().getClass();
    }
    for (ComponentWithContext comp : components) {
        WComponent cmp = comp.getComponent();
        UIContext cmpUic = comp.getContext();
        UIContextHolder.pushContext(cmpUic);
        try {
            List<WebElement> resultForComp = findElement(searchContext, cmpUic, cmp, getValue());
            result.addAll(resultForComp);
        } finally {
            UIContextHolder.popContext();
        }
    }
    return result;
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) UIContext(com.github.bordertech.wcomponents.UIContext) ArrayList(java.util.ArrayList) WebElement(org.openqa.selenium.WebElement) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 50 with WComponent

use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.

the class DiagnosticImpl_Test method testGetComponent.

@Test
public void testGetComponent() {
    final WComponent component = new WTextField();
    DiagnosticImpl diag = new DiagnosticImpl(Diagnostic.INFO, component, "dummy");
    Assert.assertSame("Incorrect component", component, diag.getComponent());
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

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