use of com.github.bordertech.wcomponents.WHeading in project wcomponents by BorderTech.
the class WConfirmationButtonExample method addAjaxExample.
/**
* This is used to reproduce a WComponents bug condition to make sure we do not re-create it once it is fixed.
* See https://github.com/BorderTech/wcomponents/issues/1266.
*/
private void addAjaxExample() {
add(new WHeading(HeadingLevel.H2, "Confirm as ajax trigger"));
final String before = "Before";
final String after = "After";
final WText ajaxContent = new WText("Before");
final WPanel target = new WPanel(WPanel.Type.BOX);
add(target);
target.add(ajaxContent);
WButton confirmWithAjax = new WButton("Replace");
confirmWithAjax.setMessage("Are you sure?");
confirmWithAjax.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
ajaxContent.setText(before.equals(ajaxContent.getText()) ? after : before);
}
});
add(confirmWithAjax);
add(new WAjaxControl(confirmWithAjax, target));
}
use of com.github.bordertech.wcomponents.WHeading in project wcomponents by BorderTech.
the class WDateFieldExample method addDateRangeExample.
/**
* Add date range example.
*/
private void addDateRangeExample() {
add(new WHeading(WHeading.MAJOR, "Example of a date range component"));
WFieldSet dateRange = new WFieldSet("Enter the expected arrival and departure dates.");
add(dateRange);
WPanel dateRangePanel = new WPanel();
dateRangePanel.setLayout(new FlowLayout(FlowLayout.LEFT, 6, 0));
dateRange.add(dateRangePanel);
final WDateField arrivalDate = new WDateField();
final WDateField departureDate = new WDateField();
// One could add some validation rules around this so that "arrival" was always earlier than or equal to "departure"
WLabel arrivalLabel = new WLabel("Arrival", arrivalDate);
arrivalLabel.setHint("dd MMM yyyy");
WLabel departureLabel = new WLabel("Departure", departureDate);
departureLabel.setHint("dd MMM yyyy");
dateRangePanel.add(arrivalLabel);
dateRangePanel.add(arrivalDate);
dateRangePanel.add(departureLabel);
dateRangePanel.add(departureDate);
// subordinate control to ensure that the departure date is only enabled if the arrival date is populated
WSubordinateControl control = new WSubordinateControl();
add(control);
Rule rule = new Rule(new Equal(arrivalDate, null));
control.addRule(rule);
rule.addActionOnTrue(new Disable(departureDate));
rule.addActionOnFalse(new Enable(departureDate));
control.addRule(rule);
}
use of com.github.bordertech.wcomponents.WHeading in project wcomponents by BorderTech.
the class WLabelExample method addNestedFieldExamples.
/**
* Examples showing WLabel with a nested input control WComponent.
* This is VERY dangerous as only a very few WComponents are valid for this scenario. If you go down this route: stop!!
* These are really here for framework testing, not as examples as to how to do things.
*/
private void addNestedFieldExamples() {
add(new WHeading(HeadingLevel.H2, "Label nesting which is technically OK"));
/* Just because it is OK to do this does not mean you should! So these "examples" have far fewer comments. */
WPanel errorLayoutPanel = new WPanel();
errorLayoutPanel.setLayout(new FlowLayout(FlowLayout.VERTICAL, Size.LARGE));
errorLayoutPanel.setMargin(new Margin(null, null, Size.XL, null));
add(errorLayoutPanel);
errorLayoutPanel.add(new ExplanatoryText("This example shows WLabels with a single nested simple form control WTextField." + " This is not a contravention of the HTML specification but you should not do it."));
WLabel outerLabel = new WLabel("Label with nested WTextField and not 'for' anything");
errorLayoutPanel.add(outerLabel);
outerLabel.add(new WTextField());
WTextField innerField = new WTextField();
outerLabel = new WLabel("Label 'for' nested WTextField", innerField);
errorLayoutPanel.add(outerLabel);
outerLabel.add(innerField);
}
use of com.github.bordertech.wcomponents.WHeading in project wcomponents by BorderTech.
the class WRadioButtonSelectExample method makeSimpleExample.
/**
* Make a simple editable example. The label for this example is used to get the example for use in the unit tests.
*/
private void makeSimpleExample() {
add(new WHeading(HeadingLevel.H3, "Simple WRadioButtonSelect"));
WPanel examplePanel = new WPanel();
examplePanel.setLayout(new FlowLayout(FlowLayout.VERTICAL, Size.MEDIUM));
add(examplePanel);
/**
* The radio button select.
*/
final WRadioButtonSelect rbSelect = new WRadioButtonSelect("australian_state");
final WTextField text = new WTextField();
text.setReadOnly(true);
text.setText(NO_SELECTION);
WButton update = new WButton("Update");
update.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
text.setText("The selected item is: " + rbSelect.getSelected());
}
});
// setting the default submit button improves usability. It can be set on a WPanel or the WRadioButtonSelect directly
examplePanel.setDefaultSubmitButton(update);
examplePanel.add(new WLabel("Select a state or territory", rbSelect));
examplePanel.add(rbSelect);
examplePanel.add(text);
examplePanel.add(update);
add(new WAjaxControl(update, text));
}
use of com.github.bordertech.wcomponents.WHeading in project wcomponents by BorderTech.
the class WRadioButtonSelectExample method addMandatorySelectExample.
/**
* adds a WRadioButtonSelect with setMandatory(true).
*/
private void addMandatorySelectExample() {
add(new WHeading(HeadingLevel.H3, "Mandatory WRadioButtonSelect"));
add(new ExplanatoryText("When a WRadioButtonSelect is mandatory it needs a visible labelling element, otherwise many users may not know that " + "the component requires an answer."));
final WRadioButtonSelect select = new WRadioButtonSelect("australian_state");
select.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
select.setMandatory(true);
add(new WLabel("Mandatory selection", select));
add(select);
add(new WHeading(HeadingLevel.H3, "Mandatory WRadioButtonSelect in a WFieldLayout"));
WRadioButtonSelect select2 = new WRadioButtonSelect("australian_state");
select2.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
select2.setMandatory(true);
final WFieldLayout layout = new WFieldLayout();
layout.setLabelWidth(25);
add(layout);
layout.addField("Required selection", select2).getLabel().setHint("Required");
select2 = new WRadioButtonSelect("australian_state");
select2.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
select2.setMandatory(true);
select2.setToolTip("Select a state");
layout.addField((WLabel) null, select2);
}
Aggregations