Search in sources :

Example 6 with WPanel

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

the class FlowLayoutExample method addBoxes.

/**
 * Adds a set of boxes to the given panel.
 *
 * @param panel the panel to add the boxes to.
 * @param amount the number of boxes to add.
 */
private static void addBoxes(final WPanel panel, final int amount) {
    for (int i = 1; i <= amount; i++) {
        WPanel box = new WPanel(WPanel.Type.BOX);
        box.add(new WText(Integer.toString(i)));
        panel.add(box);
    }
}
Also used : WText(com.github.bordertech.wcomponents.WText) WPanel(com.github.bordertech.wcomponents.WPanel)

Example 7 with WPanel

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

the class GridLayoutOptionsExample method applySettings.

/**
 * reset the container that holds the grid layout and create a new grid layout with the appropriate properties.
 */
private void applySettings() {
    container.reset();
    // Now show an example of the number of different columns
    WPanel gridLayoutPanel = new WPanel();
    if (cbResponsive.isSelected()) {
        gridLayoutPanel.setHtmlClass(HtmlClassProperties.RESPOND);
    }
    GridLayout layout = new GridLayout(rowCount.getValue().intValue(), columnCount.getValue().intValue(), hGap.getValue().intValue(), vGap.getValue().intValue());
    gridLayoutPanel.setLayout(layout);
    // give approx 3 rows, with a different number
    addBoxes(gridLayoutPanel, boxCount.getValue().intValue());
    // of boxes on the final row
    container.add(gridLayoutPanel);
    gridLayoutPanel.setVisible(cbVisible.isSelected());
}
Also used : GridLayout(com.github.bordertech.wcomponents.layout.GridLayout) WPanel(com.github.bordertech.wcomponents.WPanel)

Example 8 with WPanel

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

the class ListLayoutExample method addExample.

/**
 * Adds an example to the set of examples.
 *
 * @param heading the heading for the example
 * @param layout the layout for the panel
 */
private void addExample(final String heading, final ListLayout layout) {
    add(new WHeading(HeadingLevel.H2, heading));
    WPanel panel = new WPanel();
    panel.setLayout(layout);
    add(panel);
    for (String item : EXAMPLE_ITEMS) {
        panel.add(new WText(item));
    }
    add(new WHorizontalRule());
}
Also used : WText(com.github.bordertech.wcomponents.WText) WPanel(com.github.bordertech.wcomponents.WPanel) WHeading(com.github.bordertech.wcomponents.WHeading) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule)

Example 9 with WPanel

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

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

the class WLabelExample method addAntiPatternExamples.

/**
 * Add examples you should never follow. DO NOT use the following as examples of what to do: these are examples of what NOT to do.
 */
private void addAntiPatternExamples() {
    add(new WHeading(HeadingLevel.H2, "WLabel anti-patterns"));
    add(new ExplanatoryText("These are here for testing purposes and must not be used as examples to follow.\n" + "Turn on debugging (bordertech.wcomponents.debug.enabled=true) to get much more information."));
    add(new WHeading(HeadingLevel.H3, "Poor but not erroneous uses of WLabel"));
    WPanel errorLayoutPanel = new WPanel();
    errorLayoutPanel.setLayout(new FlowLayout(FlowLayout.VERTICAL, Size.LARGE));
    add(errorLayoutPanel);
    // label not for anything should not be a WLabel
    errorLayoutPanel.add(new WLabel("I am not 'for' anything"));
    // WLabel for something which is not labellable
    errorLayoutPanel.add(new WLabel("I am for a component which should not be labelled", errorLayoutPanel));
    // If the WLabel is 'for' something that is not in the tree it becomes 'for' the WApplication. This is not necessarily a good thing!!!
    WCheckBox notHere = new WCheckBox();
    errorLayoutPanel.add(new WLabel("My component wasn't added", notHere));
    /*
		 * The examples which follow MUST NEVER BE USED! They cause ERRORS.
		 * They are here purely for framework testing.
		 */
    add(new WHeading(HeadingLevel.H3, "Very bad uses of WLabel"));
    errorLayoutPanel = new WPanel();
    errorLayoutPanel.setLayout(new FlowLayout(FlowLayout.VERTICAL, Size.LARGE));
    add(errorLayoutPanel);
    /*
		 * Nested WLabels: very bad
		 */
    errorLayoutPanel.add(new ExplanatoryText("This example shows nested WLabels. This is a contravention of the HTML specification."));
    WPanel nestingErrorPanel = new WPanel();
    nestingErrorPanel.setLayout(new ColumnLayout(new int[] { 50, 50 }, Size.LARGE, Size.MEDIUM));
    errorLayoutPanel.add(nestingErrorPanel);
    WTextField outerField = new WTextField();
    WLabel outerLabel = new WLabel("I am an outer label", outerField);
    nestingErrorPanel.add(outerLabel);
    WTextField innerField = new WTextField();
    WLabel innerLabel = new WLabel("Inner label", innerField);
    // add the inner label to the outer label: this is the ERROR
    outerLabel.add(innerLabel);
    nestingErrorPanel.add(innerField);
    nestingErrorPanel.add(outerField);
    /*
		 * It is permissible to place certain simple form control components into
		 * a WLabel under the following conditions:
		 * there must be no more than one such component in the WLabel;
		 * the component MUST be one which outputs a simple HTML form control
		 * (and I am not going to tell you which they are);
		 * The WLabel must be 'for' the nested component or not 'for' anything.
		 */
    errorLayoutPanel.add(new ExplanatoryText("This example shows a WLabel with a nested simple form control WTextField but the WLabel is not " + "'for' the WTextField. This is a contravention of the HTML specification."));
    WTextField notMyField = new WTextField();
    notMyField.setToolTip("This field should not be in the label it is in");
    WTextField myField = new WTextField();
    WLabel myFieldLabel = new WLabel("I am not the label for my nested text field", myField);
    nestingErrorPanel = new WPanel();
    nestingErrorPanel.setLayout(new ColumnLayout(new int[] { 50, 50 }, 12, 6));
    errorLayoutPanel.add(nestingErrorPanel);
    nestingErrorPanel.add(myFieldLabel);
    nestingErrorPanel.add(myField);
    // adding the 'wrong' WTextField to a WLabel is what causes this error
    myFieldLabel.add(notMyField);
    add(new ExplanatoryText("The next field has a label explicitly set to only white space."));
    WTextField emptyLabelTextField = new WTextField();
    WLabel emptyLabel = new WLabel(" ", emptyLabelTextField);
    add(emptyLabel);
    add(emptyLabelTextField);
    add(new WHeading(HeadingLevel.H2, "Unlabelled controls"));
    add(new ExplanatoryText("These controls must be labelled but are not."));
    WFieldLayout fieldsFlat = new WFieldLayout();
    add(fieldsFlat);
    fieldsFlat.addField((WLabel) null, new WTextField());
    fieldsFlat.addField((WLabel) null, new WTextArea());
    fieldsFlat.addField((WLabel) null, new WDateField());
    fieldsFlat.addField((WLabel) null, new WCheckBox());
    fieldsFlat.addField((WLabel) null, new WCheckBoxSelect(new String[] { "Apple", "Cherry", "Orange", "Pineapple" }));
}
Also used : FlowLayout(com.github.bordertech.wcomponents.layout.FlowLayout) WPanel(com.github.bordertech.wcomponents.WPanel) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WHeading(com.github.bordertech.wcomponents.WHeading) WLabel(com.github.bordertech.wcomponents.WLabel) WTextArea(com.github.bordertech.wcomponents.WTextArea) ColumnLayout(com.github.bordertech.wcomponents.layout.ColumnLayout) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WDateField(com.github.bordertech.wcomponents.WDateField) WTextField(com.github.bordertech.wcomponents.WTextField) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect)

Aggregations

WPanel (com.github.bordertech.wcomponents.WPanel)77 Test (org.junit.Test)39 WHeading (com.github.bordertech.wcomponents.WHeading)17 WText (com.github.bordertech.wcomponents.WText)17 FlowLayout (com.github.bordertech.wcomponents.layout.FlowLayout)16 WButton (com.github.bordertech.wcomponents.WButton)13 ColumnLayout (com.github.bordertech.wcomponents.layout.ColumnLayout)10 WContainer (com.github.bordertech.wcomponents.WContainer)9 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)9 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)8 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)8 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)7 WLabel (com.github.bordertech.wcomponents.WLabel)7 Action (com.github.bordertech.wcomponents.Action)6 WTextField (com.github.bordertech.wcomponents.WTextField)6 ArrayList (java.util.ArrayList)6 Size (com.github.bordertech.wcomponents.Size)5 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)5 BorderLayout (com.github.bordertech.wcomponents.layout.BorderLayout)5 Alignment (com.github.bordertech.wcomponents.layout.ColumnLayout.Alignment)5