List of usage examples for com.vaadin.data.provider DataProvider ofCollection
public static <T> ListDataProvider<T> ofCollection(Collection<T> items)
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.j a va 2 s . c o 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; }
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 a 2 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()); } }
From source file:org.openthinclient.web.pkgmngr.ui.view.PackageDetailsView.java
public PackageDetailsView() { IMessageConveyor mc = new MessageConveyor(UI.getCurrent().getLocale()); dependencies.setDataProvider(DataProvider.ofCollection(Collections.emptyList())); dependencies.setSelectionMode(Grid.SelectionMode.NONE); dependencies.addColumn(AbstractPackageItem::getName) .setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_NAME)); dependencies.addColumn(AbstractPackageItem::getDisplayVersion) .setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_VERSION)); dependencies.setHeight("39px"); dependencies.setStyleGenerator(new StyleGenerator<AbstractPackageItem>() { @Override/*from w ww . j a v a2s. co m*/ public String apply(AbstractPackageItem item) { if (item != null && item instanceof MissingPackageItem) { return "highlight-red"; } return null; } }); // conflicts conflicts.setDataProvider(DataProvider.ofCollection(Collections.emptyList())); conflicts.setSelectionMode(Grid.SelectionMode.NONE); conflicts.addColumn(AbstractPackageItem::getName) .setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_NAME)); conflicts.addColumn(AbstractPackageItem::getDisplayVersion) .setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_VERSION)); conflicts.setHeight("39px"); // provides provides.setDataProvider(DataProvider.ofCollection(Collections.emptyList())); provides.setSelectionMode(Grid.SelectionMode.NONE); provides.addColumn(AbstractPackageItem::getName) .setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_NAME)); provides.addColumn(AbstractPackageItem::getDisplayVersion) .setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_VERSION)); provides.setHeight("39px"); this.changeLog.setContentMode(ContentMode.PREFORMATTED); this.acceptLicenseCheckbox .setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_DETAILS_LICENSE_CHECKBOX_CAPTION)); // unfortunately this is the only way to access tabs defined in a design file. // we have to use the component instance to access the tab. // first the main tab sheet mainTabSheet.getTab(tabComponentCommon) .setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_DETAILS_COMMON_CAPTION)); tabRelations = mainTabSheet.getTab(tabComponentRelations); tabRelations.setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_DETAILS_RELATIONS_CAPTION)); mainTabSheet.getTab(tabComponentChangelog) .setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_DETAILS_CHANGELOG_CAPTION)); mainTabSheet.getTab(tabComponentLicense) .setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_DETAILS_LICENSE_CAPTION)); // second the relations tab sheet. tabDependencies = relationsTabSheet.getTab(dependencies); tabDependencies.setCaption( mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_DETAILS_RELATIONS_DEPENDENCIES_CAPTION)); tabProvides = relationsTabSheet.getTab(provides); tabProvides .setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_DETAILS_RELATIONS_PROVIDES_CAPTION)); tabConflicts = relationsTabSheet.getTab(conflicts); tabConflicts.setCaption( mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_DETAILS_RELATIONS_CONFLICTS_CAPTION)); updateRelationsTabs(); }
From source file:org.openthinclient.web.pkgmngr.ui.view.PackageDetailsView.java
@Override public void addDependencies(List<AbstractPackageItem> depends) { if (depends != null) { dependencies.setDataProvider(DataProvider.ofCollection(depends)); dependencies.setHeight(39 + (depends.size() * 38) + "px"); }//from ww w. j a va2 s . c om updateRelationsTabs(); }
From source file:org.openthinclient.web.pkgmngr.ui.view.PackageDetailsView.java
@Override public void addConflicts(List<AbstractPackageItem> packageConflicts) { if (conflicts != null) { conflicts.setDataProvider(DataProvider.ofCollection(packageConflicts)); conflicts.setHeight(39 + (packageConflicts.size() * 38) + "px"); }/*from w w w .j ava2 s. c om*/ updateRelationsTabs(); }
From source file:org.openthinclient.web.pkgmngr.ui.view.PackageDetailsView.java
@Override public void addProvides(List<AbstractPackageItem> packageProvides) { if (provides != null) { provides.setDataProvider(DataProvider.ofCollection(packageProvides)); provides.setHeight(39 + (packageProvides.size() * 38) + "px"); }/*from w ww . j a v a 2 s . c om*/ updateRelationsTabs(); }