Search in sources :

Example 26 with WContainer

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);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WSelectToggle(com.github.bordertech.wcomponents.WSelectToggle) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) Test(org.junit.Test)

Example 27 with WContainer

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);
}
Also used : Condition(com.github.bordertech.wcomponents.subordinate.Condition) Hide(com.github.bordertech.wcomponents.subordinate.Hide) WContainer(com.github.bordertech.wcomponents.WContainer) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) WNumberField(com.github.bordertech.wcomponents.WNumberField) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) BigDecimal(java.math.BigDecimal) Match(com.github.bordertech.wcomponents.subordinate.Match) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) LessThan(com.github.bordertech.wcomponents.subordinate.LessThan) Equal(com.github.bordertech.wcomponents.subordinate.Equal) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) GreaterThan(com.github.bordertech.wcomponents.subordinate.GreaterThan) And(com.github.bordertech.wcomponents.subordinate.And) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) Show(com.github.bordertech.wcomponents.subordinate.Show) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 28 with WContainer

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);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 29 with WContainer

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);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) Action(com.github.bordertech.wcomponents.Action) WText(com.github.bordertech.wcomponents.WText) ActionEvent(com.github.bordertech.wcomponents.ActionEvent)

Example 30 with WContainer

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);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WText(com.github.bordertech.wcomponents.WText) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading)

Aggregations

WContainer (com.github.bordertech.wcomponents.WContainer)49 Test (org.junit.Test)41 WTextField (com.github.bordertech.wcomponents.WTextField)21 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)17 Equal (com.github.bordertech.wcomponents.subordinate.Equal)16 Rule (com.github.bordertech.wcomponents.subordinate.Rule)16 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)16 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)15 WButton (com.github.bordertech.wcomponents.WButton)14 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)14 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)14 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)14 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)11 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)10 Hide (com.github.bordertech.wcomponents.subordinate.Hide)10 Show (com.github.bordertech.wcomponents.subordinate.Show)10 WPanel (com.github.bordertech.wcomponents.WPanel)9 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)6 DiagnosticImpl (com.github.bordertech.wcomponents.validation.DiagnosticImpl)6 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)5