use of com.github.bordertech.wcomponents.WContainer in project wcomponents by BorderTech.
the class WSelectToggleRenderer_Test method testDoPaint.
@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
// Client-side
WCheckBox target = new WCheckBox();
WSelectToggle toggle = new WSelectToggle(true);
toggle.setTarget(target);
WContainer root = new WContainer();
root.add(toggle);
root.add(target);
assertSchemaMatch(toggle);
assertXpathNotExists("//ui:selecttoggle/@roundTrip", toggle);
assertXpathEvaluatesTo(toggle.getId(), "//ui:selecttoggle/@id", toggle);
assertXpathEvaluatesTo(toggle.getTarget().getId(), "//ui:selecttoggle/@target", toggle);
assertXpathEvaluatesTo("control", "//ui:selecttoggle/@renderAs", toggle);
assertXpathEvaluatesTo("none", "//ui:selecttoggle/@selected", toggle);
// Test Server-side
toggle.setClientSide(false);
assertSchemaMatch(toggle);
assertXpathEvaluatesTo("true", "//ui:selecttoggle/@roundTrip", toggle);
// Test when selected
toggle.setState(WSelectToggle.State.ALL);
assertSchemaMatch(toggle);
assertXpathEvaluatesTo("all", "//ui:selecttoggle/@selected", toggle);
// Test when partially selected
toggle.setState(WSelectToggle.State.SOME);
assertSchemaMatch(toggle);
assertXpathEvaluatesTo("some", "//ui:selecttoggle/@selected", toggle);
}
use of com.github.bordertech.wcomponents.WContainer in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testAllConditions.
@Test
public void testAllConditions() throws IOException, SAXException, XpathException {
SubordinateTrigger condTrigger = new WNumberField();
SubordinateTrigger condTrigger2 = new WTextField();
SubordinateTarget actionTarget = new WTextField();
BigDecimal value = BigDecimal.valueOf(2);
Condition cond1 = new Equal(condTrigger, value);
Condition cond2 = new NotEqual(condTrigger, value);
Condition cond3 = new LessThan(condTrigger, value);
Condition cond4 = new LessThanOrEqual(condTrigger, value);
Condition cond5 = new GreaterThan(condTrigger, value);
Condition cond6 = new GreaterThanOrEqual(condTrigger, value);
Condition cond7 = new Match(condTrigger2, "[abc]");
// Basic Condition
Rule rule = new Rule();
rule.setCondition(new And(cond1, cond2, cond3, cond4, cond5, cond6, cond7));
rule.addActionOnTrue(new Show(actionTarget));
rule.addActionOnFalse(new Hide(actionTarget));
// Setup Subordinate
WSubordinateControl control = new WSubordinateControl();
control.addRule(rule);
WContainer root = new WContainer();
root.add(condTrigger);
root.add(condTrigger2);
root.add(actionTarget);
root.add(control);
setActiveContext(createUIContext());
// Validate Schema
assertSchemaMatch(root);
assertXpathNotExists("//ui:subordinate/ui:and/ui:condition[1]/@operator", root);
assertXpathEvaluatesTo("ne", "//ui:subordinate/ui:and/ui:condition[2]/@operator", root);
assertXpathEvaluatesTo("lt", "//ui:subordinate/ui:and/ui:condition[3]/@operator", root);
assertXpathEvaluatesTo("le", "//ui:subordinate/ui:and/ui:condition[4]/@operator", root);
assertXpathEvaluatesTo("gt", "//ui:subordinate/ui:and/ui:condition[5]/@operator", root);
assertXpathEvaluatesTo("ge", "//ui:subordinate/ui:and/ui:condition[6]/@operator", root);
assertXpathEvaluatesTo("rx", "//ui:subordinate/ui:and/ui:condition[7]/@operator", root);
}
use of com.github.bordertech.wcomponents.WContainer in project wcomponents by BorderTech.
the class ObjectGraphNode_Test method testToXml.
@Test
public void testToXml() {
WContainer component = new WContainer();
setActiveContext(createUIContext());
WLabel label = new WLabel(TEST_LABEL);
component.add(label);
final int nodeId = component.getIndexOfChild(label);
final String fieldName = label.getId();
ObjectGraphNode node = new ObjectGraphNode(nodeId, fieldName, label.getClass().getName(), label);
String xmlSummary = node.toXml();
Assert.assertTrue("should report correct ID", xmlSummary.indexOf("object id=\"0\"") != -1);
Assert.assertTrue("should report correct field name", xmlSummary.indexOf("field=\"" + fieldName + "\"") != -1);
Assert.assertTrue("should report correct class name", xmlSummary.indexOf("type=\"com.github.bordertech.wcomponents.WLabel\"") != -1);
Assert.assertTrue("should report correct size", xmlSummary.indexOf("size=\"12\"") != -1);
}
use of com.github.bordertech.wcomponents.WContainer in project wcomponents by BorderTech.
the class SimpleTabs method addTab.
/**
* Adds a tab.
*
* @param card the tab content.
* @param name the tab name.
*/
public void addTab(final WComponent card, final String name) {
WContainer titledCard = new WContainer();
WText title = new WText("<b>[" + name + "]:</b><br/>");
title.setEncodeText(false);
titledCard.add(title);
titledCard.add(card);
deck.add(titledCard);
final TabButton button = new TabButton(name, titledCard);
button.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
deck.makeVisible(button.getAssociatedCard());
}
});
btnPanel.add(button);
}
use of com.github.bordertech.wcomponents.WContainer in project wcomponents by BorderTech.
the class WButtonExample method addDefaultSubmitButtonExample.
/**
* Examples showing how to set a WButton as the default submit button for an input control.
*/
private void addDefaultSubmitButtonExample() {
add(new WHeading(HeadingLevel.H3, "Default submit button"));
add(new ExplanatoryText("This example shows how to use an image as the only content of a WButton. " + "In addition this text field submits the entire screen using the image button to the right of the field."));
// We use WFieldLayout to lay out a label:input pair. In this case the input is a
// compound control of a WTextField and a WButton.
WFieldLayout imageButtonFieldLayout = new WFieldLayout();
imageButtonFieldLayout.setLabelWidth(25);
add(imageButtonFieldLayout);
// the text field and the button both need to be defined explicitly to be able to add them into a wrapper
WTextField textFld = new WTextField();
// and finally we get to the actual button
WButton button = new WButton("Flag this record for follow-up");
button.setImage("/image/flag.png");
button.getImageHolder().setCacheKey("eg-button-flag");
button.setActionObject(button);
button.setAction(new ExampleButtonAction());
// we can set the image button to be the default submit button for the text field.
textFld.setDefaultSubmitButton(button);
// There are many way of putting multiple controls in to a WField's input.
// We are using a WContainer is the one which is lowest impact in the UI.
WContainer imageButtonFieldContainer = new WContainer();
imageButtonFieldContainer.add(textFld);
// Use a WText to push the button off of the text field by an appropriate (user-agent determined) amount.
// an en space is half an em. a none-breaking space \u00a0 could also be used but will have no effect on inter-node wrapping
imageButtonFieldContainer.add(new WText("\u2002"));
imageButtonFieldContainer.add(button);
// Finally add the input wrapper to the WFieldLayout
imageButtonFieldLayout.addField("Enter record ID", imageButtonFieldContainer);
}
Aggregations