Search in sources :

Example 6 with WDateField

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

the class WDateFieldExample method addContraintExamples.

/**
 * Add constraint example.
 */
private void addContraintExamples() {
    add(new WHeading(HeadingLevel.H2, "Date fields with input constraints"));
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(33);
    add(layout);
    /* mandatory */
    WDateField constrainedDateField = new WDateField();
    constrainedDateField.setMandatory(true);
    layout.addField("Mandatory date field", constrainedDateField);
    /* min date */
    constrainedDateField = new WDateField();
    constrainedDateField.setMinDate(new Date());
    layout.addField("Minimum date today", constrainedDateField);
    /* max date */
    constrainedDateField = new WDateField();
    constrainedDateField.setMaxDate(new Date());
    layout.addField("Maximum date today", constrainedDateField);
    /* auto complete */
    constrainedDateField = new WDateField();
    constrainedDateField.setBirthdayAutocomplete();
    layout.addField("With autocomplete hint", constrainedDateField);
    constrainedDateField = new WDateField();
    constrainedDateField.setAutocompleteOff();
    layout.addField("With autocomplete off", constrainedDateField);
}
Also used : WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WDateField(com.github.bordertech.wcomponents.WDateField) WHeading(com.github.bordertech.wcomponents.WHeading) Date(java.util.Date)

Example 7 with WDateField

use of com.github.bordertech.wcomponents.WDateField 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 }, Size.LARGE, Size.MEDIUM));
    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 8 with WDateField

use of com.github.bordertech.wcomponents.WDateField 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 9 with WDateField

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

the class WDateFieldRenderer_Test method testRendererCorrectlyConfigured.

/**
 * Test the Layout is correctly configured.
 */
@Test
public void testRendererCorrectlyConfigured() {
    WDateField dateField = new WDateField();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(dateField) instanceof WDateFieldRenderer);
}
Also used : WDateField(com.github.bordertech.wcomponents.WDateField) Test(org.junit.Test)

Example 10 with WDateField

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

the class WDateFieldRenderer_Test method testDoPaintReadOnly.

@Test
public void testDoPaintReadOnly() throws IOException, SAXException, XpathException {
    WDateField dateField = new WDateField();
    dateField.setDate(TEST_DATE);
    dateField.setReadOnly(true);
    setActiveContext(createUIContext());
    // Validate Schema
    assertSchemaMatch(dateField);
    assertXpathEvaluatesTo("true", "//ui:datefield/@readOnly", dateField);
    assertXpathEvaluatesTo(TEST_INTERNAL_DATE_STRING, "//ui:datefield/@date", dateField);
}
Also used : WDateField(com.github.bordertech.wcomponents.WDateField) Test(org.junit.Test)

Aggregations

WDateField (com.github.bordertech.wcomponents.WDateField)27 Test (org.junit.Test)11 WTextField (com.github.bordertech.wcomponents.WTextField)8 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)7 Date (java.util.Date)7 SimpleDateFormat (java.text.SimpleDateFormat)5 WDataTable (com.github.bordertech.wcomponents.WDataTable)4 WNumberField (com.github.bordertech.wcomponents.WNumberField)4 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)3 WHeading (com.github.bordertech.wcomponents.WHeading)3 WLabel (com.github.bordertech.wcomponents.WLabel)3 WText (com.github.bordertech.wcomponents.WText)3 SystemException (com.github.bordertech.wcomponents.util.SystemException)3 ArrayList (java.util.ArrayList)3 AbstractWSelectList (com.github.bordertech.wcomponents.AbstractWSelectList)2 RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)2 TableTreeNode (com.github.bordertech.wcomponents.TableTreeNode)2 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)2 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)2 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)2