/** * Creates a button to toggle the visibility of a tab. * * @param idx the index of the tab. * @return a button which toggles the visibility of the tab. */ private WButton newVisibilityToggleForTab(final int idx) { WButton toggleButton = new WButton("Toggle visibility of tab " + (idx + 1)); toggleButton.setAction(new Action() { @Override public void execute(final ActionEvent event) { boolean tabVisible = tabset.isTabVisible(idx); tabset.setTabVisible(idx, !tabVisible); } }); return toggleButton; } }
@Override public String getImageUrl() { String url = super.getImageUrl(); if (url != null && isRelativeBaseUrl()) { return EnvironmentHelper.prefixBaseUrl(url); } return url; }
if (pressed && isDisabled()) { LOG.warn("A disabled button has been triggered. " + getText() + ". " + getId()); return; if (pressed != isPressed()) { getOrCreateComponentModel().isPressed = pressed; final Action action = getAction(); if (action == null) { invokeLater(later); final ActionEvent event = new ActionEvent(this, getActionCommand(), getActionObject()); invokeLater(later);
@Override public void execute(final ActionEvent event) { boolean disabled = !plainBtn.isDisabled(); plainBtn.setDisabled(disabled); linkBtn.setDisabled(disabled); disableBtn.setText(disabled ? "Enable buttons" : "Disable buttons"); } });
/** * Clear button is pressed flag. */ protected void clearPressed() { if (isPressed()) { getOrCreateComponentModel().isPressed = false; } }
@Test public void testAllOptions() throws IOException, SAXException, XpathException { WButton button = new WButton("All"); button.setDisabled(true); setFlag(button, ComponentModel.HIDE_FLAG, true); button.setToolTip("Title"); button.setAccessKey('T'); button.setImageUrl("http://localhost/image.png"); button.setImagePosition(ImagePosition.EAST); button.setRenderAsLink(true); button.setAjaxTarget(new WTextField()); button.setPopupTrigger(true); setActiveContext(createUIContext()); button.setAction(new ValidatingAction(new WValidationErrors(), validationComponent) { @Override public void executeOnValid(final ActionEvent event) { assertXpathEvaluatesTo(button.getText(), "//html:button", button); assertXpathEvaluatesTo("disabled", "//html:button/@disabled", button); assertXpathEvaluatesTo("hidden", "//html:button/@hidden", button); assertXpathEvaluatesTo(button.getToolTip(), "//html:button/@title", button); assertXpathUrlEvaluatesTo(button.getImageUrl(), "//html:button//html:img/@src", button); assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imge')]", button); assertXpathEvaluatesTo(button.getAccessKeyAsString(), "//html:button/@accesskey", button); assertXpathEvaluatesTo("true", "//html:button/@aria-haspopup", button); assertXpathEvaluatesTo(validationComponent.getId(), "//html:button/@data-wc-validate", button); assertXpathEvaluatesTo(button.getId(), "//ui:ajaxtrigger/@triggerId", button); button.setImagePosition(ImagePosition.NORTH);
XmlStringBuilder xml = renderContext.getWriter(); WButton button = (WButton) component; String text = button.getText(); String imageUrl = button.getImageUrl(); String accessibleText = button.getAccessibleText(); String toolTip = button.getToolTip(); String buttonId = button.getId(); ImagePosition pos = button.getImagePosition(); if (Util.empty(text) && Util.empty(toolTip) && Util.empty(accessibleText)) { WImage imgHolder = button.getImageHolder(); if (null != imgHolder) { toolTip = imgHolder.getAlternativeText(); xml.appendAttribute("type", getButtonType(button)); xml.appendAttribute("class", geHtmlClassName(button)); xml.appendOptionalAttribute("disabled", button.isDisabled(), "disabled"); xml.appendOptionalAttribute("hidden", button.isHidden(), "hidden"); xml.appendOptionalAttribute("title", toolTip); xml.appendOptionalAttribute("aria-label", accessibleText); xml.appendOptionalAttribute("aria-haspopup", button.isPopupTrigger(), "true"); xml.appendOptionalAttribute("accesskey", Util.upperCase(button.getAccessKeyAsString())); xml.appendOptionalAttribute("data-wc-btnmsg", button.getMessage()); if (button.isCancel()) { xml.appendAttribute("formnovalidate", "formnovalidate"); } else { Action action = button.getAction();
new ColumnLayout.Alignment[]{ColumnLayout.Alignment.LEFT, ColumnLayout.Alignment.RIGHT})); buttonBar.setMargin(new Margin(Size.ZERO, Size.ZERO, Size.SMALL, Size.ZERO)); WButton envBtn = new WButton("Print WEnvironment"); envBtn.setAction(new Action() { @Override public void execute(final ActionEvent event) { envBtn.setAjaxTarget(console); WButton clearBtn = new WButton("Clear"); clearBtn.setAction(new Action() { @Override public void execute(final ActionEvent event) { clearBtn.setAjaxTarget(console);
/** * this is were the majority of the work is done for building the button. Note that it is in a container that is * reset, effectively creating a new button. this is only done to enable to dynamically change the button to a link * and back. */ private void applySettings() { buttonContainer.reset(); WButton exampleButton = new WButton(tfButtonLabel.getText()); exampleButton.setRenderAsLink(cbRenderAsLink.isSelected()); exampleButton.setText(tfButtonLabel.getText()); if (cbSetImage.isSelected()) { exampleButton.setImage("/image/pencil.png"); exampleButton.setImagePosition((ImagePosition) ddImagePosition.getSelected()); } exampleButton.setDisabled(cbDisabled.isSelected()); if (tfAccesskey.getText() != null && tfAccesskey.getText().length() > 0) { exampleButton.setAccessKey(tfAccesskey.getText().toCharArray()[0]); } buttonContainer.add(exampleButton); }
/** * Helper to create a button with an image and an action. * * @param text the text content of the button * @param pos the position of the button image relative to the text * @param asLink indicates the button should be rendered as a link * @return a button */ private WButton makeImageButtonWithPosition(final String text, final ImagePosition pos, final Boolean asLink) { WButton button = new WButton(text); button.setImage("/image/tick.png"); if (pos != null) { button.setImagePosition(pos); } button.setActionObject(button); button.setAction(new ExampleButtonAction()); if (asLink) { button.setRenderAsLink(true); } return button; }
final WButton dialogOpeningButton = new WButton( "Immediate (non-modal) dialog with button action"); final ViewPersonList defList = new ViewPersonList(); defList.addTerm("Dialog opened by", new WText(dialogOpeningButton.getText())); nonModalDialog = new WDialog(defList, dialogOpeningButton); nonModalDialog.setTitle("View list with time"); nonModalDialog.setWidth(600); dialogOpeningButton.setAction(new Action() { @Override public void execute(final ActionEvent event) { WButton modalSearchImmediate = new WButton("Show modal search Dialog (immediate)"); modalSearchImmediate.setAction(new Action() { @Override public void execute(final ActionEvent event) { WButton dialogButton1 = new WButton("Show modal search Dialog (round trip)"); dialogButton1.setPopupTrigger(true); dialogButton1.setAction(new Action() { @Override public void execute(final ActionEvent event) { WButton dialogButton2 = new WButton("Show non-modal view dialog"); dialogButton2.setPopupTrigger(true); dialogButton2.setAction(new Action() { @Override
@Test public void testSetPressed() { WButton button = new WButton("Test"); button.setLocked(true); setActiveContext(createUIContext()); button.setPressed(true, new MockRequest()); Assert.assertTrue("Button should be pressed", button.isPressed()); Assert.assertFalse("Button should not be in default state", button.isDefaultState()); button.setPressed(false, new MockRequest()); Assert.assertFalse("Button should be pressed", button.isPressed()); button.setDisabled(true); button.setPressed(true, new MockRequest()); Assert.assertTrue("Button should be disabled", button.isDisabled()); Assert.assertFalse("Button should be pressed when disabled", button.isPressed()); }
/** * Create the UI artefacts for the update and reset buttons. */ private void createButtonBar() { // Update and reset controls for the repeater. WPanel buttonPanel = new WPanel(WPanel.Type.FEATURE); buttonPanel.setMargin(new Margin(Size.MEDIUM, null , Size.LARGE, null)); buttonPanel.setLayout(new BorderLayout()); WButton updateButton = new WButton("Update"); updateButton.setImage("/image/document-save-5.png"); updateButton.setImagePosition(WButton.ImagePosition.EAST); buttonPanel.add(updateButton, BorderLayout.EAST); WButton resetButton = new WButton("Reset"); resetButton.setImage("/image/edit-undo-8.png"); resetButton.setImagePosition(WButton.ImagePosition.WEST); resetButton.setAction(new Action() { @Override public void execute(final ActionEvent event) { repeater.setData(fetchDataList()); } }); buttonPanel.add(resetButton, BorderLayout.WEST); add(buttonPanel); add(new WAjaxControl(updateButton, repeater)); add(new WAjaxControl(resetButton, repeater)); }
/** * Sets the 'ok' button's action. * * @param action the ok action. */ public void setOKAction(final Action action) { okBtn.setAction(action); }
WButton button = new WButton("Disabled button"); button.setDisabled(true); disabledButtonLayoutPanel.add(button); button = new WButton("Disabled button as link"); button.setDisabled(true); button.setRenderAsLink(true); disabledButtonLayoutPanel.add(button); button = new WButton("Disabled button"); button.setDisabled(true); button.setImage("/image/tick.png"); button.setToolTip("Checking currently disabled"); disabledButtonLayoutPanel.add(button); button = new WButton("Disabled button as link"); button.setDisabled(true); button.setRenderAsLink(true); button.setImage("/image/tick.png"); button.setToolTip("Checking currently disabled"); disabledButtonLayoutPanel.add(button); FlowLayout.ContentAlignment.BASELINE)); add(disabledButtonLayoutPanel); button = new WButton("Disabled button"); button.setDisabled(true); button.setImage("/image/tick.png"); button.setToolTip("Checking currently disabled"); button.setImagePosition(ImagePosition.EAST); disabledButtonLayoutPanel.add(button); button = new WButton("Disabled button as link");
editButton.setImage("/image/pencil.png"); editButton.setRenderAsLink(true); editButton.setToolTip("Edit"); editButton.setAction(new Action() { @Override public void execute(final ActionEvent event) { cancelButton.setImage("/image/cancel.png"); cancelButton.setRenderAsLink(true); cancelButton.setToolTip("Cancel"); cancelButton.setAction(new Action() { @Override public void execute(final ActionEvent event) { editAjax.setIdName("ajax_edit"); cancelAjax.setIdName("ajax_can"); editButton.setIdName("edit_btn"); cancelButton.setIdName("cancel_btn"); deleteButton.setIdName("delete_btn");
startButton.setAjaxTarget(this); startButton.setAction(new Action() { @Override public void execute(final ActionEvent event) { retryButton.setAjaxTarget(this); retryButton.setAction(new Action() { @Override public void execute(final ActionEvent event) { ajaxPolling.setVisible(false); ajaxReload.setVisible(false); retryButton.setVisible(false); startButton.setVisible(false);
@Test public void testAccessKeyHandling() { String buttonText = "ABCDE abcde"; WButton button = new WButton(buttonText); button.setAccessKey('E'); // reset shared button text. Access key should be automatically reset. button.setText("Test"); // override tool tip. String myToolTip = "My ToolTip"; button.setToolTip(myToolTip); Assert.assertEquals("Unexpected ToolTip text", myToolTip, button.getToolTip()); }
WButton button = new WButton("Flag this record for follow-up"); button.setImage("/image/flag.png"); button.getImageHolder().setCacheKey("eg-button-flag"); button.setActionObject(button); button.setAction(new ExampleButtonAction());