use of com.github.bordertech.wcomponents.ActionEvent in project wcomponents by BorderTech.
the class WContentExample method addContentRow.
/**
* Adds components to the given container which demonstrate various ways of acessing the given content.
*
* @param contentDesc the description of the content, used to label the controls.
* @param contentAccess the content which will be displayed.
* @param target the container to add the UI controls to.
*/
private void addContentRow(final String contentDesc, final ContentAccess contentAccess, final MutableContainer target) {
// Demonstrate WButton + WContent, round trip
WButton button = new WButton(contentDesc);
final WContent buttonContent = new WContent();
button.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
buttonContent.setContentAccess(contentAccess);
buttonContent.display();
}
});
WContainer buttonCell = new WContainer();
buttonCell.add(buttonContent);
buttonCell.add(button);
target.add(buttonCell);
// Demonstrate WButton + WContent, using AJAX
WButton ajaxButton = new WButton(contentDesc);
final WContent ajaxContent = new WContent();
ajaxButton.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
ajaxContent.setContentAccess(contentAccess);
ajaxContent.display();
}
});
WContainer ajaxCell = new WContainer();
// The WContent must be wrapped in an AJAX targetable container
WPanel ajaxContentPanel = new WPanel();
ajaxContentPanel.add(ajaxContent);
ajaxCell.add(ajaxButton);
ajaxCell.add(ajaxContentPanel);
ajaxButton.setAjaxTarget(ajaxContentPanel);
target.add(ajaxCell);
// Demonstrate WContentLink - new window
WContentLink contentLinkNewWindow = new WContentLink(contentDesc) {
@Override
protected void preparePaintComponent(final Request request) {
super.preparePaintComponent(request);
setContentAccess(contentAccess);
}
};
target.add(contentLinkNewWindow);
// Demonstrate WContentLink - prompt to save
WContentLink contentLinkPromptToSave = new WContentLink(contentDesc) {
@Override
protected void preparePaintComponent(final Request request) {
super.preparePaintComponent(request);
setContentAccess(contentAccess);
}
};
contentLinkPromptToSave.setDisplayMode(DisplayMode.PROMPT_TO_SAVE);
target.add(contentLinkPromptToSave);
// Demonstrate WContentLink - inline
WContentLink contentLinkInline = new WContentLink(contentDesc) {
@Override
protected void preparePaintComponent(final Request request) {
super.preparePaintComponent(request);
setContentAccess(contentAccess);
}
};
contentLinkInline.setDisplayMode(DisplayMode.DISPLAY_INLINE);
target.add(contentLinkInline);
// Demonstrate targeting of content via a URL
WMenu menu = new WMenu(WMenu.MenuType.FLYOUT);
final WContent menuContent = new WContent();
menuContent.setDisplayMode(DisplayMode.PROMPT_TO_SAVE);
WMenuItem menuItem = new WMenuItem(contentDesc) {
@Override
protected void preparePaintComponent(final Request request) {
super.preparePaintComponent(request);
menuContent.setContentAccess(contentAccess);
setUrl(menuContent.getUrl());
}
};
menu.add(menuItem);
WContainer menuCell = new WContainer();
menuCell.add(menuContent);
menuCell.add(menu);
target.add(menuCell);
}
use of com.github.bordertech.wcomponents.ActionEvent in project wcomponents by BorderTech.
the class WDropdownOptionsExample method applySettings.
/**
* Apply the settings from the control table to the drop down.
*/
private void applySettings() {
container.reset();
infoPanel.reset();
// create the list of options.
List<String> options = new ArrayList<>(Arrays.asList(OPTIONS_ARRAY));
if (cbNullOption.isSelected()) {
options.add(0, "");
}
// create the dropdown.
final WDropdown dropdown = new WDropdown(options);
// set the dropdown type.
dropdown.setType((DropdownType) rbsDDType.getSelected());
// set the selected option if applicable.
String selected = (String) rgDefaultOption.getSelected();
if (selected != null && !NONE.equals(selected)) {
dropdown.setSelected(selected);
}
// set the width.
if (nfWidth.getValue() != null) {
dropdown.setOptionWidth(nfWidth.getValue().intValue());
}
// set the tool tip.
if (tfToolTip.getText() != null && tfToolTip.getText().length() > 0) {
dropdown.setToolTip(tfToolTip.getText());
}
// set misc options.
dropdown.setVisible(cbVisible.isSelected());
dropdown.setDisabled(cbDisabled.isSelected());
// add the action for action on change, ajax and subordinate.
if (cbActionOnChange.isSelected() || cbAjax.isSelected() || cbSubmitOnChange.isSelected()) {
final WStyledText info = new WStyledText();
info.setWhitespaceMode(WhitespaceMode.PRESERVE);
infoPanel.add(info);
dropdown.setActionOnChange(new Action() {
@Override
public void execute(final ActionEvent event) {
String selectedOption = (String) dropdown.getSelected();
info.setText(selectedOption);
}
});
}
// this has to be below the set action on change so it is
// not over written.
dropdown.setSubmitOnChange(cbSubmitOnChange.isSelected());
// add the ajax target.
if (cbAjax.isSelected()) {
WAjaxControl update = new WAjaxControl(dropdown);
update.addTarget(infoPanel);
container.add(update);
}
// add the subordinate stuff.
if (rbsDDType.getValue() == WDropdown.DropdownType.COMBO) {
// This is to work around a WComponent Subordinate logic flaw.
cbSubordinate.setSelected(false);
}
if (cbSubordinate.isSelected()) {
WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
container.add(group);
WSubordinateControl control = new WSubordinateControl();
container.add(control);
for (String option : OPTIONS_ARRAY) {
buildSubordinatePanel(dropdown, option, group, control);
}
// add a rule for none selected.
Rule rule = new Rule();
control.addRule(rule);
rule.setCondition(new Equal(dropdown, ""));
rule.addActionOnTrue(new Hide(group));
}
WFieldLayout flay = new WFieldLayout();
flay.setLabelWidth(25);
container.add(flay);
flay.addField("Configured dropdown", dropdown);
flay.addField((WLabel) null, new WButton("Submit"));
}
use of com.github.bordertech.wcomponents.ActionEvent in project wcomponents by BorderTech.
the class WDropdownOptionsExample method getDropDownControls.
/**
* build the drop down controls.
*
* @return a field set containing the dropdown controls.
*/
private WFieldSet getDropDownControls() {
WFieldSet fieldSet = new WFieldSet("Drop down configuration");
WFieldLayout layout = new WFieldLayout();
layout.setLabelWidth(25);
fieldSet.add(layout);
rbsDDType.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
rbsDDType.setSelected(WDropdown.DropdownType.NATIVE);
rbsDDType.setFrameless(true);
layout.addField("Dropdown Type", rbsDDType);
nfWidth.setMinValue(0);
nfWidth.setDecimalPlaces(0);
layout.addField("Width", nfWidth);
layout.addField("ToolTip", tfToolTip);
layout.addField("Include null option", cbNullOption);
rgDefaultOption.setButtonLayout(WRadioButtonSelect.LAYOUT_COLUMNS);
rgDefaultOption.setButtonColumns(2);
rgDefaultOption.setSelected(NONE);
rgDefaultOption.setFrameless(true);
layout.addField("Default Option", rgDefaultOption);
layout.addField("Action on change", cbActionOnChange);
layout.addField("Ajax", cbAjax);
WField subField = layout.addField("Subordinate", cbSubordinate);
// .getLabel().setHint("Does not work with Dropdown Type COMBO");
layout.addField("Submit on change", cbSubmitOnChange);
layout.addField("Visible", cbVisible);
layout.addField("Disabled", cbDisabled);
// Apply Button
WButton apply = new WButton("Apply");
fieldSet.add(apply);
WSubordinateControl subSubControl = new WSubordinateControl();
Rule rule = new Rule();
subSubControl.addRule(rule);
rule.setCondition(new Equal(rbsDDType, WDropdown.DropdownType.COMBO));
rule.addActionOnTrue(new Disable(subField));
rule.addActionOnFalse(new Enable(subField));
fieldSet.add(subSubControl);
apply.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
applySettings();
}
});
return fieldSet;
}
use of com.github.bordertech.wcomponents.ActionEvent in project wcomponents by BorderTech.
the class WListOptionsExample method getListControls.
/**
* build the list controls field set.
*
* @return a field set for the controls.
*/
private WFieldSet getListControls() {
// Options Layout
WFieldSet fieldSet = new WFieldSet("List configuration");
WFieldLayout layout = new WFieldLayout();
// options.
layout.addField("Type", ddType);
layout.addField("Separator", ddSeparator);
layout.addField("Render fields", cgBeanFields);
layout.addField("Render Border", cbRenderBorder);
layout.addField("Render using field layout", cbRenderUsingFieldLayout);
layout.addField("Visible", cbVisible);
// Apply Button
WButton apply = new WButton("Apply");
apply.setAction(new com.github.bordertech.wcomponents.Action() {
@Override
public void execute(final ActionEvent event) {
applySettings();
}
});
fieldSet.add(layout);
fieldSet.add(apply);
return fieldSet;
}
use of com.github.bordertech.wcomponents.ActionEvent in project wcomponents by BorderTech.
the class WRadioButtonSelectExample method addAntiPatternExamples.
/**
* Examples of what not to do when using WRadioButtonSelect.
*/
private void addAntiPatternExamples() {
add(new WHeading(HeadingLevel.H2, "WRadioButtonSelect anti-pattern examples"));
add(new WMessageBox(WMessageBox.WARN, "These examples are purposely bad and should not be used as samples of how to use WComponents but samples of how NOT to use them."));
// Even compound controls need a label
add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect with no labelling component"));
add(new ExplanatoryText("All input controls, even those which are complex and do not output labellable HTML elements, must be associated with" + " a WLabel or have a toolTip."));
add(new WRadioButtonSelect("australian_state"));
// submitOnChange is a WRadioButtonSelect no no!!
add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect with submitOnChange"));
add(new ExplanatoryText("SubmitOnChange is bad in most cases but terrible with radio buttons because there is no way to change the selection" + " between non-contiguous options using the keyboard without having multiple page submits.\nIn the following example try to change " + "the selection from 'Outside Australia' to 'Queensland' using only your keyboard. To make this easier the WRadioButtonSelect has" + " an access key of 'M'"));
final WRadioButtonSelect select = new SelectWithSelection("australian_state");
final WTextField selected = new WTextField();
selected.setReadOnly(true);
select.setActionOnChange(new Action() {
@Override
public void execute(final ActionEvent event) {
// does not matter what this is
selected.setText(select.getValueAsString());
}
});
select.setSubmitOnChange(true);
// now put them all into the UI
WFieldLayout layout = new WFieldLayout();
add(layout);
WField selectField = layout.addField("Make a selection to update the page", select);
selectField.getLabel().setAccessKey('M');
layout.addField("Selected option", selected);
// Too many options anti-pattern
add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect with too many options"));
add(new ExplanatoryText("Don't use a WRadioButtonSelect if you have more than a handful of options. A good rule of thumb is fewer than 10."));
// use the country code list at your peril!!
WRadioButtonSelect rbsTooBig = new WRadioButtonSelect(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" });
rbsTooBig.setButtonLayout(WRadioButtonSelect.LAYOUT_COLUMNS);
rbsTooBig.setButtonColumns(6);
rbsTooBig.setFrameless(true);
rbsTooBig.setToolTip("Select your country of birth");
add(rbsTooBig);
// Don't use a radioButtonSelect if the user can make no selection unless you provide a null option
add(new WHeading(HeadingLevel.H3, "Optional WRadioButtonSelect with no null option"));
add(new ExplanatoryText("Once a radio button group has a selection it cannot be removed. If a WRadioButtonSelect is not mandatory it should" + " include a 'none of these' type null option.\nWhat happens if you make a selection in the following but then change your mind" + " (even ugly chairs are not your scene). To concentrate the mind I have made a selection for you."));
WRadioButtonSelect noneOfTheAboveSelect = new SelectWithSelection(new String[] { "spike", "broken glass", "ugly chair", "wet paint" });
noneOfTheAboveSelect.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
noneOfTheAboveSelect.setFrameless(true);
layout = new WFieldLayout();
add(layout);
layout.addField("Where would you like to sit?", noneOfTheAboveSelect);
// don't use a yes/no group of radio buttons for something which should be a checkbox
add(new WHeading(HeadingLevel.H3, "Yes/No options"));
add(new ExplanatoryText("If the only answers to your question is one of yes or no then you do not have a group of radio buttons, you have a check box.\n" + "In the following example the WRadioButtonSelect should be a WCheckBox and the label be 'I agree to the terms and conditions'"));
layout = new WFieldLayout();
add(layout);
WRadioButtonSelect yesNoSelect = new WRadioButtonSelect(new String[] { "yes", "no" });
yesNoSelect.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
yesNoSelect.setFrameless(true);
layout.addField("Do you agree to the terms and conditions?", yesNoSelect);
add(new WHeading(HeadingLevel.H3, "No options"));
add(new ExplanatoryText("An interactive WRadioButtonSelect with no options is rather pointless."));
layout = new WFieldLayout();
add(layout);
layout.addField("Select from no options", new WRadioButtonSelect());
}
Aggregations