use of com.github.bordertech.wcomponents.WPanel in project wcomponents by BorderTech.
the class WAjaxControlRenderer_Test method testDoPaint.
@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
WContainer root = new WContainer();
WButton trigger = new WButton("x");
WPanel target1 = new WPanel();
WPanel target2 = new WPanel();
WPanel target3 = new WPanel();
WAjaxControl control = new WAjaxControl(trigger);
root.add(trigger);
root.add(target1);
root.add(target2);
root.add(target3);
root.add(control);
// No Targets
assertSchemaMatch(root);
assertXpathEvaluatesTo("0", "count(//ui:ajaxtrigger)", root);
// With Targets
control.addTargets(new AjaxTarget[] { target1, target2, target3 });
setActiveContext(createUIContext());
assertSchemaMatch(root);
assertXpathEvaluatesTo(trigger.getId(), "//ui:ajaxtrigger/@triggerId", root);
assertXpathNotExists("//ui:ajaxtrigger/@loadOnce", root);
assertXpathNotExists("//ui:ajaxtrigger/@delay", root);
assertXpathEvaluatesTo("3", "count(//ui:ajaxtrigger/ui:ajaxtargetid)", root);
assertXpathEvaluatesTo(target1.getId(), "//ui:ajaxtrigger/ui:ajaxtargetid[1]/@targetId", root);
assertXpathEvaluatesTo(target2.getId(), "//ui:ajaxtrigger/ui:ajaxtargetid[2]/@targetId", root);
assertXpathEvaluatesTo(target3.getId(), "//ui:ajaxtrigger/ui:ajaxtargetid[3]/@targetId", root);
control.setLoadOnce(true);
assertSchemaMatch(root);
assertXpathEvaluatesTo("true", "//ui:ajaxtrigger/@loadOnce", root);
// remove loadOnce then reset it using loadCount
control.setLoadOnce(false);
assertSchemaMatch(root);
assertXpathNotExists("//ui:ajaxtrigger/@loadOnce", root);
// With Targets and optional attributes
// any number greateer than 0...
control.setLoadCount(6);
control.setDelay(1000);
assertSchemaMatch(root);
assertXpathEvaluatesTo(trigger.getId(), "//ui:ajaxtrigger/@triggerId", root);
assertXpathEvaluatesTo("true", "//ui:ajaxtrigger/@loadOnce", root);
assertXpathEvaluatesTo("1000", "//ui:ajaxtrigger/@delay", root);
assertXpathEvaluatesTo("3", "count(//ui:ajaxtrigger/ui:ajaxtargetid)", root);
}
use of com.github.bordertech.wcomponents.WPanel in project wcomponents by BorderTech.
the class ColumnLayoutRenderer method doRender.
/**
* Paints the given WPanel's children.
*
* @param component the container to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WPanel panel = (WPanel) component;
XmlStringBuilder xml = renderContext.getWriter();
ColumnLayout layout = (ColumnLayout) panel.getLayout();
int childCount = panel.getChildCount();
Size hgap = layout.getHorizontalGap();
String hgapString = hgap == null ? null : hgap.toString();
Size vgap = layout.getVerticalGap();
String vgapString = vgap == null ? null : vgap.toString();
int cols = layout.getColumnCount();
xml.appendTagOpen("ui:columnlayout");
xml.appendOptionalAttribute("hgap", hgapString);
xml.appendOptionalAttribute("vgap", vgapString);
xml.appendClose();
// Column Definitions
for (int col = 0; col < cols; col++) {
xml.appendTagOpen("ui:column");
int width = layout.getColumnWidth(col);
xml.appendOptionalAttribute("width", width > 0, width);
switch(layout.getColumnAlignment(col)) {
case LEFT:
// left is assumed if omitted
break;
case RIGHT:
xml.appendAttribute("align", "right");
break;
case CENTER:
xml.appendAttribute("align", "center");
break;
default:
throw new IllegalArgumentException("Invalid alignment: " + layout.getColumnAlignment(col));
}
xml.appendEnd();
}
for (int i = 0; i < childCount; i++) {
xml.appendTag("ui:cell");
WComponent child = panel.getChildAt(i);
child.paint(renderContext);
xml.appendEndTag("ui:cell");
}
xml.appendEndTag("ui:columnlayout");
}
use of com.github.bordertech.wcomponents.WPanel in project wcomponents by BorderTech.
the class WButtonRenderer_Test method testAllOptions.
@Test
public void testAllOptions() throws IOException, SAXException, XpathException {
WButton button = new WButton("All");
button.setDisabled(true);
setFlag(button, ComponentModel.HIDE_FLAG, true);
button.setToolTip("Title");
button.setAccessKey('T');
button.setImageUrl("http://localhost/image.png");
button.setImagePosition(ImagePosition.EAST);
button.setRenderAsLink(true);
button.setAjaxTarget(new WTextField());
button.setPopupTrigger(true);
setActiveContext(createUIContext());
WPanel validationComponent = new WPanel();
button.setAction(new ValidatingAction(new WValidationErrors(), validationComponent) {
@Override
public void executeOnValid(final ActionEvent event) {
// Do nothing
}
});
WContainer root = new WContainer();
root.add(button);
root.add(validationComponent);
assertXpathExists("//html:button[@id]", button);
assertXpathExists("//html:button[contains(@class, 'wc-linkbutton')]", button);
assertXpathEvaluatesTo(button.getText(), "//html:button", button);
assertXpathEvaluatesTo("disabled", "//html:button/@disabled", button);
assertXpathEvaluatesTo("hidden", "//html:button/@hidden", button);
assertXpathEvaluatesTo(button.getToolTip(), "//html:button/@title", button);
assertXpathUrlEvaluatesTo(button.getImageUrl(), "//html:button//html:img/@src", button);
assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imge')]", button);
assertXpathEvaluatesTo(button.getAccessKeyAsString(), "//html:button/@accesskey", button);
assertXpathEvaluatesTo("true", "//html:button/@aria-haspopup", button);
assertXpathEvaluatesTo(validationComponent.getId(), "//html:button/@data-wc-validate", button);
assertXpathEvaluatesTo(button.getId(), "//ui:ajaxtrigger/@triggerId", button);
button.setImagePosition(ImagePosition.NORTH);
assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgn')]", button);
button.setImagePosition(ImagePosition.SOUTH);
assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgs')]", button);
button.setImagePosition(ImagePosition.WEST);
assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgw')]", button);
button.setClientCommandOnly(true);
assertXpathEvaluatesTo("button", "//html:button/@type", button);
}
use of com.github.bordertech.wcomponents.WPanel in project wcomponents by BorderTech.
the class WFieldErrorIndicatorRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
WContainer root = new WContainer();
WPanel target = new WPanel();
WFieldErrorIndicator indicator = new WFieldErrorIndicator(target);
root.add(indicator);
root.add(target);
List<Diagnostic> diags = new ArrayList<>();
diags.add(new DiagnosticImpl(Diagnostic.ERROR, target, getMaliciousContent()));
root.showErrorIndicators(diags);
assertSafeContent(root);
}
use of com.github.bordertech.wcomponents.WPanel in project wcomponents by BorderTech.
the class WFieldWarningIndicatorRenderer_Test method testDoPaint.
@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
WContainer root = new WContainer();
WPanel target = new WPanel();
WFieldWarningIndicator indicator = new WFieldWarningIndicator(target);
root.add(target);
root.add(indicator);
// Simulate Warning Message
setActiveContext(createUIContext());
List<Diagnostic> diags = new ArrayList<>();
diags.add(new DiagnosticImpl(Diagnostic.WARNING, target, "Test Warning"));
root.showWarningIndicators(diags);
// Validate Schema
assertSchemaMatch(root);
// Check Attributes
assertXpathEvaluatesTo(indicator.getId(), "//ui:fieldindicator/@id", root);
assertXpathEvaluatesTo("warn", "//ui:fieldindicator/@type", root);
assertXpathEvaluatesTo(target.getId(), "//ui:fieldindicator/@for", root);
// Check Message
assertXpathEvaluatesTo("Test Warning", "//ui:fieldindicator/ui:message", root);
}
Aggregations