Search in sources :

Example 21 with ActionEvent

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

the class WSuggestionsRenderer_Test method testDoPaintAjaxOptions.

@Test
public void testDoPaintAjaxOptions() throws IOException, SAXException, XpathException {
    List<String> options = Arrays.asList("A", "B", "C");
    WSuggestions field = new WSuggestions(options);
    // Set action for AJAX refresh
    field.setRefreshAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
        // Do nothing
        }
    });
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getId(), "//ui:suggestions/@id", field);
    assertXpathNotExists("//ui:suggestions/@min", field);
    assertXpathNotExists("//ui:suggestions/@data", field);
    // AJAX flag should be true
    assertXpathEvaluatesTo("true", "//ui:suggestions/@ajax", field);
    // Suggestions should only be rendered when refreshed via AJAX
    assertXpathNotExists("//ui:suggestions/ui:suggestion", field);
    // Setup suggestions as the current AJAX trigger
    UIContext uic = createUIContext();
    uic.setUI(new DefaultWComponent());
    setActiveContext(uic);
    try {
        AjaxOperation operation = new AjaxOperation(field.getId(), field.getId());
        AjaxHelper.setCurrentOperationDetails(operation, null);
        assertSchemaMatch(field);
        assertXpathExists("//ui:suggestions/ui:suggestion", field);
        assertXpathEvaluatesTo(options.get(0), "//ui:suggestions/ui:suggestion[1]/@value", field);
        assertXpathEvaluatesTo(options.get(1), "//ui:suggestions/ui:suggestion[2]/@value", field);
        assertXpathEvaluatesTo(options.get(2), "//ui:suggestions/ui:suggestion[3]/@value", field);
    } finally {
        AjaxHelper.clearCurrentOperationDetails();
    }
}
Also used : Action(com.github.bordertech.wcomponents.Action) AjaxOperation(com.github.bordertech.wcomponents.AjaxOperation) UIContext(com.github.bordertech.wcomponents.UIContext) WSuggestions(com.github.bordertech.wcomponents.WSuggestions) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Example 22 with ActionEvent

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

the class WButtonRenderer_Test method testAllOptions.

@Test
public void testAllOptions() throws IOException, SAXException, XpathException {
    WButton button = new WButton("All");
    button.setDisabled(true);
    setFlag(button, ComponentModel.HIDE_FLAG, true);
    button.setToolTip("Title");
    button.setAccessKey('T');
    button.setImageUrl("http://localhost/image.png");
    button.setImagePosition(ImagePosition.EAST);
    button.setRenderAsLink(true);
    button.setAjaxTarget(new WTextField());
    button.setPopupTrigger(true);
    setActiveContext(createUIContext());
    WPanel validationComponent = new WPanel();
    button.setAction(new ValidatingAction(new WValidationErrors(), validationComponent) {

        @Override
        public void executeOnValid(final ActionEvent event) {
        // Do nothing
        }
    });
    WContainer root = new WContainer();
    root.add(button);
    root.add(validationComponent);
    assertXpathExists("//html:button[@id]", button);
    assertXpathExists("//html:button[contains(@class, 'wc-linkbutton')]", button);
    assertXpathEvaluatesTo(button.getText(), "//html:button", button);
    assertXpathEvaluatesTo("disabled", "//html:button/@disabled", button);
    assertXpathEvaluatesTo("hidden", "//html:button/@hidden", button);
    assertXpathEvaluatesTo(button.getToolTip(), "//html:button/@title", button);
    assertXpathUrlEvaluatesTo(button.getImageUrl(), "//html:button//html:img/@src", button);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imge')]", button);
    assertXpathEvaluatesTo(button.getAccessKeyAsString(), "//html:button/@accesskey", button);
    assertXpathEvaluatesTo("true", "//html:button/@aria-haspopup", button);
    assertXpathEvaluatesTo(validationComponent.getId(), "//html:button/@data-wc-validate", button);
    assertXpathEvaluatesTo(button.getId(), "//ui:ajaxtrigger/@triggerId", button);
    button.setImagePosition(ImagePosition.NORTH);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgn')]", button);
    button.setImagePosition(ImagePosition.SOUTH);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgs')]", button);
    button.setImagePosition(ImagePosition.WEST);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgw')]", button);
    button.setClientCommandOnly(true);
    assertXpathEvaluatesTo("button", "//html:button/@type", button);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) WValidationErrors(com.github.bordertech.wcomponents.validation.WValidationErrors) WButton(com.github.bordertech.wcomponents.WButton) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 23 with ActionEvent

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

the class ValidatingAction_Test method testExecuteOnError.

@Test
public void testExecuteOnError() {
    componentToValidate.setErrorLevel(Diagnostic.ERROR);
    Assert.assertEquals("Incorrect validation component returned.", componentToValidate, validatingAction.getComponentToValidate());
    validatingAction.execute(new ActionEvent("source", "command"));
    Assert.assertTrue("Should have called executeOnError", validatingAction.executeOnErrorExecuted);
    Assert.assertFalse("Should not have called executeOnValid", validatingAction.executeOnValidExecuted);
}
Also used : ActionEvent(com.github.bordertech.wcomponents.ActionEvent) Test(org.junit.Test)

Example 24 with ActionEvent

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

the class LinkOptionsExample 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("Link configuration");
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(30);
    layout.addField("Link text", tfLinkLabel);
    layout.addField("Link address", tfUrlField);
    layout.addField("Link AccessKey", tfAccesskey).getLabel().setHint("A single upper case letter or digit.");
    layout.addField("Render as button", cbRenderAsButton);
    layout.addField("Disabled", cbDisabled);
    layout.addField("Open in a new window", cbOpenNew);
    layout.addField("setImage ('/image/attachment.png')", cbSetImage);
    layout.addField("Image Position", ddImagePosition);
    layout.setMargin(new com.github.bordertech.wcomponents.Margin(0, 0, 6, 0));
    // 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 25 with ActionEvent

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

the class SimpleTabs method addTab.

/**
 * Adds a tab.
 *
 * @param card the tab content.
 * @param name the tab name.
 */
public void addTab(final WComponent card, final String name) {
    WContainer titledCard = new WContainer();
    WText title = new WText("<b>[" + name + "]:</b><br/>");
    title.setEncodeText(false);
    titledCard.add(title);
    titledCard.add(card);
    deck.add(titledCard);
    final TabButton button = new TabButton(name, titledCard);
    button.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            deck.makeVisible(button.getAssociatedCard());
        }
    });
    btnPanel.add(button);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) Action(com.github.bordertech.wcomponents.Action) WText(com.github.bordertech.wcomponents.WText) ActionEvent(com.github.bordertech.wcomponents.ActionEvent)

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