Search in sources :

Example 41 with WFieldLayout

use of com.github.bordertech.wcomponents.WFieldLayout in project wcomponents by BorderTech.

the class WTabSetExample method constructExample.

/**
 * Helper to do the work of the constructor since we do not really want to call over-rideable methods in a
 * constructor.
 */
private void constructExample() {
    add(new WHeading(HeadingLevel.H2, "Examples showing TabSet Type property."));
    add(new WHeading(HeadingLevel.H3, "Tabs at the top"));
    WTabSet tabset0 = new SampleWTabset();
    add(tabset0);
    add(new WHeading(HeadingLevel.H3, "Tabs at the top with explicit TYPE"));
    /* Explicitly setting TYPE_TOP is superfluous */
    WTabSet tabset1 = new SampleWTabset(WTabSet.TYPE_TOP);
    add(tabset1);
    add(new WHeading(HeadingLevel.H3, "Tabs on the LEFT"));
    WTabSet tabset1a = new SampleWTabset(WTabSet.TYPE_LEFT);
    add(tabset1a);
    add(new WHeading(HeadingLevel.H3, "Tabs on the RIGHT"));
    WTabSet tabset1b = new SampleWTabset(WTabSet.TYPE_RIGHT);
    add(tabset1b);
    add(new WHeading(HeadingLevel.H3, "ACCORDION tabs"));
    WTabSet tabset1c = new SampleWTabset(TabSetType.ACCORDION);
    add(tabset1c);
    add(new WHorizontalRule());
    /* Content height */
    add(new WHeading(HeadingLevel.H2, "Examples showing content height property."));
    add(new WHeading(HeadingLevel.H3, "Tall content."));
    WTabSet htabset1 = new SampleWTabset();
    htabset1.setContentHeight(TALL_CONTENT);
    add(htabset1);
    WTabSet htabset1a = new SampleWTabset(WTabSet.TYPE_LEFT);
    htabset1a.setContentHeight(TALL_CONTENT);
    add(htabset1a);
    WTabSet htabset1b = new SampleWTabset(WTabSet.TYPE_RIGHT);
    htabset1b.setContentHeight(TALL_CONTENT);
    add(htabset1b);
    WTabSet htabset1c = new SampleWTabset(TabSetType.ACCORDION);
    htabset1c.setContentHeight(TALL_CONTENT);
    add(htabset1c);
    add(new WHeading(HeadingLevel.H3, "Short content."));
    WTabSet htabset1d = new SampleWTabset();
    htabset1d.setContentHeight(SHORT_CONTENT);
    add(htabset1d);
    WTabSet htabset1e = new SampleWTabset(WTabSet.TYPE_LEFT);
    htabset1e.setContentHeight(SHORT_CONTENT);
    add(htabset1e);
    WTabSet htabset1f = new SampleWTabset(WTabSet.TYPE_RIGHT);
    htabset1f.setContentHeight(SHORT_CONTENT);
    add(htabset1f);
    WTabSet htabset1g = new SampleWTabset(TabSetType.ACCORDION);
    htabset1g.setContentHeight(SHORT_CONTENT);
    add(htabset1g);
    add(new WHorizontalRule());
    add(new WHeading(HeadingLevel.H2, "Examples showing disabled property."));
    /* NOTE: WTabSet does not currently implement SubordinateTarget therefore one cannot create a subordinate
		 * control to disable/enable a WTabSet.
		 */
    WTabSet disabledTabset = new SampleWTabset();
    disabledTabset.setDisabled(true);
    add(disabledTabset);
    add(new WHeading(HeadingLevel.H2, "Examples showing accordion's single property."));
    WTabSet singleOpenAccordionabset = new SampleWTabset(WTabSet.TYPE_ACCORDION);
    singleOpenAccordionabset.setSingle(true);
    add(singleOpenAccordionabset);
    add(new WHorizontalRule());
    /* NOTE: no example of the hidden property because WTabSet is not a subordinate target. This is inconsistent
		 * with the schema. */
    add(new WHeading(HeadingLevel.H2, "Setting the initially active tab"));
    add(new WHeading(HeadingLevel.H3, "Server side with tabs on the left, with second tab initially active."));
    WTabSet tabset3 = new WTabSet(WTabSet.TYPE_LEFT);
    tabset3.setContentHeight("10em");
    tabset3.addTab(new WText("Some content should go in here."), "First tab", WTabSet.TAB_MODE_SERVER, 'i');
    WPanel largeContent2 = new WPanel();
    largeContent2.setLayout(new FlowLayout(Alignment.VERTICAL));
    largeContent2.add(new WText(LONG_TEXT));
    largeContent2.add(new WText(LONG_TEXT));
    largeContent2.add(new WText(LONG_TEXT));
    tabset3.addTab(largeContent2, "Second tab which is much longer", WTabSet.TAB_MODE_SERVER, 'e');
    WImage image = new WImage("/image/success.png", "success");
    image.setCacheKey("eg-image-tab");
    WDecoratedLabel tabLabel = new WDecoratedLabel(image, new WText("Third tab"), null);
    tabset3.addTab(new WText("The tab button for this tab has an image!"), tabLabel, WTabSet.TAB_MODE_SERVER, 'h');
    // Set 2nd tab active
    tabset3.setActiveIndex(1);
    add(tabset3);
    add(new WHeading(HeadingLevel.H3, "Client side with tabs on the right and the third tab initially active."));
    WText thirdContent = new WText("Some more content should go into here.");
    WTabSet tabset4 = new WTabSet(WTabSet.TYPE_RIGHT);
    tabset4.setContentHeight("10em");
    tabset4.addTab(new WText("Some content should go into here."), "First tab", WTabSet.TAB_MODE_CLIENT);
    tabset4.addTab(new WText(LONG_TEXT), "Second tab which is longer", WTabSet.TAB_MODE_CLIENT);
    tabset4.addTab(thirdContent, "Third tab", WTabSet.TAB_MODE_CLIENT);
    // Set 3rd tab active
    tabset4.setActiveTab(thirdContent);
    add(tabset4);
    add(new WHeading(HeadingLevel.H3, "Client side with showing lots of tabs."));
    add(new ExplanatoryText("This will effectively show what happens when tabs need to wrap. You should do everything possible to avoid this situation."));
    WTabSet tabset5 = new WTabSet();
    tabset5.addTab(new WText("Tab 1."), "First tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 2."), "Second tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 3."), "Third tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 4."), "Fourth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 5."), "Fifth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 6."), "Sixth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 7."), "Seventh tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 8."), "Eighth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 9."), "Nineth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 10."), "Tenth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 11."), "Eleventh tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 12."), "Twelfth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 13."), "Thirteenth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 14."), "Fourteenth tab", WTabSet.TAB_MODE_CLIENT);
    tabset5.addTab(new WText("Tab 15."), "Fifteenth tab", WTabSet.TAB_MODE_CLIENT);
    add(tabset5);
    add(new WHorizontalRule());
    add(new WHeading(HeadingLevel.H2, "Using WSubordinateControl"));
    WTabSet targetTabset = new SampleWTabset();
    add(targetTabset);
    WFieldLayout layout = new WFieldLayout(WFieldLayout.LAYOUT_STACKED);
    add(layout);
    final WCheckBox disabledControllerCb = new WCheckBox();
    final WCheckBox hiddenControllerCb = new WCheckBox();
    layout.addField("disable tabset", disabledControllerCb);
    layout.addField("hide tabset", hiddenControllerCb);
    // Build & add the subordinate
    SubordinateBuilder builder = new SubordinateBuilder();
    builder.condition().equals(hiddenControllerCb, String.valueOf(true));
    builder.whenTrue().hide(targetTabset);
    builder.whenFalse().show(targetTabset);
    add(builder.build());
    builder = new SubordinateBuilder();
    builder.condition().equals(disabledControllerCb, String.valueOf(true));
    builder.whenTrue().disable(targetTabset);
    builder.whenFalse().enable(targetTabset);
    add(builder.build());
}
Also used : FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) WPanel(com.github.bordertech.wcomponents.WPanel) WImage(com.github.bordertech.wcomponents.WImage) SubordinateBuilder(com.github.bordertech.wcomponents.subordinate.builder.SubordinateBuilder) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WHeading(com.github.bordertech.wcomponents.WHeading) WText(com.github.bordertech.wcomponents.WText) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WTabSet(com.github.bordertech.wcomponents.WTabSet) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule) WDecoratedLabel(com.github.bordertech.wcomponents.WDecoratedLabel)

Example 42 with WFieldLayout

use of com.github.bordertech.wcomponents.WFieldLayout in project wcomponents by BorderTech.

the class WCheckBoxExample_Test method testFindByLabelTextExact.

/**
 * Test that ByLabel works for CheckBoxes by label text exact match.
 */
@Test
public void testFindByLabelTextExact() {
    // Launch the web browser to the LDE
    WebDriver driver = getDriver();
    WContainer container = (WContainer) getUi();
    WFieldLayout layout = (WFieldLayout) container.getChildAt(0);
    WField field = (WField) layout.getChildAt(0);
    String labelText = field.getLabel().getText();
    String componentId = field.getField().getId();
    WebElement checkBox = driver.findElement(new ByLabel(labelText, false));
    Assert.assertNotNull("Unable to find checkbox by label text", checkBox);
    Assert.assertEquals("Checkbox element ID does not match expected", componentId, checkBox.getAttribute("id"));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WContainer(com.github.bordertech.wcomponents.WContainer) WField(com.github.bordertech.wcomponents.WField) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WebElement(org.openqa.selenium.WebElement) ByLabel(com.github.bordertech.wcomponents.test.selenium.ByLabel) Test(org.junit.Test)

Example 43 with WFieldLayout

use of com.github.bordertech.wcomponents.WFieldLayout in project wcomponents by BorderTech.

the class WFieldLayoutRenderer_Test method testDoPaintWithFields.

@Test
public void testDoPaintWithFields() throws IOException, SAXException, XpathException {
    WFieldLayout layout = new WFieldLayout();
    layout.addField("Test1", new WTextField());
    layout.addField("Test2", new WTextField());
    // Validate Schema
    assertSchemaMatch(layout);
    // Check Fields
    assertXpathEvaluatesTo("2", "count(//ui:fieldlayout/ui:field)", layout);
}
Also used : WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 44 with WFieldLayout

use of com.github.bordertech.wcomponents.WFieldLayout in project wcomponents by BorderTech.

the class WFieldRenderer_Test method testWithValidationMessages.

@Test
public void testWithValidationMessages() throws IOException, SAXException, XpathException {
    WTextField text = new WTextField();
    text.setText("text1");
    WFieldLayout test = new WFieldLayout();
    WField field = test.addField("label1", text);
    setActiveContext(createUIContext());
    assertXpathEvaluatesTo("text1", "//ui:field/ui:input/ui:textfield/text()", field);
    // Simulate Error Message
    List<Diagnostic> diags = new ArrayList<>();
    diags.add(new DiagnosticImpl(Diagnostic.ERROR, text, "Test Error"));
    diags.add(new DiagnosticImpl(Diagnostic.WARNING, text, "Test Warning"));
    field.showErrorIndicators(diags);
    field.showWarningIndicators(diags);
    // Validate Schema
    assertSchemaMatch(test);
    // Check Attributes
    assertXpathEvaluatesTo(field.getId(), "//ui:field/@id", field);
    // Check Label
    assertXpathEvaluatesTo("label1", "//ui:field/ui:label", field);
    // Check Input
    assertXpathEvaluatesTo("text1", "//ui:field/ui:input/ui:textfield/text()", field);
    assertXpathExists("//ui:field/ui:input/ui:textfield/ui:fieldindicator", field);
    assertXpathExists("//ui:field/ui:input/ui:textfield/ui:fieldindicator[@type='error']", field);
    assertXpathExists("//ui:field/ui:input/ui:textfield/ui:fieldindicator[@type='warn']", field);
    assertXpathEvaluatesTo("Test Error", "//ui:field/ui:input/ui:textfield/ui:fieldindicator[@type='error']/ui:message", field);
    assertXpathEvaluatesTo("Test Warning", "//ui:field/ui:input/ui:textfield/ui:fieldindicator[@type='warn']/ui:message", field);
}
Also used : WField(com.github.bordertech.wcomponents.WField) DiagnosticImpl(com.github.bordertech.wcomponents.validation.DiagnosticImpl) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 45 with WFieldLayout

use of com.github.bordertech.wcomponents.WFieldLayout in project wcomponents by BorderTech.

the class WFieldRenderer_Test method testDoPaintBasic.

@Test
public void testDoPaintBasic() throws IOException, SAXException, XpathException {
    WTextField text = new WTextField();
    WFieldLayout test = new WFieldLayout();
    WField field = test.addField("label1", text);
    text.setText("text1");
    // Validate Schema
    assertSchemaMatch(test);
    // Check Attributes
    assertXpathEvaluatesTo(field.getId(), "//ui:field/@id", field);
    assertXpathEvaluatesTo("", "//ui:field/@hidden", field);
    assertXpathEvaluatesTo("", "//ui:field/@inputWidth", field);
    // Check Label
    assertXpathEvaluatesTo("label1", "//ui:field/ui:label", field);
    // Check Input
    assertXpathEvaluatesTo("text1", "//ui:field/ui:input/ui:textfield", field);
    // Test Hidden
    setFlag(field, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(test);
    assertXpathEvaluatesTo("true", "//ui:field/@hidden", field);
    // Test Width - 1
    field.setInputWidth(1);
    assertSchemaMatch(test);
    assertXpathEvaluatesTo("1", "//ui:field/@inputWidth", field);
    // Test Width - 100
    field.setInputWidth(100);
    assertSchemaMatch(test);
    assertXpathEvaluatesTo("100", "//ui:field/@inputWidth", field);
}
Also used : WField(com.github.bordertech.wcomponents.WField) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Aggregations

WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)47 WHeading (com.github.bordertech.wcomponents.WHeading)18 Test (org.junit.Test)13 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)12 WButton (com.github.bordertech.wcomponents.WButton)11 WTextField (com.github.bordertech.wcomponents.WTextField)11 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)11 Margin (com.github.bordertech.wcomponents.Margin)10 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)10 WField (com.github.bordertech.wcomponents.WField)10 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)10 Action (com.github.bordertech.wcomponents.Action)8 WRadioButtonSelect (com.github.bordertech.wcomponents.WRadioButtonSelect)7 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)6 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)5 WContainer (com.github.bordertech.wcomponents.WContainer)5 WLabel (com.github.bordertech.wcomponents.WLabel)5 WText (com.github.bordertech.wcomponents.WText)5 Equal (com.github.bordertech.wcomponents.subordinate.Equal)5 Rule (com.github.bordertech.wcomponents.subordinate.Rule)5