Example usage for com.google.gwt.gen2.table.client SelectionGrid setSelectionPolicy

List of usage examples for com.google.gwt.gen2.table.client SelectionGrid setSelectionPolicy

Introduction

In this page you can find the example usage for com.google.gwt.gen2.table.client SelectionGrid setSelectionPolicy.

Prototype

public void setSelectionPolicy(SelectionPolicy selectionPolicy) 

Source Link

Document

Set the selection policy, which determines if the user can select zero, one, or multiple rows.

Usage

From source file:com.google.gwt.gen2.demo.scrolltable.client.option.highlight.RowSelectionPolicyOption.java

License:Apache License

@Override
protected Widget onInitialize() {
    CustomForm form = new CustomForm();

    // Add the current status
    statusLabel = new Label();
    form.addLabeledWidget("Selection Status:", statusLabel);

    // Add the current policy
    policyBox = new ListBox();
    policyBox.addItem("Multi Row");
    policyBox.addItem("Single Row");
    policyBox.addItem("Checkboxes");
    policyBox.addItem("Radio Buttons");
    form.addLabeledWidget("Selection Policy:", policyBox);

    // Add button to change policy
    {/*w  w w.ja v  a 2s .  c  o  m*/
        Button button = new Button("Set Selection Policy", new ClickHandler() {
            public void onClick(ClickEvent event) {
                SelectionGrid grid = ScrollTableDemo.get().getDataTable();
                switch (policyBox.getSelectedIndex()) {
                case 0:
                    grid.setSelectionPolicy(SelectionPolicy.MULTI_ROW);
                    break;
                case 1:
                    grid.setSelectionPolicy(SelectionPolicy.ONE_ROW);
                    break;
                case 2:
                    grid.setSelectionPolicy(SelectionPolicy.CHECKBOX);
                    break;
                case 3:
                    grid.setSelectionPolicy(SelectionPolicy.RADIO);
                    break;
                }
                PagingScrollTableDemo.get().getPagingScrollTable().reloadPage();
            }
        });
        form.addButton(button);
    }

    // Add button to change status
    {
        Button button = new Button("Toggle Status", new ClickHandler() {
            public void onClick(ClickEvent event) {
                SelectionGrid grid = ScrollTableDemo.get().getDataTable();
                grid.setSelectionEnabled(!grid.isSelectionEnabled());
                refreshPolicy();
            }
        });
        form.addButton(button);
    }

    // Refresh policy and return
    refreshPolicy();
    return form;
}