Example usage for com.vaadin.ui Grid addComponentColumn

List of usage examples for com.vaadin.ui Grid addComponentColumn

Introduction

In this page you can find the example usage for com.vaadin.ui Grid addComponentColumn.

Prototype

public <V extends Component> Column<T, V> addComponentColumn(ValueProvider<T, V> componentProvider) 

Source Link

Document

Adds a column that shows components.

Usage

From source file:org.openthinclient.web.pkgmngr.ui.InstallationPlanSummaryDialog.java

/**
 * Creates a table with datasource of IndexedContainer
 * @return the Grid for InstallationSummary
 *//*from   w w w  . java2s.co  m*/
private Grid<InstallationSummary> createTable(GridTypes type) {

    Grid<InstallationSummary> summary = new Grid<>();
    summary.setDataProvider(DataProvider.ofCollection(Collections.EMPTY_LIST));
    summary.setSelectionMode(Grid.SelectionMode.NONE);
    summary.addColumn(InstallationSummary::getPackageName)
            .setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_NAME));
    summary.addColumn(InstallationSummary::getPackageVersion)
            .setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_VERSION));
    if (type == GridTypes.INSTALL_UNINSTALL && !packageManagerOperation.hasPackagesToUninstall()) { // license column
        summary.addComponentColumn(is -> {
            if (is.getLicense() != null) {
                Button button = new Button(
                        mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_LICENSE_SHOW));
                button.addClickListener(click -> {
                    // licence already clicked, re-set button caption
                    licenceButtons.stream().filter(b -> !b.equals(button)).forEach(b -> {
                        if (b.getCaption().equals(
                                mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_LICENSE_HIDE))) {
                            b.setCaption(
                                    mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_LICENSE_SHOW));
                        }
                    });
                    // display licence
                    if (button.getCaption()
                            .equals(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_LICENSE_SHOW))) {
                        licenceTextArea.setVisible(true);
                        licenceTextArea.setValue(is.getLicense());
                    } else {
                        licenceTextArea.setVisible(false);
                    }
                    button.setCaption(licenceTextArea.isVisible()
                            ? mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_LICENSE_HIDE)
                            : mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_LICENSE_SHOW));
                });
                button.addStyleName("package_install_summary_display_license_button");
                licenceButtons.add(button);
                return button;
            } else {
                return null;
            }
        }).setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_LICENSE));
    }

    summary.addStyleName(ValoTheme.TABLE_BORDERLESS);
    summary.addStyleName(ValoTheme.TABLE_NO_HEADER);
    summary.addStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES);
    summary.addStyleName(ValoTheme.TABLE_NO_HORIZONTAL_LINES);
    summary.setHeightMode(HeightMode.ROW);

    return summary;
}