Search in sources :

Example 11 with WButton

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

the class WButtonExample method addClientOnlyExamples.

/**
 * Examples showing use of client only buttons.
 */
private void addClientOnlyExamples() {
    // client command button
    add(new WHeading(HeadingLevel.H2, "Client command buttons"));
    add(new ExplanatoryText("These examples show buttons which do not submit the form"));
    // client command buttons witho a command
    WButton nothingButton = new WButton("Do nothing");
    add(nothingButton);
    nothingButton.setClientCommandOnly(true);
    nothingButton = new WButton("Do nothing link");
    add(nothingButton);
    nothingButton.setRenderAsLink(true);
    nothingButton.setClientCommandOnly(true);
    // client command buttons with command.
    HelloButton helloButton = new HelloButton("Hello");
    add(helloButton);
    helloButton = new HelloButton("Hello link");
    helloButton.setRenderAsLink(true);
    add(helloButton);
}
Also used : ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WButton(com.github.bordertech.wcomponents.WButton) WHeading(com.github.bordertech.wcomponents.WHeading)

Example 12 with WButton

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

the class WButtonExample method addAntiPatternExamples.

/**
 * Examples of what not to do when using WButton.
 */
private void addAntiPatternExamples() {
    add(new WHeading(HeadingLevel.H2, "WButton anti-pattern examples"));
    add(new WMessageBox(WMessageBox.WARN, "These examples are purposely bad and should not be used as samples of how to use WComponents but samples of how NOT to use them."));
    add(new WHeading(HeadingLevel.H3, "WButton without a good label"));
    add(new WButton("\u2002"));
    add(new ExplanatoryText("A button without a text label is very bad"));
    add(new WHeading(HeadingLevel.H3, "WButton with a WImage but without a good label"));
    WButton button = new WButton("");
    button.setImage("/image/help.png");
    add(button);
    add(new ExplanatoryText("A button without a text label is very bad, even if you think the image is sufficient. The text label becomes the image alt text."));
}
Also used : WMessageBox(com.github.bordertech.wcomponents.WMessageBox) WButton(com.github.bordertech.wcomponents.WButton) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WHeading(com.github.bordertech.wcomponents.WHeading)

Example 13 with WButton

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

the class WButtonExample method makeImageButtonWithPosition.

/**
 * 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;
}
Also used : WButton(com.github.bordertech.wcomponents.WButton)

Example 14 with WButton

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

the class WContentExample method addContentRow.

/**
 * Adds components to the given container which demonstrate various ways of acessing the given content.
 *
 * @param contentDesc the description of the content, used to label the controls.
 * @param contentAccess the content which will be displayed.
 * @param target the container to add the UI controls to.
 */
private void addContentRow(final String contentDesc, final ContentAccess contentAccess, final MutableContainer target) {
    // Demonstrate WButton + WContent, round trip
    WButton button = new WButton(contentDesc);
    final WContent buttonContent = new WContent();
    button.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            buttonContent.setContentAccess(contentAccess);
            buttonContent.display();
        }
    });
    WContainer buttonCell = new WContainer();
    buttonCell.add(buttonContent);
    buttonCell.add(button);
    target.add(buttonCell);
    // Demonstrate WButton + WContent, using AJAX
    WButton ajaxButton = new WButton(contentDesc);
    final WContent ajaxContent = new WContent();
    ajaxButton.setAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            ajaxContent.setContentAccess(contentAccess);
            ajaxContent.display();
        }
    });
    WContainer ajaxCell = new WContainer();
    // The WContent must be wrapped in an AJAX targetable container
    WPanel ajaxContentPanel = new WPanel();
    ajaxContentPanel.add(ajaxContent);
    ajaxCell.add(ajaxButton);
    ajaxCell.add(ajaxContentPanel);
    ajaxButton.setAjaxTarget(ajaxContentPanel);
    target.add(ajaxCell);
    // Demonstrate WContentLink - new window
    WContentLink contentLinkNewWindow = new WContentLink(contentDesc) {

        @Override
        protected void preparePaintComponent(final Request request) {
            super.preparePaintComponent(request);
            setContentAccess(contentAccess);
        }
    };
    target.add(contentLinkNewWindow);
    // Demonstrate WContentLink - prompt to save
    WContentLink contentLinkPromptToSave = new WContentLink(contentDesc) {

        @Override
        protected void preparePaintComponent(final Request request) {
            super.preparePaintComponent(request);
            setContentAccess(contentAccess);
        }
    };
    contentLinkPromptToSave.setDisplayMode(DisplayMode.PROMPT_TO_SAVE);
    target.add(contentLinkPromptToSave);
    // Demonstrate WContentLink - inline
    WContentLink contentLinkInline = new WContentLink(contentDesc) {

        @Override
        protected void preparePaintComponent(final Request request) {
            super.preparePaintComponent(request);
            setContentAccess(contentAccess);
        }
    };
    contentLinkInline.setDisplayMode(DisplayMode.DISPLAY_INLINE);
    target.add(contentLinkInline);
    // Demonstrate targeting of content via a URL
    WMenu menu = new WMenu(WMenu.MenuType.FLYOUT);
    final WContent menuContent = new WContent();
    menuContent.setDisplayMode(DisplayMode.PROMPT_TO_SAVE);
    WMenuItem menuItem = new WMenuItem(contentDesc) {

        @Override
        protected void preparePaintComponent(final Request request) {
            super.preparePaintComponent(request);
            menuContent.setContentAccess(contentAccess);
            setUrl(menuContent.getUrl());
        }
    };
    menu.add(menuItem);
    WContainer menuCell = new WContainer();
    menuCell.add(menuContent);
    menuCell.add(menu);
    target.add(menuCell);
}
Also used : Action(com.github.bordertech.wcomponents.Action) WContainer(com.github.bordertech.wcomponents.WContainer) WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WContent(com.github.bordertech.wcomponents.WContent) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) Request(com.github.bordertech.wcomponents.Request) WMenu(com.github.bordertech.wcomponents.WMenu) WButton(com.github.bordertech.wcomponents.WButton) WContentLink(com.github.bordertech.wcomponents.WContentLink)

Example 15 with WButton

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

the class WDropdownOptionsExample method applySettings.

/**
 * Apply the settings from the control table to the drop down.
 */
private void applySettings() {
    container.reset();
    infoPanel.reset();
    // create the list of options.
    List<String> options = new ArrayList<>(Arrays.asList(OPTIONS_ARRAY));
    if (cbNullOption.isSelected()) {
        options.add(0, "");
    }
    // create the dropdown.
    final WDropdown dropdown = new WDropdown(options);
    // set the dropdown type.
    dropdown.setType((DropdownType) rbsDDType.getSelected());
    // set the selected option if applicable.
    String selected = (String) rgDefaultOption.getSelected();
    if (selected != null && !NONE.equals(selected)) {
        dropdown.setSelected(selected);
    }
    // set the width.
    if (nfWidth.getValue() != null) {
        dropdown.setOptionWidth(nfWidth.getValue().intValue());
    }
    // set the tool tip.
    if (tfToolTip.getText() != null && tfToolTip.getText().length() > 0) {
        dropdown.setToolTip(tfToolTip.getText());
    }
    // set misc options.
    dropdown.setVisible(cbVisible.isSelected());
    dropdown.setDisabled(cbDisabled.isSelected());
    // add the action for action on change, ajax and subordinate.
    if (cbActionOnChange.isSelected() || cbAjax.isSelected() || cbSubmitOnChange.isSelected()) {
        final WStyledText info = new WStyledText();
        info.setWhitespaceMode(WhitespaceMode.PRESERVE);
        infoPanel.add(info);
        dropdown.setActionOnChange(new Action() {

            @Override
            public void execute(final ActionEvent event) {
                String selectedOption = (String) dropdown.getSelected();
                info.setText(selectedOption);
            }
        });
    }
    // this has to be below the set action on change so it is
    // not over written.
    dropdown.setSubmitOnChange(cbSubmitOnChange.isSelected());
    // add the ajax target.
    if (cbAjax.isSelected()) {
        WAjaxControl update = new WAjaxControl(dropdown);
        update.addTarget(infoPanel);
        container.add(update);
    }
    // add the subordinate stuff.
    if (rbsDDType.getValue() == WDropdown.DropdownType.COMBO) {
        // This is to work around a WComponent Subordinate logic flaw.
        cbSubordinate.setSelected(false);
    }
    if (cbSubordinate.isSelected()) {
        WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
        container.add(group);
        WSubordinateControl control = new WSubordinateControl();
        container.add(control);
        for (String option : OPTIONS_ARRAY) {
            buildSubordinatePanel(dropdown, option, group, control);
        }
        // add a rule for none selected.
        Rule rule = new Rule();
        control.addRule(rule);
        rule.setCondition(new Equal(dropdown, ""));
        rule.addActionOnTrue(new Hide(group));
    }
    WFieldLayout flay = new WFieldLayout();
    flay.setLabelWidth(25);
    container.add(flay);
    flay.addField("Configured dropdown", dropdown);
    flay.addField((WLabel) null, new WButton("Submit"));
}
Also used : Hide(com.github.bordertech.wcomponents.subordinate.Hide) Action(com.github.bordertech.wcomponents.Action) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) ArrayList(java.util.ArrayList) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WStyledText(com.github.bordertech.wcomponents.WStyledText) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) WButton(com.github.bordertech.wcomponents.WButton) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WDropdown(com.github.bordertech.wcomponents.WDropdown) Equal(com.github.bordertech.wcomponents.subordinate.Equal) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule)

Aggregations

WButton (com.github.bordertech.wcomponents.WButton)76 Test (org.junit.Test)39 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)25 Action (com.github.bordertech.wcomponents.Action)20 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)18 WTextField (com.github.bordertech.wcomponents.WTextField)17 WHeading (com.github.bordertech.wcomponents.WHeading)16 WContainer (com.github.bordertech.wcomponents.WContainer)14 WPanel (com.github.bordertech.wcomponents.WPanel)13 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)11 ValidatingAction (com.github.bordertech.wcomponents.validation.ValidatingAction)10 WLabel (com.github.bordertech.wcomponents.WLabel)9 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)8 UIContext (com.github.bordertech.wcomponents.UIContext)7 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)7 WText (com.github.bordertech.wcomponents.WText)6 WDataTable (com.github.bordertech.wcomponents.WDataTable)5 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)5 WTable (com.github.bordertech.wcomponents.WTable)5 AdapterBasicTableModel (com.github.bordertech.wcomponents.AdapterBasicTableModel)4