use of com.github.bordertech.wcomponents.WebComponent in project wcomponents by BorderTech.
the class AbstractContainerHelper_Test method testGetUI.
@Test
public void testGetUI() {
AbstractContainerHelper helper = new MyContainerHelper();
WebComponent webComponent = new WTextField();
helper.setWebComponent(webComponent);
Assert.assertSame("getUI returned incorrect UI", webComponent, helper.getUI());
}
use of com.github.bordertech.wcomponents.WebComponent in project wcomponents by BorderTech.
the class AbstractContainerHelper_Test method testSetWebComponent.
@Test
public void testSetWebComponent() {
AbstractContainerHelper helper = new MyContainerHelper();
WebComponent webComponent = new WTextField();
// getUI throws a NPE
Assert.assertNull("Default interceptor should be null", helper.getInterceptor());
helper.setWebComponent(webComponent);
Assert.assertSame("Incorrect UI set", webComponent, helper.getUI());
try {
helper = new MyContainerHelper();
helper.setWebComponent(new MyWebComponent());
Assert.fail("Should have thrown an IllegalArgumentException");
} catch (IllegalArgumentException e) {
Assert.assertNull("Interceptor should be null", helper.getInterceptor());
}
}
use of com.github.bordertech.wcomponents.WebComponent in project wcomponents by BorderTech.
the class InterceptorComponent method replaceInterceptor.
/**
* Utility method for replacing an individual interceptor within an existing chain.
*
* @param match the type of the interceptor to be replaced.
* @param replacement the new interceptor to be used as a replacement.
* @param chain the existing interceptor chain in which the replacement will take place.
* @return the modified interceptor chain. If no match was found, the existing interceptor chain is returned
* unchanged.
*/
public static InterceptorComponent replaceInterceptor(final Class match, final InterceptorComponent replacement, final InterceptorComponent chain) {
if (chain == null) {
return null;
}
InterceptorComponent current = chain;
InterceptorComponent previous = null;
InterceptorComponent updatedChain = null;
while (updatedChain == null) {
if (match.isInstance(current)) {
// Found the interceptor that needs to be replaced.
replacement.setBackingComponent(current.getBackingComponent());
if (previous == null) {
updatedChain = replacement;
} else {
previous.setBackingComponent(replacement);
updatedChain = chain;
}
} else {
previous = current;
WebComponent next = current.getBackingComponent();
if (next instanceof InterceptorComponent) {
current = (InterceptorComponent) next;
} else {
// Reached the end of the chain. No replacement done.
updatedChain = chain;
}
}
}
return updatedChain;
}
use of com.github.bordertech.wcomponents.WebComponent in project wcomponents by BorderTech.
the class InterceptorComponent_Test method testAttachUIBadBacking.
@Test(expected = IllegalStateException.class)
public void testAttachUIBadBacking() {
InterceptorComponent interceptor = new InterceptorComponent(new WebComponent() {
/**
* {@inheritDoc}
*/
@Override
public void serviceRequest(final Request request) {
// NO-OP
}
/**
* {@inheritDoc}
*/
@Override
public void preparePaint(final Request request) {
// NO-OP
}
/**
* {@inheritDoc}
*/
@Override
public void paint(final RenderContext renderContext) {
// NO-OP
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getId() {
return null;
}
});
// This should throw an exception, as it doesn't know how to attach the UI
// to the anonymous WebComponent implementation.
interceptor.attachUI(new WLabel());
}
Aggregations