Example usage for com.vaadin.ui Grid setDataProvider

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

Introduction

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

Prototype

@Override
    public void setDataProvider(DataProvider<T, ?> dataProvider) 

Source Link

Usage

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

/**
 * Creates a table with datasource of IndexedContainer
 * @return the Grid for InstallationSummary
 */// w ww  . j  a  va 2  s.  c om
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;
}

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

@Override
@SuppressWarnings("unchecked")
public void update() {

    // install/uninstall steps
    Grid<InstallationSummary> installTable = tables.get(GridTypes.INSTALL_UNINSTALL);
    List<InstallationSummary> installationSummaries = new ArrayList<>();
    for (InstallPlanStep step : packageManagerOperation.getInstallPlan().getSteps()) {

        InstallationSummary is = new InstallationSummary();
        final Package pkg;
        if (step instanceof InstallPlanStep.PackageInstallStep) {
            pkg = ((InstallPlanStep.PackageInstallStep) step).getPackage();
            is.setIcon(VaadinIcons.DOWNLOAD);
        } else if (step instanceof InstallPlanStep.PackageUninstallStep) {
            pkg = ((InstallPlanStep.PackageUninstallStep) step).getInstalledPackage();
            is.setIcon(VaadinIcons.TRASH);
        } else if (step instanceof InstallPlanStep.PackageVersionChangeStep) {
            pkg = ((InstallPlanStep.PackageVersionChangeStep) step).getTargetPackage();
            final Package installedPackage = ((InstallPlanStep.PackageVersionChangeStep) step)
                    .getInstalledPackage();
            is.setInstalledVersion(installedPackage.getVersion().toString());

            if (installedPackage.getVersion().compareTo(pkg.getVersion()) < 0) {
                is.setIcon(VaadinIcons.ARROW_CIRCLE_UP_O);
            } else {
                is.setIcon(VaadinIcons.ARROW_CIRCLE_DOWN_O);
            }//from  w w  w.  j  av a2  s .c  o m

        } else {
            LOG.error("Unsupported type of Install Plan Step:" + step);
            continue;
        }
        is.setPackageName(pkg.getName());
        is.setPackageVersion(pkg.getVersion().toString());
        is.setLicense(pkg.getLicense());
        installationSummaries.add(is);
    }
    installTable.setDataProvider(DataProvider.ofCollection(installationSummaries));
    setGridHeight(installTable, installationSummaries.size());

    // conflicts
    Grid<InstallationSummary> conflictsTable = tables.get(GridTypes.CONFLICTS);
    if (conflictsTable != null) {
        List<InstallationSummary> conflictsSummaries = new ArrayList<>();
        for (PackageConflict conflict : packageManagerOperation.getConflicts()) {
            Package pkg = conflict.getSource();
            conflictsSummaries
                    .add(new InstallationSummary(pkg.getName(), pkg.getVersion().toString(), pkg.getLicense()));
        }
        conflictsTable.setDataProvider(DataProvider.ofCollection(conflictsSummaries));
        setGridHeight(conflictsTable, conflictsSummaries.size());
    }

    // unresolved dependencies
    Grid<InstallationSummary> unresolvedTable = tables.get(GridTypes.UNRESOVED);
    if (unresolvedTable != null) {
        List<InstallationSummary> unresolvedSummaries = new ArrayList<>();
        for (UnresolvedDependency unresolvedDep : packageManagerOperation.getUnresolved()) {
            Package pkg;
            if (packageManagerOperation.hasPackagesToUninstall()) {
                pkg = unresolvedDep.getSource();
            } else {
                pkg = getPackage(unresolvedDep.getMissing());
            }
            if (pkg != null) {
                unresolvedSummaries.add(
                        new InstallationSummary(pkg.getName(), pkg.getVersion().toString(), pkg.getLicense()));
            }
        }
        unresolvedTable.setDataProvider(DataProvider.ofCollection(unresolvedSummaries));
        setGridHeight(unresolvedTable, unresolvedSummaries.size());
    }

    // suggested
    Grid<InstallationSummary> suggestedTable = tables.get(GridTypes.SUGGESTED);
    if (suggestedTable != null) {
        suggestedTable
                .setDataProvider(
                        DataProvider.ofCollection(packageManagerOperation
                                .getSuggested().stream().map(pkg -> new InstallationSummary(pkg.getName(),
                                        pkg.getVersion().toString(), pkg.getLicense()))
                                .collect(Collectors.toList())));
        setGridHeight(suggestedTable, packageManagerOperation.getSuggested().size());
    }
}