Search in sources :

Example 1 with Action

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

the class MenuBarExample method buildMenuBar.

/**
 * Builds up a menu bar for inclusion in the example.
 *
 * @param selectedMenuText the WText to display the selected menu item.
 * @return a menu bar for the example.
 */
private WMenu buildMenuBar(final WText selectedMenuText) {
    WMenu menu = new WMenu();
    // The Colours menu just shows simple text
    WSubMenu colourMenu = new WSubMenu("Colours");
    colourMenu.setMode(WSubMenu.MenuMode.LAZY);
    colourMenu.setAccessKey('C');
    addMenuItem(colourMenu, "Red", selectedMenuText);
    addMenuItem(colourMenu, "Green", selectedMenuText);
    addMenuItem(colourMenu, "Blue", selectedMenuText);
    colourMenu.addSeparator();
    colourMenu.add(new WMenuItem("Disable colour menu", new ToggleDisabledAction(colourMenu)));
    menu.add(colourMenu);
    // The Shapes menu shows grouping of items
    WSubMenu shapeMenu = new WSubMenu("Shapes");
    shapeMenu.setAccessKey('S');
    addMenuItem(shapeMenu, "Circle", selectedMenuText);
    WMenuItemGroup triangleGroup = new WMenuItemGroup("Triangles");
    shapeMenu.add(triangleGroup);
    shapeMenu.setMode(WSubMenu.MenuMode.DYNAMIC);
    addMenuItem(triangleGroup, "Equilateral", selectedMenuText);
    addMenuItem(triangleGroup, "Isosceles", selectedMenuText);
    addMenuItem(triangleGroup, "Scalene", selectedMenuText);
    addMenuItem(triangleGroup, "Right-angled", selectedMenuText);
    addMenuItem(triangleGroup, "Obtuse", selectedMenuText);
    WMenuItemGroup quadGroup = new WMenuItemGroup("Quadrilaterals");
    shapeMenu.add(quadGroup);
    addMenuItem(quadGroup, "Square", selectedMenuText);
    addMenuItem(quadGroup, "Rectangle", selectedMenuText);
    addMenuItem(quadGroup, "Rhombus", selectedMenuText);
    addMenuItem(quadGroup, "Trapezoid", selectedMenuText);
    addMenuItem(quadGroup, "Parallelogram", selectedMenuText);
    shapeMenu.addSeparator();
    shapeMenu.add(new WMenuItem("Disable shape menu", new ToggleDisabledAction(shapeMenu)));
    menu.add(shapeMenu);
    // The Image menu shows use of decorated labels and images
    WDecoratedLabel imageLabel = new WDecoratedLabel(new WImage("/image/wrench.png", "spanner"), new WText("Images"), null);
    WSubMenu imageMenu = new WSubMenu(imageLabel);
    imageMenu.add(createImageMenuItem("/image/flag.png", "Flag", "eg-menu-image-1", selectedMenuText));
    imageMenu.add(createImageMenuItem("/image/attachment.png", "Attachment", "eg-menu-image-2", selectedMenuText));
    imageMenu.add(createImageMenuItem("/image/settings.png", "Settings", "eg-menu-image-3", selectedMenuText));
    imageMenu.addSeparator();
    imageMenu.add(new WMenuItem("Disable image menu", new ToggleDisabledAction(imageMenu)));
    menu.add(imageMenu);
    WSubMenu sitesMenu = new WSubMenu("External apps");
    sitesMenu.add(new WMenuItem("External website", "http://www.example.com/"));
    WMenuItem google = new WMenuItem("Example (new window)", "http://www.example.com/");
    google.setTargetWindow("exampleWindow");
    sitesMenu.add(google);
    menu.add(sitesMenu);
    // Add an item to toggle the states of all the menus
    menu.add(new WMenuItem("Toggle top-level menus", new ToggleDisabledAction(colourMenu, shapeMenu, imageMenu, sitesMenu)));
    menu.add(new WMenuItem("Link", "http://www.example.com"));
    menu.add(new WMenuItem("No Action"));
    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);
    WMenuItem itemWithImage = new WMenuItem(new WDecoratedLabel(new WImage("/image/home.png", "home"), new WText("Home"), null));
    menu.add(itemWithImage);
    menu.add(new WMenuItem(new WDecoratedLabel(new WImage("/image/settings.png", "settings"), new WText("Settings Menu"), null)));
    itemWithImage = new WMenuItem(new WDecoratedLabel(new WImage("/image/flag.png", "flag")));
    itemWithImage.setAccessibleText("flag this view");
    menu.add(itemWithImage);
    return menu;
}
Also used : Action(com.github.bordertech.wcomponents.Action) WSubMenu(com.github.bordertech.wcomponents.WSubMenu) WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WMenuItemGroup(com.github.bordertech.wcomponents.WMenuItemGroup) 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 2 with Action

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

the class RepeaterExampleWithStaticIDs method createPrintContactsSubForm.

/**
 * Create the UI artefacts for the "Print contacts" sub form.
 */
private void createPrintContactsSubForm() {
    add(new WHeading(HeadingLevel.H3, "Print to CSV"));
    WButton printBtn = new WButton("Print");
    printBtn.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            printDetails();
        }
    });
    printBtn.setImage("/image/document-print.png");
    printBtn.setImagePosition(WButton.ImagePosition.EAST);
    WFieldLayout layout = new WFieldLayout();
    add(layout);
    layout.setMargin(new Margin(Size.LARGE, null, null, null));
    layout.addField("Print output", printOutput);
    layout.addField((WLabel) null, printBtn);
    add(new WAjaxControl(printBtn, printOutput));
}
Also used : Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) Margin(com.github.bordertech.wcomponents.Margin)

Example 3 with Action

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

the class RepeaterExampleWithStaticIDs method createAddContactSubForm.

/**
 * Create the UI artefacts for the "Add contact" sub form.
 */
private void createAddContactSubForm() {
    add(new WHeading(HeadingLevel.H3, "Add a new contact"));
    WButton addBtn = new WButton("Add");
    addBtn.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            addNewContact();
        }
    });
    addBtn.setImage("/image/address-book-new.png");
    newNameField.setDefaultSubmitButton(addBtn);
    WContainer container = new WContainer();
    container.add(newNameField);
    container.add(addBtn);
    WFieldLayout layout = new WFieldLayout();
    add(layout);
    layout.addField("New contact name", container);
    add(new WAjaxControl(addBtn, new AjaxTarget[] { repeater, newNameField }));
}
Also used : Action(com.github.bordertech.wcomponents.Action) WContainer(com.github.bordertech.wcomponents.WContainer) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) AjaxTarget(com.github.bordertech.wcomponents.AjaxTarget)

Example 4 with Action

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

the class TableRowEditingAjaxExample method setUpActionButtons.

/**
 * Setup the action buttons and ajax controls in the action column.
 */
private void setUpActionButtons() {
    // Buttons Panel
    WPanel buttonPanel = new WPanel();
    actionContainer.add(buttonPanel);
    // Edit Button
    final WButton editButton = new WButton("Edit") {

        @Override
        public boolean isVisible() {
            Object key = TableUtil.getCurrentRowKey();
            return !isEditRow(key);
        }
    };
    editButton.setImage("/image/pencil.png");
    editButton.setRenderAsLink(true);
    editButton.setToolTip("Edit");
    editButton.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            Object key = TableUtil.getCurrentRowKey();
            addEditRow(key);
        }
    });
    // Cancel Button
    final WButton cancelButton = new WButton("Cancel") {

        @Override
        public boolean isVisible() {
            Object key = TableUtil.getCurrentRowKey();
            return isEditRow(key);
        }
    };
    cancelButton.setImage("/image/cancel.png");
    cancelButton.setRenderAsLink(true);
    cancelButton.setToolTip("Cancel");
    cancelButton.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            Object key = TableUtil.getCurrentRowKey();
            removeEditRow(key);
            firstNameField.reset();
            lastNameField.reset();
            dobField.reset();
        }
    });
    // Delete Button
    WConfirmationButton deleteButton = new WConfirmationButton("Delete") {

        @Override
        public boolean isVisible() {
            Object key = TableUtil.getCurrentRowKey();
            return !isEditRow(key);
        }
    };
    deleteButton.setMessage("Do you want to delete row?");
    deleteButton.setImage("/image/remove.png");
    deleteButton.setRenderAsLink(true);
    deleteButton.setToolTip("Delete");
    deleteButton.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            Object key = TableUtil.getCurrentRowKey();
            removeEditRow(key);
            PersonBean bean = (PersonBean) actionContainer.getBean();
            List<PersonBean> beans = (List<PersonBean>) table.getBean();
            beans.remove(bean);
            table.handleDataChanged();
            messages.success(bean.getFirstName() + " " + bean.getLastName() + " removed.");
        }
    });
    buttonPanel.add(editButton);
    buttonPanel.add(cancelButton);
    buttonPanel.add(deleteButton);
    // Ajax - edit button
    WAjaxControl editAjax = new WAjaxControl(editButton, new AjaxTarget[] { firstNameField, lastNameField, dobField, buttonPanel }) {

        @Override
        public boolean isVisible() {
            return editButton.isVisible();
        }
    };
    buttonPanel.add(editAjax);
    // Ajax - cancel button
    WAjaxControl cancelAjax = new WAjaxControl(cancelButton, new AjaxTarget[] { firstNameField, lastNameField, dobField, buttonPanel }) {

        @Override
        public boolean isVisible() {
            return cancelButton.isVisible();
        }
    };
    buttonPanel.add(cancelAjax);
    buttonPanel.setIdName("buttons");
    editAjax.setIdName("ajax_edit");
    cancelAjax.setIdName("ajax_can");
    editButton.setIdName("edit_btn");
    cancelButton.setIdName("cancel_btn");
    deleteButton.setIdName("delete_btn");
}
Also used : Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) List(java.util.List) WButton(com.github.bordertech.wcomponents.WButton) WConfirmationButton(com.github.bordertech.wcomponents.WConfirmationButton)

Example 5 with Action

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

the class WCheckBoxSelectExample method addExampleUsingArrayList.

/**
 * This example creates the WCheckBoxSelect from a List of CarOptions.
 */
private void addExampleUsingArrayList() {
    add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect created using an array list of options"));
    List<CarOption> options = new ArrayList<>();
    options.add(new CarOption("1", "Ferrari", "F-360"));
    options.add(new CarOption("2", "Mercedez Benz", "amg"));
    options.add(new CarOption("3", "Nissan", "Skyline"));
    options.add(new CarOption("5", "Toyota", "Prius"));
    final WCheckBoxSelect select = new WCheckBoxSelect(options);
    select.setToolTip("Cars");
    final WTextField text = new WTextField();
    text.setReadOnly(true);
    text.setText(NO_SELECTION);
    WButton update = new WButton("Select Cars");
    update.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            String output = select.getSelected().isEmpty() ? NO_SELECTION : "The selected cars are: " + select.getSelected();
            text.setText(output);
        }
    });
    select.setDefaultSubmitButton(update);
    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) ArrayList(java.util.ArrayList) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect)

Aggregations

Action (com.github.bordertech.wcomponents.Action)28 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)27 WButton (com.github.bordertech.wcomponents.WButton)20 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)15 WHeading (com.github.bordertech.wcomponents.WHeading)12 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)8 WTextField (com.github.bordertech.wcomponents.WTextField)7 WPanel (com.github.bordertech.wcomponents.WPanel)6 ValidatingAction (com.github.bordertech.wcomponents.validation.ValidatingAction)6 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)4 WContainer (com.github.bordertech.wcomponents.WContainer)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 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)4 Margin (com.github.bordertech.wcomponents.Margin)3 WText (com.github.bordertech.wcomponents.WText)3 Equal (com.github.bordertech.wcomponents.subordinate.Equal)3 Rule (com.github.bordertech.wcomponents.subordinate.Rule)3