Search in sources :

Example 16 with ActionEvent

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

the class WRadioButtonSelectExample method addColumnSelectExample.

/**
 * adds a WRadioButtonSelect with LAYOUT_COLUMN in 3 columns.
 */
private void addColumnSelectExample() {
    add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect laid out in three columns"));
    add(new ExplanatoryText("Setting the layout to COLUMN will make the radio buttons be rendered in 'n' columns. The number of columns is" + " determined by the layoutColumnCount property."));
    final WRadioButtonSelect select = new WRadioButtonSelect("australian_state");
    select.setButtonLayout(WRadioButtonSelect.LAYOUT_COLUMNS);
    select.setButtonColumns(3);
    add(new WLabel("Three column selection", select));
    add(select);
    add(new WHeading(HeadingLevel.H3, "Options equal to columns"));
    String[] options = new String[] { "Dog", "Cat", "Bird" };
    final WRadioButtonSelect select2 = new WRadioButtonSelect(options);
    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() == null ? NO_SELECTION : "The selected animal is: " + select2.getSelected();
            text.setText(output);
        }
    });
    select2.setDefaultSubmitButton(update);
    add(new WLabel("Three columns and three options", select2));
    add(select2);
    add(update);
    add(text);
    add(new WAjaxControl(update, text));
}
Also used : ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) 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) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 17 with ActionEvent

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

the class WRadioButtonSelectExample method addInsideAFieldLayoutExample.

/**
 * When a WRadioButtonSelect is added to a WFieldLayout the legend is moved. The first CheckBoxSelect has a frame,
 * the second doesn't
 */
private void addInsideAFieldLayoutExample() {
    add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect inside a WFieldLayout"));
    add(new ExplanatoryText("When a WRadioButtonSelect is inside a WField its label is exposed in a way which appears and behaves like a regular HTML label." + " This allows WRadioButtonSelects to be used in a layout with simple form controls (such as WTextField) and produce a consistent" + " and predicatable interface.\n" + "The third example in this set uses a null label and a toolTip to hide the labelling element. This can lead to user confusion and" + " is not recommended."));
    // Note: the wrapper WPanel here is to work around a bug in validation. See https://github.com/BorderTech/wcomponents/issues/1370
    final WPanel wrapper = new WPanel();
    add(wrapper);
    final WMessages messages = new WMessages();
    wrapper.add(messages);
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(25);
    wrapper.add(layout);
    WButton resetThisBit = new WButton("Reset this bit");
    resetThisBit.setCancel(true);
    resetThisBit.setAjaxTarget(wrapper);
    resetThisBit.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            wrapper.reset();
        }
    });
    layout.addField(resetThisBit);
    String[] options = new String[] { "Dog", "Cat", "Bird", "Turtle" };
    WRadioButtonSelect select = new WRadioButtonSelect(options);
    layout.addField("Select an animal", select);
    String[] options2 = new String[] { "Parrot", "Galah", "Cockatoo", "Lyre" };
    select = new WRadioButtonSelect(options2);
    select.setMandatory(true);
    layout.addField("You must select a bird", select);
    select.setFrameless(true);
    // a tooltip can be used as a label stand-in even in a WField
    String[] options3 = new String[] { "Carrot", "Beet", "Brocolli", "Bacon - the perfect vegetable" };
    select = new WRadioButtonSelect(options3);
    // if you absolutely do not want a WLabel in a WField then it has to be added using null cast to a WLabel.
    layout.addField((WLabel) null, select);
    select.setToolTip("Veggies");
    WButton btnValidate = new WButton("validate");
    btnValidate.setAction(new ValidatingAction(messages.getValidationErrors(), layout) {

        @Override
        public void executeOnValid(final ActionEvent event) {
        // do nothing
        }
    });
    layout.addField(btnValidate);
    wrapper.add(new WAjaxControl(btnValidate, wrapper));
}
Also used : ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) WPanel(com.github.bordertech.wcomponents.WPanel) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) WMessages(com.github.bordertech.wcomponents.WMessages) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect)

Example 18 with ActionEvent

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

the class WTabAndCollapsibleExample method newVisibilityToggleForTab.

/**
 * Creates a button to toggle the visibility of a tab.
 *
 * @param idx the index of the tab.
 * @return a button which toggles the visibility of the tab.
 */
private WButton newVisibilityToggleForTab(final int idx) {
    WButton toggleButton = new WButton("Toggle visibility of tab " + (idx + 1));
    toggleButton.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            boolean tabVisible = tabset.isTabVisible(idx);
            tabset.setTabVisible(idx, !tabVisible);
        }
    });
    return toggleButton;
}
Also used : Action(com.github.bordertech.wcomponents.Action) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WButton(com.github.bordertech.wcomponents.WButton)

Example 19 with ActionEvent

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

the class SubordinateControlInterceptor_Test method testServiceRequestApplyControls.

@Test
public void testServiceRequestApplyControls() {
    // Create Target
    WButton target = new WButton();
    target.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            buttonClicked = true;
        }
    });
    // Create Control - Enable/Disable Button
    WCheckBox box = new WCheckBox();
    Rule rule = new Rule();
    rule.setCondition(new Equal(box, Boolean.TRUE));
    rule.addActionOnTrue(new Enable(target));
    rule.addActionOnFalse(new Disable(target));
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    // Create component tree
    WContainer root = new WContainer();
    root.add(control);
    root.add(box);
    root.add(target);
    // Setup Intercepter
    SubordinateControlInterceptor interceptor = new SubordinateControlInterceptor();
    interceptor.setBackingComponent(root);
    UIContext uic = createUIContext();
    uic.setUI(root);
    setActiveContext(uic);
    buttonClicked = false;
    // Test Service Request - Empty Request and no control registered, so the control should not be applied
    MockRequest request = new MockRequest();
    interceptor.serviceRequest(request);
    // Target should still be enabled (control not applied)
    Assert.assertFalse("After service request target should be enabled", target.isDisabled());
    // Button not clicked
    Assert.assertFalse("Button should not have been clicked", buttonClicked);
    // Test Service Request - Try to click button while it is disabled and should not be clicked
    target.setDisabled(true);
    request.setParameter(target.getId(), "x");
    interceptor.serviceRequest(request);
    // Target should still be disabled (control not applied, as still not registered)
    Assert.assertTrue("After service request target should be disabled", target.isDisabled());
    // Button not clicked
    Assert.assertFalse("Button should not have been clicked while disabled", buttonClicked);
    // Test Prepare Paint - Should register and apply the subordinate control
    target.setDisabled(false);
    request = new MockRequest();
    interceptor.preparePaint(request);
    // Target should be disabled (Disabled by control as box is not selected)
    Assert.assertTrue("After service request target should be disabled", target.isDisabled());
    // Test Service Request - Simulate button click as it was enabled on the client by the check box being selected.
    // As the controls have been registered from the Prepare Paint, they will be applied in the Service Request and
    // this will enable the button and allow it to be clicked.
    buttonClicked = false;
    request.setParameter(target.getId(), "x");
    setupCheckBoxRequest(box, request, true);
    interceptor.serviceRequest(request);
    // Target should be enabled (enabled by control as box is selected)
    Assert.assertFalse("After service request target should be enabled", target.isDisabled());
    // Button should have been clicked
    Assert.assertTrue("Button should have been clicked", buttonClicked);
// // Check Subordinate Controls have not been cleared from session
// Assert.assertNotNull("Registered Controls should not have been cleared on the session",
// request.getSessionAttribute(SubordinateControlHelper.SUBORDINATE_CONTROL_SESSION_KEY));
// 
// interceptor.preparePaint(request);
// 
// // Check Subordinate Controls have been cleared from session
// Assert.assertNull("Registered Controls should have been cleared on the session",
// request.getSessionAttribute(SubordinateControlHelper.SUBORDINATE_CONTROL_SESSION_KEY));
}
Also used : Action(com.github.bordertech.wcomponents.Action) WContainer(com.github.bordertech.wcomponents.WContainer) UIContext(com.github.bordertech.wcomponents.UIContext) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WButton(com.github.bordertech.wcomponents.WButton) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) Equal(com.github.bordertech.wcomponents.subordinate.Equal) Enable(com.github.bordertech.wcomponents.subordinate.Enable) Rule(com.github.bordertech.wcomponents.subordinate.Rule) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Disable(com.github.bordertech.wcomponents.subordinate.Disable) Test(org.junit.Test)

Example 20 with ActionEvent

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

the class WSuggestionsRenderer_Test method testDoPaintLookupTableOptions.

@Test
public void testDoPaintLookupTableOptions() throws IOException, SAXException, XpathException {
    WSuggestions field = new WSuggestions(TestLookupTable.CACHEABLE_DAY_OF_WEEK_TABLE);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getId(), "//ui:suggestions/@id", field);
    assertXpathNotExists("//ui:suggestions/@ajax", field);
    assertXpathNotExists("//ui:suggestions/@min", field);
    assertXpathNotExists("//ui:suggestions/suggestion", field);
    assertXpathEvaluatesTo(field.getListCacheKey(), "//ui:suggestions/@data", field);
    // If action set with a lookup table, AJAX flag should still be not set
    field.setRefreshAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
        // Do nothing
        }
    });
    assertSchemaMatch(field);
    assertXpathNotExists("//ui:suggestions/@ajax", field);
}
Also used : Action(com.github.bordertech.wcomponents.Action) WSuggestions(com.github.bordertech.wcomponents.WSuggestions) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) Test(org.junit.Test)

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