Search in sources :

Example 51 with WLabel

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

the class DiagnosticImpl_Test method testGetDescription.

@Test
public void testGetDescription() {
    final UIContext uic = new UIContextImpl();
    final WTextField input = new WTextField();
    final String noArgsMessage = "The field is required";
    final String fieldArgMessage = "The field ''{0}'' is required";
    // Test with no formatting
    DiagnosticImpl diag = new DiagnosticImpl(Diagnostic.INFO, uic, input, noArgsMessage);
    Assert.assertEquals("Incorrect description text", noArgsMessage, diag.getDescription());
    // Test with formatting, but missing label text should default to empty String
    diag = new DiagnosticImpl(Diagnostic.INFO, uic, input, fieldArgMessage, input);
    Assert.assertEquals("Incorrect description text", "The field '' is required", diag.getDescription());
    // Test with formatting with accessible text set
    input.setAccessibleText("a");
    Assert.assertEquals("Incorrect description text", "The field 'a' is required", diag.getDescription());
    // Test with formatting with toolTip
    input.setAccessibleText(null);
    input.setToolTip("a tooltip");
    Assert.assertEquals("Incorrect description text", "The field 'a tooltip' is required", diag.getDescription());
    // Test with label set
    WLabel label = new WLabel("bc", input);
    Assert.assertEquals("Incorrect description text", "The field 'bc' is required", diag.getDescription());
    // Test with label set, with a colon at the end
    label.setText("def:");
    Assert.assertEquals("Incorrect description text", "The field 'def' is required", diag.getDescription());
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) WTextField(com.github.bordertech.wcomponents.WTextField) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 52 with WLabel

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

the class TextDuplicator method setupUI.

/**
 * Add the controls to the UI.
 * @param labelText the text to show in the duplicator field's label.
 */
private void setupUI(final String labelText) {
    WButton dupBtn = new WButton("Duplicate");
    dupBtn.setAction(new DuplicateAction());
    WButton clrBtn = new WButton("Clear");
    clrBtn.setAction(new ClearAction());
    add(new WLabel(labelText, textFld));
    add(textFld);
    add(dupBtn);
    add(clrBtn);
    add(new WAjaxControl(dupBtn, this));
    add(new WAjaxControl(clrBtn, this));
}
Also used : WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) WButton(com.github.bordertech.wcomponents.WButton) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 53 with WLabel

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

the class WSkipLinksExample method buildPanel.

/**
 * Creates a panel for the example.
 *
 * @param title the panel title.
 * @return a panel for use in the example.
 */
private WPanel buildPanel(final String title) {
    WPanel panel = new WPanel(WPanel.Type.CHROME);
    panel.setTitleText(title);
    WProgressBar progress = new WProgressBar(18);
    progress.setValue(15);
    panel.add(progress);
    panel.add(new WHorizontalRule());
    WTextField input = new WTextField();
    WLabel label = new WLabel("Text input", input);
    panel.add(label);
    panel.add(input);
    return panel;
}
Also used : WProgressBar(com.github.bordertech.wcomponents.WProgressBar) WPanel(com.github.bordertech.wcomponents.WPanel) WTextField(com.github.bordertech.wcomponents.WTextField) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 54 with WLabel

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

the class WCheckBoxSelectExample method addAntiPatternExamples.

/**
 * Examples of what not to do when using WCheckBoxSelect.
 */
private void addAntiPatternExamples() {
    add(new WHeading(HeadingLevel.H2, "WCheckBoxSelect anti-pattern examples"));
    add(new WMessageBox(WMessageBox.WARN, "These examples are purposely bad and should not be used as samples of how to use WComponents but samples of how NOT to use them."));
    add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect with submitOnChange"));
    WFieldLayout layout = new WFieldLayout(WFieldLayout.LAYOUT_STACKED);
    add(layout);
    WCheckBoxSelect select = new WCheckBoxSelect("australian_state");
    select.setSubmitOnChange(true);
    layout.addField("Select a state or territory with auto save", select);
    select = new WCheckBoxSelect("australian_state");
    select.setSubmitOnChange(true);
    layout.addField("Select a state or territory with auto save and hint", select).getLabel().setHint("This is a hint");
    // Even compound controls need a label
    add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect with no labelling component"));
    add(new ExplanatoryText("All input controls, even those which are complex and do not output labellable HTML elements, must be associated with" + " a WLabel or have a toolTip."));
    add(new WCheckBoxSelect("australian_state"));
    // Too many options anti-pattern
    add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect with too many options"));
    add(new ExplanatoryText("Don't use a WCheckBoxSelect if you have more than a handful of options. A good rule of thumb is fewer than 10."));
    select = new WCheckBoxSelect(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" });
    select.setButtonLayout(WCheckBoxSelect.LAYOUT_COLUMNS);
    select.setButtonColumns(6);
    select.setFrameless(true);
    add(new WLabel("Select your country of birth", select));
    add(select);
    add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect with no options."));
    add(new ExplanatoryText("An interactive WCheckBoxSelect with no options is rather pointless."));
    select = new WCheckBoxSelect();
    add(new WLabel("WCheckBoxSelect with no options", select));
    add(select);
}
Also used : WMessageBox(com.github.bordertech.wcomponents.WMessageBox) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WHeading(com.github.bordertech.wcomponents.WHeading) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 55 with WLabel

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

the class WCheckBoxSelectExample method addExampleUsingLookupTable.

/**
 * This example creates the WCheckBoxSelect using an a look up table. All other optional properties are in their default state.
 * <p>Note for Framework devs: the unit tests for this Example are used to test the Selenium WebElement extension and this example is expected
 * to be: the first WCheckBoxSelect in the example; and to be interactive; and to have the 9 options of the "australian_state" lookup table.
 */
private void addExampleUsingLookupTable() {
    add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect created using a lookup table"));
    final WCheckBoxSelect select = new WCheckBoxSelect("australian_state");
    final WTextField text = new WTextField();
    text.setReadOnly(true);
    text.setText(NO_SELECTION);
    WButton update = new WButton("Select");
    update.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            String output = select.getSelected().isEmpty() ? NO_SELECTION : "The selected states are: " + select.getSelected();
            text.setText(output);
        }
    });
    select.setDefaultSubmitButton(update);
    add(new WLabel("Select a state or territory", select));
    add(select);
    add(update);
    add(text);
    add(new WAjaxControl(update, text));
}
Also used : Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect) WLabel(com.github.bordertech.wcomponents.WLabel)

Aggregations

WLabel (com.github.bordertech.wcomponents.WLabel)99 Test (org.junit.Test)57 WHeading (com.github.bordertech.wcomponents.WHeading)13 WTextField (com.github.bordertech.wcomponents.WTextField)10 WButton (com.github.bordertech.wcomponents.WButton)9 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)9 WComponent (com.github.bordertech.wcomponents.WComponent)8 WRadioButtonSelect (com.github.bordertech.wcomponents.WRadioButtonSelect)8 WPanel (com.github.bordertech.wcomponents.WPanel)7 UIContext (com.github.bordertech.wcomponents.UIContext)6 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)6 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)5 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)5 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)5 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)5 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)5 Action (com.github.bordertech.wcomponents.Action)4 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)4 WApplication (com.github.bordertech.wcomponents.WApplication)4 WContainer (com.github.bordertech.wcomponents.WContainer)4