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);
}
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);
}
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);
}
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);
}
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");
}
Aggregations