Search in sources :

Example 21 with WAjaxControl

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

the class FilterableTableExample method buildFilterSubMenu.

/**
 * Creates and populates the sub-menu for each filter menu.
 *
 * @param menu The WMenu we are currently populating.
 * @param column The column index of the table column the menu is in. This is used to get the data off the table's
 * Bean to put text content into the menu's items.
 */
private void buildFilterSubMenu(final WMenu menu, final int column) {
    List<?> beanList = getFilterableTableModel().getFullBeanList();
    int rows = (beanList == null) ? 0 : beanList.size();
    if (rows == 0) {
        return;
    }
    final List<String> found = new ArrayList<>();
    final WDecoratedLabel filterSubMenuLabel = new WDecoratedLabel(new WText("\u200b"));
    filterSubMenuLabel.setToolTip("Filter this column");
    filterSubMenuLabel.setHtmlClass(HtmlIconUtil.getIconClasses("fa-filter"));
    final WSubMenu submenu = new WSubMenu(filterSubMenuLabel);
    submenu.setSelectionMode(SELECTION_MODE);
    menu.add(submenu);
    WMenuItem item = new WMenuItem(CLEAR_ALL, new ClearFilterAction());
    submenu.add(item);
    item.setActionObject(item);
    item.setSelectability(false);
    add(new WAjaxControl(item, table));
    Object cellObject;
    String cellContent, cellContentMatch;
    Object bean;
    if (beanList != null) {
        for (int i = 0; i < rows; ++i) {
            bean = beanList.get(i);
            if (bean != null) {
                cellObject = getFilterableTableModel().getBeanPropertyValueFullList(BEAN_PROPERTIES[column], bean);
                if (cellObject != null) {
                    if (cellObject instanceof Date) {
                        cellContent = new SimpleDateFormat(DATE_FORMAT).format((Date) cellObject);
                    } else {
                        cellContent = cellObject.toString();
                    }
                    if ("".equals(cellContent)) {
                        cellContent = EMPTY;
                    }
                    cellContentMatch = (getFilterableTableModel().isCaseInsensitiveMatch()) ? cellContent.toLowerCase() : cellContent;
                    if (found.indexOf(cellContentMatch) == -1) {
                        item = new WMenuItem(cellContent, new FilterAction());
                        submenu.add(item);
                        add(new WAjaxControl(item, table));
                        found.add(cellContentMatch);
                    }
                }
            }
        }
    }
}
Also used : WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ArrayList(java.util.ArrayList) Date(java.util.Date) WSubMenu(com.github.bordertech.wcomponents.WSubMenu) WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WText(com.github.bordertech.wcomponents.WText) SimpleDateFormat(java.text.SimpleDateFormat) WDecoratedLabel(com.github.bordertech.wcomponents.WDecoratedLabel)

Example 22 with WAjaxControl

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

the class WCheckBoxSelectExample method addExampleUsingLookupTable.

/**
 * This example creates the WCheckBoxSelect using an a look up table. All other optional properties are in their default state.
 * <p>Note for Framework devs: the unit tests for this Example are used to test the Selenium WebElement extension and this example is expected
 * to be: the first WCheckBoxSelect in the example; and to be interactive; and to have the 9 options of the "australian_state" lookup table.
 */
private void addExampleUsingLookupTable() {
    add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect created using a lookup table"));
    final WCheckBoxSelect select = new WCheckBoxSelect("australian_state");
    final WTextField text = new WTextField();
    text.setReadOnly(true);
    text.setText(NO_SELECTION);
    WButton update = new WButton("Select");
    update.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            String output = select.getSelected().isEmpty() ? NO_SELECTION : "The selected states are: " + select.getSelected();
            text.setText(output);
        }
    });
    select.setDefaultSubmitButton(update);
    add(new WLabel("Select a state or territory", select));
    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 23 with WAjaxControl

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

the class WConfirmationButtonExample method addAjaxExample.

/**
 * This is used to reproduce a WComponents bug condition to make sure we do not re-create it once it is fixed.
 * See https://github.com/BorderTech/wcomponents/issues/1266.
 */
private void addAjaxExample() {
    add(new WHeading(HeadingLevel.H2, "Confirm as ajax trigger"));
    final String before = "Before";
    final String after = "After";
    final WText ajaxContent = new WText("Before");
    final WPanel target = new WPanel(WPanel.Type.BOX);
    add(target);
    target.add(ajaxContent);
    WButton confirmWithAjax = new WButton("Replace");
    confirmWithAjax.setMessage("Are you sure?");
    confirmWithAjax.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            ajaxContent.setText(before.equals(ajaxContent.getText()) ? after : before);
        }
    });
    add(confirmWithAjax);
    add(new WAjaxControl(confirmWithAjax, target));
}
Also used : Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) WText(com.github.bordertech.wcomponents.WText) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading)

Example 24 with WAjaxControl

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

the class WPanelTypeExample method buildUI.

/**
 * Add the components in the required order.
 */
private void buildUI() {
    buildTargetPanel();
    buildConfigOptions();
    add(new WHorizontalRule());
    add(panel);
    add(new WHorizontalRule());
    // We need this reflection of the selected menu item just so we can reuse the menu from the
    // MenuBarExample. It serves no purpose in this example so I am going to hide it.
    WPanel hiddenPanel = new WPanel() {

        @Override
        public boolean isHidden() {
            return true;
        }
    };
    hiddenPanel.add(selectedMenuText);
    add(hiddenPanel);
    add(new WAjaxControl(applyConfigButton, panel));
    buildSubordinates();
}
Also used : WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) WPanel(com.github.bordertech.wcomponents.WPanel) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule)

Example 25 with WAjaxControl

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

the class WRadioButtonSelectExample method makeSimpleExample.

/**
 * Make a simple editable example. The label for this example is used to get the example for use in the unit tests.
 */
private void makeSimpleExample() {
    add(new WHeading(HeadingLevel.H3, "Simple WRadioButtonSelect"));
    WPanel examplePanel = new WPanel();
    examplePanel.setLayout(new FlowLayout(FlowLayout.VERTICAL, Size.MEDIUM));
    add(examplePanel);
    /**
     * The radio button select.
     */
    final WRadioButtonSelect rbSelect = new WRadioButtonSelect("australian_state");
    final WTextField text = new WTextField();
    text.setReadOnly(true);
    text.setText(NO_SELECTION);
    WButton update = new WButton("Update");
    update.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            text.setText("The selected item is: " + rbSelect.getSelected());
        }
    });
    // setting the default submit button improves usability. It can be set on a WPanel or the WRadioButtonSelect directly
    examplePanel.setDefaultSubmitButton(update);
    examplePanel.add(new WLabel("Select a state or territory", rbSelect));
    examplePanel.add(rbSelect);
    examplePanel.add(text);
    examplePanel.add(update);
    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) FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) 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)

Aggregations

WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)27 WButton (com.github.bordertech.wcomponents.WButton)18 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)16 Action (com.github.bordertech.wcomponents.Action)15 WHeading (com.github.bordertech.wcomponents.WHeading)13 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)10 WPanel (com.github.bordertech.wcomponents.WPanel)8 Margin (com.github.bordertech.wcomponents.Margin)6 WTextField (com.github.bordertech.wcomponents.WTextField)6 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)5 WLabel (com.github.bordertech.wcomponents.WLabel)5 AjaxTarget (com.github.bordertech.wcomponents.AjaxTarget)4 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)4 ValidatingAction (com.github.bordertech.wcomponents.validation.ValidatingAction)4 WRadioButtonSelect (com.github.bordertech.wcomponents.WRadioButtonSelect)3 Equal (com.github.bordertech.wcomponents.subordinate.Equal)3 Rule (com.github.bordertech.wcomponents.subordinate.Rule)3 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)3 ArrayList (java.util.ArrayList)3 WComponent (com.github.bordertech.wcomponents.WComponent)2