Search in sources :

Example 1 with WLabel

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

the class SubordinateControlOptionsExample method setupTrigger.

/**
 * Setup the trigger for the subordinate control.
 */
private void setupTrigger() {
    String label = drpTriggerType.getSelected() + " Trigger";
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(LABEL_WIDTH);
    buildControlPanel.add(layout);
    switch((TriggerType) drpTriggerType.getSelected()) {
        case RadioButtonGroup:
            trigger = new RadioButtonGroup();
            WFieldSet rbSet = new WFieldSet("Select an option");
            RadioButtonGroup group = (RadioButtonGroup) trigger;
            WRadioButton rb1 = group.addRadioButton("A");
            WRadioButton rb2 = group.addRadioButton("B");
            WRadioButton rb3 = group.addRadioButton("C");
            rbSet.add(group);
            rbSet.add(rb1);
            rbSet.add(new WLabel("A", rb1));
            rbSet.add(new WText("\u00a0"));
            rbSet.add(rb2);
            rbSet.add(new WLabel("B", rb2));
            rbSet.add(new WText("\u00a0"));
            rbSet.add(rb3);
            rbSet.add(new WLabel("C", rb3));
            layout.addField(label, rbSet);
            return;
        case CheckBox:
            trigger = new WCheckBox();
            break;
        case CheckBoxSelect:
            trigger = new WCheckBoxSelect(LOOKUP_TABLE_NAME);
            break;
        case DateField:
            trigger = new WDateField();
            break;
        case Dropdown:
            trigger = new WDropdown(new TableWithNullOption(LOOKUP_TABLE_NAME));
            break;
        case EmailField:
            trigger = new WEmailField();
            break;
        case MultiSelect:
            trigger = new WMultiSelect(LOOKUP_TABLE_NAME);
            break;
        case MultiSelectPair:
            trigger = new WMultiSelectPair(LOOKUP_TABLE_NAME);
            break;
        case NumberField:
            trigger = new WNumberField();
            break;
        case PartialDateField:
            trigger = new WPartialDateField();
            break;
        case PasswordField:
            trigger = new WPasswordField();
            break;
        case PhoneNumberField:
            trigger = new WPhoneNumberField();
            break;
        case RadioButtonSelect:
            trigger = new WRadioButtonSelect(LOOKUP_TABLE_NAME);
            break;
        case SingleSelect:
            trigger = new WSingleSelect(LOOKUP_TABLE_NAME);
            break;
        case TextArea:
            trigger = new WTextArea();
            ((WTextArea) trigger).setMaxLength(1000);
            break;
        case TextField:
            trigger = new WTextField();
            break;
        default:
            throw new SystemException("Trigger type not valid");
    }
    layout.addField(label, trigger);
}
Also used : WFieldSet(com.github.bordertech.wcomponents.WFieldSet) WNumberField(com.github.bordertech.wcomponents.WNumberField) WEmailField(com.github.bordertech.wcomponents.WEmailField) WPasswordField(com.github.bordertech.wcomponents.WPasswordField) WMultiSelect(com.github.bordertech.wcomponents.WMultiSelect) WLabel(com.github.bordertech.wcomponents.WLabel) WTextArea(com.github.bordertech.wcomponents.WTextArea) WRadioButton(com.github.bordertech.wcomponents.WRadioButton) WDropdown(com.github.bordertech.wcomponents.WDropdown) SystemException(com.github.bordertech.wcomponents.util.SystemException) WText(com.github.bordertech.wcomponents.WText) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) TableWithNullOption(com.github.bordertech.wcomponents.examples.common.ExampleLookupTable.TableWithNullOption) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) WTextField(com.github.bordertech.wcomponents.WTextField) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect) WMultiSelectPair(com.github.bordertech.wcomponents.WMultiSelectPair) WPhoneNumberField(com.github.bordertech.wcomponents.WPhoneNumberField) WSingleSelect(com.github.bordertech.wcomponents.WSingleSelect) RadioButtonGroup(com.github.bordertech.wcomponents.RadioButtonGroup) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WPartialDateField(com.github.bordertech.wcomponents.WPartialDateField) WDateField(com.github.bordertech.wcomponents.WDateField)

Example 2 with WLabel

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

the class WCheckBoxSelectExample method addExampleUsingStringArray.

/**
 * This example creates the WCheckBoxSelect from an array of Strings.
 */
private void addExampleUsingStringArray() {
    add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect created using a String array"));
    String[] options = new String[] { "Dog", "Cat", "Bird", "Turtle" };
    final WCheckBoxSelect select = new WCheckBoxSelect(options);
    select.setToolTip("Animals");
    select.setMandatory(true);
    final WTextField text = new WTextField();
    text.setReadOnly(true);
    text.setText(NO_SELECTION);
    WButton update = new WButton("Select Animals");
    update.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            String output = select.getSelected().isEmpty() ? NO_SELECTION : "The selected animals are: " + select.getSelected();
            text.setText(output);
        }
    });
    select.setDefaultSubmitButton(update);
    WLabel animalLabel = new WLabel("A selection is required", select);
    animalLabel.setHint("mandatory");
    add(animalLabel);
    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)

Example 3 with WLabel

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

the class WLabelExample method addNullLabelExample.

/**
 * Example of when and how to use a null WLabel.
 */
private void addNullLabelExample() {
    add(new WHeading(HeadingLevel.H2, "How to use accessible null WLabels"));
    add(new ExplanatoryText("These examples shows how sometime a null WLabel is the right thing to do." + "\n This example uses a WFieldSet as the labelled component and it has its own \"label\"."));
    // We want to add a WFieldSet to a WFieldLayout but without an extra label.
    WFieldLayout fieldsFlat = new WFieldLayout();
    fieldsFlat.setMargin(new Margin(null, null, Size.XL, null));
    add(fieldsFlat);
    WFieldSet fs = new WFieldSet("Do you like Bananas?");
    fieldsFlat.addField((WLabel) null, fs);
    // now add the WRadioButtons to the WFieldSet using an inner WFieldLayout
    WFieldLayout innerLayout = new WFieldLayout(WFieldLayout.LAYOUT_STACKED);
    // The content will be a group of WRadioButtons
    RadioButtonGroup group1 = new RadioButtonGroup();
    WRadioButton rb1 = group1.addRadioButton(1);
    WRadioButton rb2 = group1.addRadioButton(2);
    // make the labels for the radio buttons
    WLabel rb1Label = new WLabel("", rb1);
    WImage labelImage = new WImage("/image/success.png", "I still like bananas");
    labelImage.setHtmlClass("wc-valign-bottom");
    rb1Label.add(labelImage);
    WLabel rb2Label = new WLabel("", rb2);
    labelImage = new WImage("/image/error.png", "I still dislike bananas");
    labelImage.setHtmlClass("wc-valign-bottom");
    rb2Label.add(labelImage);
    innerLayout.addField(rb1Label, rb1);
    innerLayout.addField(rb2Label, rb2);
    // add the content to the WFieldLayout - the order really doesn't matter.
    fs.add(group1);
    fs.add(innerLayout);
}
Also used : WFieldSet(com.github.bordertech.wcomponents.WFieldSet) WRadioButton(com.github.bordertech.wcomponents.WRadioButton) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) RadioButtonGroup(com.github.bordertech.wcomponents.RadioButtonGroup) WImage(com.github.bordertech.wcomponents.WImage) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WHeading(com.github.bordertech.wcomponents.WHeading) Margin(com.github.bordertech.wcomponents.Margin) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 4 with WLabel

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

the class WLabelExample method addAntiPatternExamples.

/**
 * Add examples you should never follow. DO NOT use the following as examples of what to do: these are examples of what NOT to do.
 */
private void addAntiPatternExamples() {
    add(new WHeading(HeadingLevel.H2, "WLabel anti-patterns"));
    add(new ExplanatoryText("These are here for testing purposes and must not be used as examples to follow.\n" + "Turn on debugging (bordertech.wcomponents.debug.enabled=true) to get much more information."));
    add(new WHeading(HeadingLevel.H3, "Poor but not erroneous uses of WLabel"));
    WPanel errorLayoutPanel = new WPanel();
    errorLayoutPanel.setLayout(new FlowLayout(FlowLayout.VERTICAL, Size.LARGE));
    add(errorLayoutPanel);
    // label not for anything should not be a WLabel
    errorLayoutPanel.add(new WLabel("I am not 'for' anything"));
    // WLabel for something which is not labellable
    errorLayoutPanel.add(new WLabel("I am for a component which should not be labelled", errorLayoutPanel));
    // If the WLabel is 'for' something that is not in the tree it becomes 'for' the WApplication. This is not necessarily a good thing!!!
    WCheckBox notHere = new WCheckBox();
    errorLayoutPanel.add(new WLabel("My component wasn't added", notHere));
    /*
		 * The examples which follow MUST NEVER BE USED! They cause ERRORS.
		 * They are here purely for framework testing.
		 */
    add(new WHeading(HeadingLevel.H3, "Very bad uses of WLabel"));
    errorLayoutPanel = new WPanel();
    errorLayoutPanel.setLayout(new FlowLayout(FlowLayout.VERTICAL, Size.LARGE));
    add(errorLayoutPanel);
    /*
		 * Nested WLabels: very bad
		 */
    errorLayoutPanel.add(new ExplanatoryText("This example shows nested WLabels. This is a contravention of the HTML specification."));
    WPanel nestingErrorPanel = new WPanel();
    nestingErrorPanel.setLayout(new ColumnLayout(new int[] { 50, 50 }, Size.LARGE, Size.MEDIUM));
    errorLayoutPanel.add(nestingErrorPanel);
    WTextField outerField = new WTextField();
    WLabel outerLabel = new WLabel("I am an outer label", outerField);
    nestingErrorPanel.add(outerLabel);
    WTextField innerField = new WTextField();
    WLabel innerLabel = new WLabel("Inner label", innerField);
    // add the inner label to the outer label: this is the ERROR
    outerLabel.add(innerLabel);
    nestingErrorPanel.add(innerField);
    nestingErrorPanel.add(outerField);
    /*
		 * It is permissible to place certain simple form control components into
		 * a WLabel under the following conditions:
		 * there must be no more than one such component in the WLabel;
		 * the component MUST be one which outputs a simple HTML form control
		 * (and I am not going to tell you which they are);
		 * The WLabel must be 'for' the nested component or not 'for' anything.
		 */
    errorLayoutPanel.add(new ExplanatoryText("This example shows a WLabel with a nested simple form control WTextField but the WLabel is not " + "'for' the WTextField. This is a contravention of the HTML specification."));
    WTextField notMyField = new WTextField();
    notMyField.setToolTip("This field should not be in the label it is in");
    WTextField myField = new WTextField();
    WLabel myFieldLabel = new WLabel("I am not the label for my nested text field", myField);
    nestingErrorPanel = new WPanel();
    nestingErrorPanel.setLayout(new ColumnLayout(new int[] { 50, 50 }, 12, 6));
    errorLayoutPanel.add(nestingErrorPanel);
    nestingErrorPanel.add(myFieldLabel);
    nestingErrorPanel.add(myField);
    // adding the 'wrong' WTextField to a WLabel is what causes this error
    myFieldLabel.add(notMyField);
    add(new ExplanatoryText("The next field has a label explicitly set to only white space."));
    WTextField emptyLabelTextField = new WTextField();
    WLabel emptyLabel = new WLabel(" ", emptyLabelTextField);
    add(emptyLabel);
    add(emptyLabelTextField);
    add(new WHeading(HeadingLevel.H2, "Unlabelled controls"));
    add(new ExplanatoryText("These controls must be labelled but are not."));
    WFieldLayout fieldsFlat = new WFieldLayout();
    add(fieldsFlat);
    fieldsFlat.addField((WLabel) null, new WTextField());
    fieldsFlat.addField((WLabel) null, new WTextArea());
    fieldsFlat.addField((WLabel) null, new WDateField());
    fieldsFlat.addField((WLabel) null, new WCheckBox());
    fieldsFlat.addField((WLabel) null, new WCheckBoxSelect(new String[] { "Apple", "Cherry", "Orange", "Pineapple" }));
}
Also used : FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) WPanel(com.github.bordertech.wcomponents.WPanel) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WHeading(com.github.bordertech.wcomponents.WHeading) WLabel(com.github.bordertech.wcomponents.WLabel) WTextArea(com.github.bordertech.wcomponents.WTextArea) ColumnLayout(com.github.bordertech.wcomponents.layout.ColumnLayout) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WDateField(com.github.bordertech.wcomponents.WDateField) WTextField(com.github.bordertech.wcomponents.WTextField) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect)

Example 5 with WLabel

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

the class ObjectGraphNode_Test method testToFlatSummary.

@Test
public void testToFlatSummary() {
    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 flatSummary = node.toFlatSummary();
    flatSummary = flatSummary.replaceAll("\n", "");
    Assert.assertTrue("summary should start with size", flatSummary.startsWith(node.getSize() + " "));
    Assert.assertTrue("summary should end with class name", flatSummary.endsWith(label.getClass().getName()));
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

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