Search in sources :

Example 1 with WAjaxControl

use of com.github.bordertech.wcomponents.WAjaxControl 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 2 with WAjaxControl

use of com.github.bordertech.wcomponents.WAjaxControl 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 3 with WAjaxControl

use of com.github.bordertech.wcomponents.WAjaxControl 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 4 with WAjaxControl

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

the class WCheckBoxSelectExample method addInsideAFieldLayoutExamples.

/**
 * When a WCheckBoxSelect is added to a WFieldLayout the legend is moved. The first CheckBoxSelect has a frame, the
 * second doesn't
 */
private void addInsideAFieldLayoutExamples() {
    add(new WHeading(HeadingLevel.H3, "WCheckBoxSelect inside a WFieldLayout"));
    add(new ExplanatoryText("When a WCheckBoxSelect is inside a WField its label is exposed in a way which appears and behaves like a regular " + "HTML label. This allows WCheckBoxSelects to be used in a layout with simple form controls (such as WTextField) and produce a " + "consistent and predicatable interface. 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."));
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(25);
    add(layout);
    String[] options = new String[] { "Dog", "Cat", "Bird", "Turtle" };
    WCheckBoxSelect select = new WCheckBoxSelect(options);
    layout.addField("Select some animals", select);
    String[] options2 = new String[] { "Parrot", "Galah", "Cockatoo", "Lyre" };
    select = new WCheckBoxSelect(options2);
    layout.addField("Select some birds", 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 WCheckBoxSelect(options3);
    layout.addField((WLabel) null, select);
    select.setToolTip("Veggies");
    select = new WCheckBoxSelect("australian_state");
    layout.addField("Select a state", select).getLabel().setHint("This is an ajax trigger");
    add(new WAjaxControl(select, layout));
}
Also used : WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WHeading(com.github.bordertech.wcomponents.WHeading) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect)

Example 5 with WAjaxControl

use of com.github.bordertech.wcomponents.WAjaxControl 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

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