Search in sources :

Example 1 with WMultiSelectPair

use of com.github.bordertech.wcomponents.WMultiSelectPair 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 WMultiSelectPair

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

the class WMultiSelectPairRenderer_Test method testDoPaintOptions.

@Test
public void testDoPaintOptions() throws IOException, SAXException, XpathException {
    WMultiSelectPair select = new WMultiSelectPair(new String[] { "a", "b", "c" });
    select.setRows(3);
    select.setDisabled(true);
    setFlag(select, ComponentModel.HIDE_FLAG, true);
    select.setMandatory(true);
    select.setShuffle(true);
    select.setAvailableListName("available");
    select.setSelectedListName("selected");
    select.setAccessibleText("accessible text");
    select.setMinSelect(1);
    select.setMaxSelect(2);
    assertSchemaMatch(select);
    assertXpathEvaluatesTo(select.getId(), "//ui:multiselectpair/@id", select);
    assertXpathEvaluatesTo("3", "//ui:multiselectpair/@size", select);
    assertXpathEvaluatesTo("true", "//ui:multiselectpair/@disabled", select);
    assertXpathEvaluatesTo("true", "//ui:multiselectpair/@hidden", select);
    assertXpathEvaluatesTo("true", "//ui:multiselectpair/@required", select);
    assertXpathEvaluatesTo("true", "//ui:multiselectpair/@shuffle", select);
    assertXpathEvaluatesTo("available", "//ui:multiselectpair/@fromListName", select);
    assertXpathEvaluatesTo("selected", "//ui:multiselectpair/@toListName", select);
    assertXpathEvaluatesTo("accessible text", "//ui:multiselectpair/@accessibleText", select);
    assertXpathEvaluatesTo("1", "//ui:multiselectpair/@min", select);
    assertXpathEvaluatesTo("2", "//ui:multiselectpair/@max", select);
}
Also used : WMultiSelectPair(com.github.bordertech.wcomponents.WMultiSelectPair) Test(org.junit.Test)

Example 3 with WMultiSelectPair

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

the class WMultiSelectPairRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WMultiSelectPair multiSelectPair = new WMultiSelectPair();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(multiSelectPair) instanceof WMultiSelectPairRenderer);
}
Also used : WMultiSelectPair(com.github.bordertech.wcomponents.WMultiSelectPair) Test(org.junit.Test)

Example 4 with WMultiSelectPair

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

the class WMultiSelectPairRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    final String option1 = "WMultiSelectPairRenderer_Test.testDoPaint.option1";
    final String option2 = "WMultiSelectPairRenderer_Test.testDoPaint.option2";
    final String option3 = "WMultiSelectPairRenderer_Test.testDoPaint.option3";
    // Empty list
    WMultiSelectPair select = new WMultiSelectPair();
    setActiveContext(createUIContext());
    assertSchemaMatch(select);
    assertXpathEvaluatesTo("0", "count(//ui:multiselectpair/option)", select);
    assertXpathEvaluatesTo(select.getId(), "//ui:multiselectpair/@id", select);
    assertXpathEvaluatesTo(String.valueOf(select.getRows()), "//ui:multiselectpair/@size", select);
    assertXpathNotExists("//ui:multiselectpair/@disabled", select);
    assertXpathNotExists("//ui:multiselectpair/@required", select);
    assertXpathNotExists("//ui:multiselectpair/@accessibleText", select);
    assertXpathEvaluatesTo(select.getAvailableListName(), "//ui:multiselectpair/@fromListName", select);
    assertXpathEvaluatesTo(select.getSelectedListName(), "//ui:multiselectpair/@toListName", select);
    // List with options
    select.setOptions(new String[] { option1, option2, option3 });
    assertSchemaMatch(select);
    assertXpathEvaluatesTo("3", "count(//ui:multiselectpair/ui:option)", select);
    assertXpathEvaluatesTo("0", "count(//ui:multiselectpair/ui:option[@selected='true'])", select);
    assertXpathEvaluatesTo(option1, "//ui:multiselectpair/ui:option[1]", select);
    assertXpathEvaluatesTo(option2, "//ui:multiselectpair/ui:option[2]", select);
    assertXpathEvaluatesTo(option3, "//ui:multiselectpair/ui:option[3]", select);
    // List with selected options
    select.setSelected(Arrays.asList(new String[] { option2 }));
    assertSchemaMatch(select);
    assertXpathEvaluatesTo("3", "count(//ui:multiselectpair/ui:option)", select);
    assertXpathEvaluatesTo("1", "count(//ui:multiselectpair/ui:option[@selected='true'])", select);
    assertXpathEvaluatesTo(option2, "//ui:multiselectpair/ui:option[@selected='true']", select);
    // Required
    select.setMandatory(true);
    assertSchemaMatch(select);
    assertXpathEvaluatesTo("true", "//ui:multiselectpair/@required", select);
    // Accessible text
    String accessibleText = "WMultiSelectPairRenderer_Test.testDoPaint.accessibleText";
    select.setAccessibleText(accessibleText);
    assertSchemaMatch(select);
    assertXpathEvaluatesTo(accessibleText, "//ui:multiselectpair/@accessibleText", select);
    // Disabled list
    select.setDisabled(true);
    assertSchemaMatch(select);
    assertXpathEvaluatesTo("true", "//ui:multiselectpair/@disabled", select);
    // Rows - Less than 2 should return default
    select.setRows(1);
    assertSchemaMatch(select);
    assertXpathEvaluatesTo(String.valueOf(WMultiSelectPair.DEFAULT_ROWS), "//ui:multiselectpair/@size", select);
    // Rows - Set valid rows
    select.setRows(10);
    assertSchemaMatch(select);
    assertXpathEvaluatesTo(String.valueOf(10), "//ui:multiselectpair/@size", select);
}
Also used : WMultiSelectPair(com.github.bordertech.wcomponents.WMultiSelectPair) Test(org.junit.Test)

Example 5 with WMultiSelectPair

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

the class WMultiSelectPairRenderer method doRender.

/**
 * Paints the given WMultiSelectPair.
 *
 * @param component the WMultiSelectPair to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WMultiSelectPair multiSelectPair = (WMultiSelectPair) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = multiSelectPair.isReadOnly();
    xml.appendTagOpen("ui:multiselectpair");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", multiSelectPair.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        int rows = multiSelectPair.getRows();
        int min = multiSelectPair.getMinSelect();
        int max = multiSelectPair.getMaxSelect();
        xml.appendAttribute("size", rows < 2 ? WMultiSelectPair.DEFAULT_ROWS : rows);
        xml.appendOptionalAttribute("disabled", multiSelectPair.isDisabled(), "true");
        xml.appendOptionalAttribute("required", multiSelectPair.isMandatory(), "true");
        xml.appendOptionalAttribute("shuffle", multiSelectPair.isShuffle(), "true");
        xml.appendOptionalAttribute("fromListName", multiSelectPair.getAvailableListName());
        xml.appendOptionalAttribute("toListName", multiSelectPair.getSelectedListName());
        xml.appendOptionalAttribute("accessibleText", multiSelectPair.getAccessibleText());
        xml.appendOptionalAttribute("min", min > 0, min);
        xml.appendOptionalAttribute("max", max > 0, max);
    }
    xml.appendClose();
    // Options
    List<?> options = multiSelectPair.getOptions();
    boolean renderSelectionsOnly = readOnly;
    if (options != null) {
        if (multiSelectPair.isShuffle()) {
            // We need to render the selected options in order
            renderOrderedOptions(multiSelectPair, options, 0, xml, renderSelectionsOnly);
        } else {
            renderUnorderedOptions(multiSelectPair, options, 0, xml, renderSelectionsOnly);
        }
    }
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(multiSelectPair, renderContext);
    }
    xml.appendEndTag("ui:multiselectpair");
}
Also used : WMultiSelectPair(com.github.bordertech.wcomponents.WMultiSelectPair) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Aggregations

WMultiSelectPair (com.github.bordertech.wcomponents.WMultiSelectPair)10 Test (org.junit.Test)8 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)3 WLabel (com.github.bordertech.wcomponents.WLabel)2 RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)1 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)1 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)1 WDateField (com.github.bordertech.wcomponents.WDateField)1 WDropdown (com.github.bordertech.wcomponents.WDropdown)1 WEmailField (com.github.bordertech.wcomponents.WEmailField)1 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)1 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)1 WMultiSelect (com.github.bordertech.wcomponents.WMultiSelect)1 WNumberField (com.github.bordertech.wcomponents.WNumberField)1 WPartialDateField (com.github.bordertech.wcomponents.WPartialDateField)1 WPasswordField (com.github.bordertech.wcomponents.WPasswordField)1 WPhoneNumberField (com.github.bordertech.wcomponents.WPhoneNumberField)1 WRadioButton (com.github.bordertech.wcomponents.WRadioButton)1 WRadioButtonSelect (com.github.bordertech.wcomponents.WRadioButtonSelect)1 WSingleSelect (com.github.bordertech.wcomponents.WSingleSelect)1