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;
}
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);
}
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));
}
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;
}
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());
}
Aggregations