Search in sources :

Example 1 with WConfirmationButton

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

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

the class WConfirmationButtonRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WConfirmationButton component = new WConfirmationButton("dummy");
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(component) instanceof WButtonRenderer);
}
Also used : WConfirmationButton(com.github.bordertech.wcomponents.WConfirmationButton) Test(org.junit.Test)

Example 3 with WConfirmationButton

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

the class WConfirmationButtonRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WConfirmationButton button = new WConfirmationButton("dummy");
    assertXpathExists("//html:button", button);
    String message = "WConfirmationButton_Test.testRenderedFormat.message";
    button.setMessage(message);
    assertXpathEvaluatesTo(message, "//html:button/@data-wc-btnmsg", button);
}
Also used : WConfirmationButton(com.github.bordertech.wcomponents.WConfirmationButton) Test(org.junit.Test)

Example 4 with WConfirmationButton

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

the class WConfirmationButtonRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WConfirmationButton button = new WConfirmationButton(getMaliciousContent());
    assertSafeContent(button);
    button.setToolTip(getMaliciousAttribute("html:button"));
    assertSafeContent(button);
    button.setAccessibleText(getMaliciousAttribute("html:button"));
    assertSafeContent(button);
    button.setMessage(getMaliciousAttribute("html:button"));
    assertSafeContent(button);
    button.setImageUrl(getMaliciousAttribute());
    assertSafeContent(button);
}
Also used : WConfirmationButton(com.github.bordertech.wcomponents.WConfirmationButton) Test(org.junit.Test)

Aggregations

WConfirmationButton (com.github.bordertech.wcomponents.WConfirmationButton)4 Test (org.junit.Test)3 Action (com.github.bordertech.wcomponents.Action)1 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)1 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)1 WButton (com.github.bordertech.wcomponents.WButton)1 WPanel (com.github.bordertech.wcomponents.WPanel)1 List (java.util.List)1