Search in sources :

Example 26 with ActionEvent

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

the class WRadioButtonTriggerActionExample method setup.

/**
 * Add controls to the UI.
 */
private void setup() {
    setLayout(new FlowLayout(FlowLayout.VERTICAL));
    WFieldSet fset = new WFieldSet("Select a meal");
    add(fset);
    fset.setMargin(new Margin(null, null, Size.LARGE, null));
    WFieldLayout flay = new WFieldLayout(WFieldLayout.LAYOUT_STACKED);
    fset.add(flay);
    flay.setLabelWidth(0);
    flay.addField("Breakfast", rb1);
    flay.addField("Lunch", rb2);
    flay.addField("Dinner", rb3);
    /*
		 * NOTE: you should never use submitOnChange with a WRadioButton
		 */
    fset.add(new WAjaxControl(mealSelections, textBox));
    mealSelections.setActionOnChange(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            String selection = null;
            if (rb1.isSelected()) {
                selection = "Breakfast selected";
            }
            if (rb2.isSelected()) {
                selection = "Lunch selected";
            }
            if (rb3.isSelected()) {
                selection = "Dinner selected";
            }
            text1.setText(selection + " : " + (new Date()).toString());
        }
    });
    textBox.add(text1);
    add(textBox);
    add(mealSelections);
}
Also used : WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) Action(com.github.bordertech.wcomponents.Action) FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) WFieldSet(com.github.bordertech.wcomponents.WFieldSet) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) Date(java.util.Date) Margin(com.github.bordertech.wcomponents.Margin)

Example 27 with ActionEvent

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

the class GridLayoutOptionsExample method getLayoutControls.

/**
 * build the list controls field set.
 *
 * @param errors the error box to be linked to the apply button.
 * @return a field set for the controls.
 */
private WFieldSet getLayoutControls(final WValidationErrors errors) {
    // Options Layout
    WFieldSet fieldSet = new WFieldSet("List configuration");
    WFieldLayout layout = new ControlFieldLayout();
    fieldSet.add(layout);
    // options.
    columnCount.setDecimalPlaces(0);
    columnCount.setMinValue(0);
    columnCount.setNumber(DEFAULT_COLUMN_COUNT);
    columnCount.setMandatory(true);
    layout.addField("Number of Columns", columnCount);
    rowCount.setDecimalPlaces(0);
    rowCount.setMinValue(0);
    rowCount.setNumber(DEFAULT_ROW_COUNT);
    rowCount.setMandatory(true);
    layout.addField("Number of Rows", rowCount);
    hGap.setDecimalPlaces(0);
    hGap.setMinValue(0);
    hGap.setNumber(0);
    hGap.setMandatory(true);
    layout.addField("Horizontal Gap", hGap);
    vGap.setDecimalPlaces(0);
    vGap.setMinValue(0);
    vGap.setNumber(0);
    vGap.setMandatory(true);
    layout.addField("Vertical Gap", vGap);
    boxCount.setDecimalPlaces(0);
    boxCount.setMinValue(0);
    boxCount.setNumber(DEFAULT_BOX_COUNT);
    boxCount.setMandatory(true);
    layout.addField("Number of Boxes", boxCount);
    layout.addField("Visible", cbVisible);
    layout.addField("Allow responsive design", cbResponsive);
    // Apply Button
    WButton apply = new WButton("Apply");
    apply.setAction(new ValidatingAction(errors, this) {

        @Override
        public void executeOnValid(final ActionEvent event) {
            applySettings();
        }
    });
    layout.addField(apply);
    fieldSet.add(new WAjaxControl(apply, container));
    fieldSet.setMargin(new Margin(null, null, Size.LARGE, null));
    return fieldSet;
}
Also used : WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) 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) Margin(com.github.bordertech.wcomponents.Margin)

Example 28 with ActionEvent

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

the class ColumnMenuExample method buildColumnMenu.

/**
 * Builds up a column menu for inclusion in the example.
 *
 * @param selectedMenuText the WText to display the selected menu.
 * @return a column menu for the example.
 */
private WMenu buildColumnMenu(final WText selectedMenuText) {
    WMenu menu = new WMenu(WMenu.MenuType.COLUMN);
    menu.setSelectMode(SelectMode.SINGLE);
    menu.setRows(8);
    StringTreeNode root = getOrgHierarchyTree();
    mapColumnHierarchy(menu, root, selectedMenuText);
    // Demonstrate different menu modes
    getSubMenuByText("Australia", menu).setAccessKey('A');
    getSubMenuByText("NSW", menu).setMode(MenuMode.CLIENT);
    getSubMenuByText("Branch 1", menu).setMode(MenuMode.DYNAMIC);
    getSubMenuByText("VIC", menu).setMode(MenuMode.LAZY);
    WMenuItem itemWithIcon = new WMenuItem("Help");
    itemWithIcon.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
        // do something
        }
    });
    itemWithIcon.setHtmlClass(HtmlClassProperties.ICON_HELP_BEFORE);
    menu.add(itemWithIcon);
    return menu;
}
Also used : Action(com.github.bordertech.wcomponents.Action) WMenuItem(com.github.bordertech.wcomponents.WMenuItem) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WMenu(com.github.bordertech.wcomponents.WMenu)

Example 29 with ActionEvent

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

the class TreeMenuExample method buildTreeMenuWithDecoratedLabel.

/**
 * Tree menu containing image in the items. This example demonstrates creating {@link WSubMenu} and
 * {@link WMenuItem} components with {@link WDecoratedLabel}.
 *
 * @return menu with a decorated label
 */
private WMenu buildTreeMenuWithDecoratedLabel() {
    WMenu menu = new WMenu(WMenu.MenuType.TREE);
    WDecoratedLabel dLabel = new WDecoratedLabel(null, new WText("Settings Menu"), new WImage("/image/settings.png", "settings"));
    WSubMenu settings = new WSubMenu(dLabel);
    settings.setMode(WSubMenu.MenuMode.LAZY);
    settings.setAccessKey('S');
    menu.add(settings);
    settings.add(new WMenuItem(new WDecoratedLabel(null, new WText("Account Settings"), new WImage("/image/user-properties.png", "user properties"))));
    settings.add(new WMenuItem(new WDecoratedLabel(null, new WText("Personal Details"), new WImage("/image/user.png", "user"))));
    WSubMenu addressSub = new WSubMenu(new WDecoratedLabel(null, new WText("Address Details"), new WImage("/image/address-book-open.png", "address book")));
    addressSub.setMode(WSubMenu.MenuMode.LAZY);
    settings.add(addressSub);
    addressSub.add(new WMenuItem(new WDecoratedLabel(null, new WText("Home Address"), new WImage("/image/home.png", "home"))));
    addressSub.add(new WMenuItem(new WDecoratedLabel(null, new WText("Work Address"), new WImage("/image/wrench.png", "work"))));
    addressSub.add(new WMenuItem(new WDecoratedLabel(null, new WText("Postal Address"), new WImage("/image/mail-post.png", "postal"))));
    WMenuItem itemWithIcon = new WMenuItem("Help");
    itemWithIcon.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
        // do something
        }
    });
    itemWithIcon.setHtmlClass(HtmlClassProperties.ICON_HELP_BEFORE);
    menu.add(itemWithIcon);
    return menu;
}
Also used : Action(com.github.bordertech.wcomponents.Action) WSubMenu(com.github.bordertech.wcomponents.WSubMenu) WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WText(com.github.bordertech.wcomponents.WText) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WMenu(com.github.bordertech.wcomponents.WMenu) WImage(com.github.bordertech.wcomponents.WImage) WDecoratedLabel(com.github.bordertech.wcomponents.WDecoratedLabel)

Example 30 with ActionEvent

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

the class ExampleSection method buildUI.

/**
 * Add the controls to the section in the right order.
 */
private void buildUI() {
    add(messages);
    add(tabset);
    // add(new AccessibilityWarningContainer());
    container.add(new WText("Select an example from the menu"));
    // Set a static ID on container and it becomes a de-facto naming context.
    container.setIdName("eg");
    tabset.addTab(container, "(no selection)", WTabSet.TAB_MODE_CLIENT);
    WImage srcImage = new WImage(new ImageResource("/image/text-x-source.png", "View Source"));
    srcImage.setCacheKey("srcTabImage");
    tabset.addTab(source, new WDecoratedLabel(srcImage), WTabSet.TAB_MODE_LAZY).setToolTip("View Source");
    // The refresh current view button.
    WButton refreshButton = new WButton("\u200b");
    refreshButton.setToolTip("Refresh");
    refreshButton.setHtmlClass(HtmlIconUtil.getIconClasses("fa-refresh"));
    // refreshButton.setImage("/image/refresh-w.png");
    refreshButton.setRenderAsLink(true);
    refreshButton.setAction(new ValidatingAction(messages.getValidationErrors(), refreshButton) {

        @Override
        public void executeOnValid(final ActionEvent event) {
        // Do Nothing
        }
    });
    // The reset example button.
    final WButton resetButton = new WButton("\u200b");
    resetButton.setToolTip("Reset");
    resetButton.setHtmlClass(HtmlIconUtil.getIconClasses("fa-times-circle"));
    // resetButton.setImage("/image/cancel-w.png");
    resetButton.setRenderAsLink(true);
    resetButton.setAction(new ValidatingAction(messages.getValidationErrors(), resetButton) {

        @Override
        public void executeOnValid(final ActionEvent event) {
            resetExample();
        }
    });
    addToTail(refreshButton);
    addToTail(new WText("\u2002"));
    addToTail(resetButton);
}
Also used : ImageResource(com.github.bordertech.wcomponents.ImageResource) WText(com.github.bordertech.wcomponents.WText) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WImage(com.github.bordertech.wcomponents.WImage) WButton(com.github.bordertech.wcomponents.WButton) WDecoratedLabel(com.github.bordertech.wcomponents.WDecoratedLabel)

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