Search in sources :

Example 6 with ActionEvent

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

the class WCheckBoxSelectExample method addColumnSelectExample.

/**
 * adds a WCheckBoxSelect with LAYOUT_COLUMN in 2 columns.
 */
private void addColumnSelectExample() {
    add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect laid out in columns"));
    add(new ExplanatoryText("Setting the layout to COLUMN will make the check boxes be rendered in 'n' columns. The number of columns is" + " determined by the layoutColumnCount property."));
    final WCheckBoxSelect select = new WCheckBoxSelect("australian_state");
    select.setToolTip("Make a selection");
    select.setButtonLayout(WCheckBoxSelect.LAYOUT_COLUMNS);
    select.setButtonColumns(2);
    add(select);
    add(new WHeading(HeadingLevel.H3, "Options equal to columns"));
    String[] options = new String[] { "Dog", "Cat", "Bird" };
    final WCheckBoxSelect select2 = new WCheckBoxSelect(options);
    select2.setToolTip("Animals");
    select2.setButtonColumns(3);
    final WTextField text = new WTextField();
    text.setReadOnly(true);
    text.setText(NO_SELECTION);
    WButton update = new WButton("Select Animals");
    update.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            String output = select2.getSelected().isEmpty() ? NO_SELECTION : "The selected animals are: " + select2.getSelected();
            text.setText(output);
        }
    });
    select2.setDefaultSubmitButton(update);
    add(select2);
    add(update);
    add(text);
    add(new WAjaxControl(update, text));
}
Also used : Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect)

Example 7 with ActionEvent

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

the class WCheckBoxSelectExample method addExampleUsingStringArray.

/**
 * This example creates the WCheckBoxSelect from an array of Strings.
 */
private void addExampleUsingStringArray() {
    add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect created using a String array"));
    String[] options = new String[] { "Dog", "Cat", "Bird", "Turtle" };
    final WCheckBoxSelect select = new WCheckBoxSelect(options);
    select.setToolTip("Animals");
    select.setMandatory(true);
    final WTextField text = new WTextField();
    text.setReadOnly(true);
    text.setText(NO_SELECTION);
    WButton update = new WButton("Select Animals");
    update.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            String output = select.getSelected().isEmpty() ? NO_SELECTION : "The selected animals are: " + select.getSelected();
            text.setText(output);
        }
    });
    select.setDefaultSubmitButton(update);
    WLabel animalLabel = new WLabel("A selection is required", select);
    animalLabel.setHint("mandatory");
    add(animalLabel);
    add(select);
    add(update);
    add(text);
    add(new WAjaxControl(update, text));
}
Also used : Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 8 with ActionEvent

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

the class ValidatingAction_Test method testExecuteOnValid.

@Test
public void testExecuteOnValid() {
    // Test with no diagnostics
    Assert.assertEquals("Incorrect validation component returned.", componentToValidate, validatingAction.getComponentToValidate());
    validatingAction.execute(new ActionEvent("source", "command"));
    Assert.assertTrue("Should have called executeOnValid", validatingAction.executeOnValidExecuted);
    Assert.assertFalse("Should not have called executeOnError", validatingAction.executeOnErrorExecuted);
    // Test with a warning diagnostic - should still succeed
    componentToValidate.setErrorLevel(Diagnostic.WARNING);
    validatingAction.execute(new ActionEvent("source", "command"));
    Assert.assertTrue("Should have called executeOnValid", validatingAction.executeOnValidExecuted);
    Assert.assertFalse("Should not have called executeOnError", validatingAction.executeOnErrorExecuted);
}
Also used : ActionEvent(com.github.bordertech.wcomponents.ActionEvent) Test(org.junit.Test)

Example 9 with ActionEvent

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

the class ButtonOptionsExample method getButtonControls.

/**
 * build the button controls field set.
 *
 * @param errors the error pane from the page.
 * @return a field set for the controls.
 */
private WFieldSet getButtonControls(final WValidationErrors errors) {
    // Options Layout
    WFieldSet fieldSet = new WFieldSet("Button configuration");
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(30);
    layout.addField("Text", tfButtonLabel);
    layout.addField("AccessKey", tfAccesskey);
    layout.addField("Render as link", cbRenderAsLink);
    layout.addField("Disabled", cbDisabled);
    layout.addField("setImage ('/image/pencil.png')", cbSetImage);
    layout.addField("Image Position", ddImagePosition);
    // Apply Button
    WButton apply = new WButton("Apply");
    apply.setAction(new ValidatingAction(errors, fieldSet) {

        @Override
        public void executeOnValid(final ActionEvent event) {
            applySettings();
        }
    });
    fieldSet.add(layout);
    fieldSet.add(apply);
    return fieldSet;
}
Also used : WFieldSet(com.github.bordertech.wcomponents.WFieldSet) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WButton(com.github.bordertech.wcomponents.WButton)

Example 10 with ActionEvent

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

the class InputBeanBindingExample method addButtons.

/**
 * Setup the action buttons.
 */
private void addButtons() {
    // Validation Button
    WButton buttonValidate = new WButton("Validate and Update Bean");
    add(buttonValidate);
    buttonValidate.setAction(new ValidatingAction(messages.getValidationErrors(), layout) {

        @Override
        public void executeOnValid(final ActionEvent event) {
            WebUtilities.updateBeanValue(layout);
            messages.success("OK");
        }
    });
    // Update Bean
    WButton buttonUpdate = new WButton("Update Bean");
    add(buttonUpdate);
    buttonUpdate.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            WebUtilities.updateBeanValue(layout);
        }
    });
    // Reset Inputs
    WButton buttonReset = new WButton("Reset Inputs");
    add(buttonReset);
    buttonReset.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            layout.reset();
        }
    });
    // Reset Bean
    WButton buttonBean = new WButton("Reset Bean");
    add(buttonBean);
    buttonBean.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            InputBeanBindingExample.this.setBean(new MyDemoBean());
        }
    });
    add(new WButton("submit"));
}
Also used : Action(com.github.bordertech.wcomponents.Action) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WButton(com.github.bordertech.wcomponents.WButton)

Aggregations

ActionEvent (com.github.bordertech.wcomponents.ActionEvent)35 Action (com.github.bordertech.wcomponents.Action)27 WButton (com.github.bordertech.wcomponents.WButton)25 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)16 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)12 WHeading (com.github.bordertech.wcomponents.WHeading)12 ValidatingAction (com.github.bordertech.wcomponents.validation.ValidatingAction)10 WTextField (com.github.bordertech.wcomponents.WTextField)8 WPanel (com.github.bordertech.wcomponents.WPanel)7 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)6 Test (org.junit.Test)6 WContainer (com.github.bordertech.wcomponents.WContainer)5 Margin (com.github.bordertech.wcomponents.Margin)4 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)4 WLabel (com.github.bordertech.wcomponents.WLabel)4 WMenu (com.github.bordertech.wcomponents.WMenu)4 WMenuItem (com.github.bordertech.wcomponents.WMenuItem)4 WRadioButtonSelect (com.github.bordertech.wcomponents.WRadioButtonSelect)4 WText (com.github.bordertech.wcomponents.WText)4 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)4