Example usage for com.vaadin.ui Grid setSelectionMode

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

Introduction

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

Prototype

public GridSelectionModel<T> setSelectionMode(SelectionMode selectionMode) 

Source Link

Document

Sets the grid's selection mode.

Usage

From source file:net.sourceforge.javydreamercsw.validation.manager.web.admin.AdminScreenProvider.java

License:Apache License

private Component displayIssueResolutions() {
    VerticalLayout vl = new VerticalLayout();
    Grid grid = new Grid(TRANSLATOR.translate(ISSUE_RESOLUTION));
    BeanItemContainer<IssueResolution> types = new BeanItemContainer<>(IssueResolution.class);
    types.addAll(new IssueResolutionJpaController(DataBaseManager.getEntityManagerFactory())
            .findIssueResolutionEntities());
    grid.setContainerDataSource(types);/*from ww w .ja va  2  s.  c  o  m*/
    grid.setSelectionMode(SelectionMode.SINGLE);
    grid.setColumns(NAME);
    Grid.Column name = grid.getColumn(NAME);
    name.setHeaderCaption(TRANSLATOR.translate("general.name"));
    name.setConverter(new TranslationConverter());
    grid.setSizeFull();
    vl.addComponent(grid);
    grid.setHeightMode(HeightMode.ROW);
    grid.setHeightByRows(types.size() > 5 ? 5 : types.size());
    //Menu
    HorizontalLayout hl = new HorizontalLayout();
    Button add = new Button(TRANSLATOR.translate("general.create"));
    add.addClickListener(listener -> {
        VMWindow w = new VMWindow();
        w.setContent(new IssueResolutionComponent(new IssueResolution(), true));
        ((VMUI) UI.getCurrent()).addWindow(w);
        w.addCloseListener(l -> {
            ((VMUI) UI.getCurrent()).updateScreen();
        });
    });
    hl.addComponent(add);
    Button delete = new Button(TRANSLATOR.translate("general.delete"));
    delete.setEnabled(false);
    delete.addClickListener(listener -> {
        IssueResolution selected = (IssueResolution) ((SingleSelectionModel) grid.getSelectionModel())
                .getSelectedRow();
        if (selected != null && selected.getId() >= 1000) {
            try {
                new IssueResolutionJpaController(DataBaseManager.getEntityManagerFactory())
                        .destroy(selected.getId());
                ((VMUI) UI.getCurrent()).updateScreen();
            } catch (IllegalOrphanException | NonexistentEntityException ex) {
                LOG.log(Level.SEVERE, null, ex);
                Notification.show(TRANSLATOR.translate(DELETE_ERROR), TRANSLATOR.translate(DELETE_ERROR),
                        Notification.Type.ERROR_MESSAGE);
            }
        }
    });
    hl.addComponent(delete);
    vl.addComponent(hl);
    grid.addSelectionListener(event -> { // Java 8
        // Get selection from the selection model
        IssueResolution selected = (IssueResolution) ((SingleSelectionModel) grid.getSelectionModel())
                .getSelectedRow();
        //Only delete custom ones.
        delete.setEnabled(selected != null && selected.getId() >= 1000);
    });
    return vl;
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.admin.AdminScreenProvider.java

License:Apache License

private Component displayRequirementTypes() {
    VerticalLayout vl = new VerticalLayout();
    Grid grid = new Grid(TRANSLATOR.translate(REQUIREMENT_TYPE));
    BeanItemContainer<RequirementType> types = new BeanItemContainer<>(RequirementType.class);
    types.addAll(new RequirementTypeJpaController(DataBaseManager.getEntityManagerFactory())
            .findRequirementTypeEntities());
    grid.setContainerDataSource(types);//from w ww . j  a  v  a2s.c o  m
    grid.setSelectionMode(SelectionMode.SINGLE);
    grid.setColumns(NAME, DESC);
    Grid.Column name = grid.getColumn(NAME);
    name.setHeaderCaption(TRANSLATOR.translate("general.name"));
    name.setConverter(new TranslationConverter());
    Grid.Column desc = grid.getColumn(DESC);
    desc.setHeaderCaption(TRANSLATOR.translate("general.description"));
    desc.setConverter(new TranslationConverter());
    grid.setSizeFull();
    vl.addComponent(grid);
    grid.setHeightMode(HeightMode.ROW);
    grid.setHeightByRows(types.size() > 5 ? 5 : types.size());
    //Menu
    HorizontalLayout hl = new HorizontalLayout();
    Button add = new Button(TRANSLATOR.translate("general.create"));
    add.addClickListener(listener -> {
        VMWindow w = new VMWindow();
        w.setContent(new RequirementTypeComponent(new RequirementType(), true));
        ((VMUI) UI.getCurrent()).addWindow(w);
        w.addCloseListener(l -> {
            ((VMUI) UI.getCurrent()).updateScreen();
        });
    });
    hl.addComponent(add);
    Button delete = new Button(TRANSLATOR.translate("general.delete"));
    delete.setEnabled(false);
    delete.addClickListener(listener -> {
        RequirementType selected = (RequirementType) ((SingleSelectionModel) grid.getSelectionModel())
                .getSelectedRow();
        if (selected != null && selected.getId() >= 1000) {
            try {
                new RequirementTypeJpaController(DataBaseManager.getEntityManagerFactory())
                        .destroy(selected.getId());
                ((VMUI) UI.getCurrent()).updateScreen();
            } catch (IllegalOrphanException | NonexistentEntityException ex) {
                LOG.log(Level.SEVERE, null, ex);
                Notification.show(TRANSLATOR.translate(DELETE_ERROR), TRANSLATOR.translate(DELETE_ERROR),
                        Notification.Type.ERROR_MESSAGE);
            }
        }
    });
    hl.addComponent(delete);
    vl.addComponent(hl);
    grid.addSelectionListener(event -> { // Java 8
        // Get selection from the selection model
        RequirementType selected = (RequirementType) ((SingleSelectionModel) grid.getSelectionModel())
                .getSelectedRow();
        //Only delete custom ones.
        delete.setEnabled(selected != null && selected.getId() >= 1000);
    });
    return vl;
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.notification.NotificationScreenProvider.java

License:Apache License

@Override
public Component getContent() {
    VerticalLayout vs = new VerticalLayout();
    //On top put a list of notifications
    BeanItemContainer<Notification> container = new BeanItemContainer<>(Notification.class);
    ValidationManagerUI.getInstance().getUser().getNotificationList().forEach(n -> {
        container.addBean(n);//  w  ww.  j av  a  2 s .c  o m
    });
    //        Unable to use VerticalSplitPanel as I hoped.
    //        See: https://github.com/vaadin/framework/issues/9460
    //        VerticalSplitPanel vs = new VerticalSplitPanel();
    //        vs.setSplitPosition(25, Sizeable.Unit.PERCENTAGE);
    TextArea text = new TextArea(TRANSLATOR.translate("general.text"));
    text.setWordwrap(true);
    text.setReadOnly(true);
    text.setSizeFull();
    Grid grid = new Grid(TRANSLATOR.translate("general.notifications"), container);
    grid.setColumns("notificationType", "author", "creationDate", "archieved");
    if (container.size() > 0) {
        grid.setHeightMode(HeightMode.ROW);
        grid.setHeightByRows(container.size() > 5 ? 5 : container.size());
    }
    GridCellFilter filter = new GridCellFilter(grid);
    filter.setBooleanFilter("archieved",
            new GridCellFilter.BooleanRepresentation(VaadinIcons.CHECK, TRANSLATOR.translate("general.yes")),
            new GridCellFilter.BooleanRepresentation(VaadinIcons.CLOSE, TRANSLATOR.translate("general.no")));
    filter.setDateFilter("creationDate",
            new SimpleDateFormat(VMSettingServer.getSetting("date.format").getStringVal()), true);
    grid.sort("creationDate");
    Column nt = grid.getColumn("notificationType");
    nt.setHeaderCaption(TRANSLATOR.translate("notification.type"));
    nt.setConverter(new Converter<String, NotificationType>() {
        @Override
        public NotificationType convertToModel(String value, Class<? extends NotificationType> targetType,
                Locale locale) throws Converter.ConversionException {
            for (NotificationType n : new NotificationTypeJpaController(
                    DataBaseManager.getEntityManagerFactory()).findNotificationTypeEntities()) {
                if (Lookup.getDefault().lookup(InternationalizationProvider.class).translate(n.getTypeName())
                        .equals(value)) {
                    return n;
                }
            }
            return null;
        }

        @Override
        public String convertToPresentation(NotificationType value, Class<? extends String> targetType,
                Locale locale) throws Converter.ConversionException {
            return Lookup.getDefault().lookup(InternationalizationProvider.class)
                    .translate(value.getTypeName());
        }

        @Override
        public Class<NotificationType> getModelType() {
            return NotificationType.class;
        }

        @Override
        public Class<String> getPresentationType() {
            return String.class;
        }
    });
    Column author = grid.getColumn("author");
    author.setConverter(new UserToStringConverter());
    author.setHeaderCaption(TRANSLATOR.translate("notification.author"));
    Column creation = grid.getColumn("creationDate");
    creation.setHeaderCaption(TRANSLATOR.translate("creation.time"));
    Column archive = grid.getColumn("archieved");
    archive.setHeaderCaption(TRANSLATOR.translate("general.archived"));
    archive.setConverter(new Converter<String, Boolean>() {
        @Override
        public Boolean convertToModel(String value, Class<? extends Boolean> targetType, Locale locale)
                throws Converter.ConversionException {
            return value.equals(TRANSLATOR.translate("general.yes"));
        }

        @Override
        public String convertToPresentation(Boolean value, Class<? extends String> targetType, Locale locale)
                throws Converter.ConversionException {
            return value ? TRANSLATOR.translate("general.yes") : TRANSLATOR.translate("general.no");
        }

        @Override
        public Class<Boolean> getModelType() {
            return Boolean.class;
        }

        @Override
        public Class<String> getPresentationType() {
            return String.class;
        }
    });
    grid.setSelectionMode(SelectionMode.SINGLE);
    grid.setSizeFull();
    ContextMenu menu = new ContextMenu(grid, true);
    menu.addItem(TRANSLATOR.translate("notification.mark.unread"), (MenuItem selectedItem) -> {
        Object selected = ((SingleSelectionModel) grid.getSelectionModel()).getSelectedRow();
        if (selected != null) {
            NotificationServer ns = new NotificationServer((Notification) selected);
            ns.setAcknowledgeDate(null);
            try {
                ns.write2DB();
                ((VMUI) UI.getCurrent()).updateScreen();
                ((VMUI) UI.getCurrent()).showTab(getComponentCaption());
            } catch (VMException ex) {
                LOG.log(Level.SEVERE, null, ex);
            }
        }
    });
    menu.addItem(TRANSLATOR.translate("notification.archive"), (MenuItem selectedItem) -> {
        Object selected = ((SingleSelectionModel) grid.getSelectionModel()).getSelectedRow();
        if (selected != null) {
            NotificationServer ns = new NotificationServer((Notification) selected);
            ns.setArchieved(true);
            try {
                ns.write2DB();
                ((VMUI) UI.getCurrent()).updateScreen();
                ((VMUI) UI.getCurrent()).showTab(getComponentCaption());
            } catch (VMException ex) {
                LOG.log(Level.SEVERE, null, ex);
            }
        }
    });
    grid.addSelectionListener(selectionEvent -> {
        // Get selection from the selection model
        Object selected = ((SingleSelectionModel) grid.getSelectionModel()).getSelectedRow();
        if (selected != null) {
            text.setReadOnly(false);
            Notification n = (Notification) selected;
            text.setValue(n.getContent());
            text.setReadOnly(true);
            if (n.getAcknowledgeDate() != null) {
                try {
                    //Mark as read
                    NotificationServer ns = new NotificationServer((Notification) n);
                    ns.setAcknowledgeDate(new Date());
                    ns.write2DB();
                } catch (VMException ex) {
                    LOG.log(Level.SEVERE, null, ex);
                }
            }
        }
    });
    vs.addComponent(grid);
    vs.addComponent(text);
    vs.setSizeFull();
    vs.setId(getComponentCaption());
    return vs;
}

From source file:org.eclipse.hawkbit.ui.artifacts.upload.UploadProgressInfoWindow.java

License:Open Source License

private Grid createGrid() {
    final Grid statusGrid = new Grid(uploads);
    statusGrid.addStyleName(SPUIStyleDefinitions.UPLOAD_STATUS_GRID);
    statusGrid.setId(UIComponentIdProvider.UPLOAD_STATUS_POPUP_GRID);
    statusGrid.setSelectionMode(SelectionMode.NONE);
    statusGrid.setHeaderVisible(true);//  ww  w .  j  a  va  2  s.  c  o  m
    statusGrid.setImmediate(true);
    statusGrid.setSizeFull();
    return statusGrid;
}

From source file:org.eclipse.hawkbit.ui.artifacts.upload.UploadStatusInfoWindow.java

License:Open Source License

private Grid createGrid() {
    final Grid statusGrid = new Grid(uploads);
    statusGrid.addStyleName(SPUIStyleDefinitions.UPLOAD_STATUS_GRID);
    statusGrid.setSelectionMode(SelectionMode.NONE);
    statusGrid.setHeaderVisible(true);/*w  w  w. ja  v a 2  s .  c om*/
    statusGrid.setImmediate(true);
    statusGrid.setSizeFull();
    return statusGrid;
}

From source file:org.eclipse.hawkbit.ui.common.AbstractMetadataPopupLayout.java

License:Open Source License

protected Grid createMetadataGrid() {
    final Grid metadataGrid = new Grid();
    metadataGrid.addStyleName(SPUIStyleDefinitions.METADATA_GRID);
    metadataGrid.setImmediate(true);//from   ww w  .j a v a  2  s.  c o m
    metadataGrid.setHeight("100%");
    metadataGrid.setWidth("100%");
    metadataGrid.setId(UIComponentIdProvider.METDATA_TABLE_ID);
    metadataGrid.setSelectionMode(SelectionMode.SINGLE);
    metadataGrid.setColumnReorderingAllowed(true);
    metadataGrid.setContainerDataSource(getMetadataContainer());
    metadataGrid.getColumn(KEY).setHeaderCaption(i18n.getMessage("header.key"));
    metadataGrid.getColumn(VALUE).setHeaderCaption(i18n.getMessage("header.value"));
    metadataGrid.getColumn(VALUE).setHidden(true);
    metadataGrid.addSelectionListener(this::onRowClick);
    metadataGrid.getColumn(DELETE_BUTTON).setHeaderCaption("");
    metadataGrid.getColumn(DELETE_BUTTON).setRenderer(new HtmlButtonRenderer(this::onDelete));
    metadataGrid.getColumn(DELETE_BUTTON).setWidth(50);
    metadataGrid.getColumn(KEY).setExpandRatio(1);
    return metadataGrid;
}

From source file:org.jpos.qi.QIEntityView.java

License:Open Source License

public Grid createGrid() {
    Grid g = new Grid();
    g.setSizeFull();/* ww w . j  a  v  a 2  s .c  o  m*/
    g.setSelectionMode(Grid.SelectionMode.SINGLE);
    g.setColumnReorderingAllowed(true);
    g.addItemClickListener(event -> {
        navigateToSpecificView(event);
    });
    return g;
}

From source file:org.jumpmind.metl.ui.views.design.ManageProjectsPanel.java

License:Open Source License

protected Component buildVersionGrid(Project project) {
    context.getConfigurationService().refresh(project);
    List<ProjectVersion> versions = project.getProjectVersions();
    BeanItemContainer<ProjectVersion> versionGridContainer = new BeanItemContainer<>(ProjectVersion.class);
    Grid versionGrid = new Grid();

    VerticalLayout layout = new VerticalLayout();
    layout.setWidth(100, Unit.PERCENTAGE);
    layout.setMargin(true);//w w  w  . j ava  2  s  .co m
    layout.setSpacing(true);
    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    Button openButton = new Button("Open", (event) -> {
        Collection<Object> selected = versionGrid.getSelectedRows();
        for (Object object : selected) {
            projectNavigator.addProjectVersion(((ProjectVersion) object));
        }
    });
    buttons.addComponent(openButton);
    Button newButton = new Button("New Version", (event) -> newVersion(versionGrid));
    buttons.addComponent(newButton);
    Button editButton = new Button("Edit Version", (event) -> edit(versionGrid));
    buttons.addComponent(editButton);
    Button removeButton = new Button("Remove Version", (event) -> removeVersion(versionGrid));
    buttons.addComponent(removeButton);

    openButton.setEnabled(false);
    newButton.setEnabled(false);
    removeButton.setEnabled(false);
    editButton.setEnabled(false);

    layout.addComponent(buttons);

    versionGrid.setWidth(100, Unit.PERCENTAGE);
    versionGrid.setHeight(3 + (versions.size() * ROW_EM), Unit.EM);
    versionGrid.setEditorEnabled(true);
    versionGrid.setSelectionMode(SelectionMode.MULTI);

    versionGrid.addColumn("versionLabel", String.class).setHeaderCaption("Version").setExpandRatio(2);
    versionGrid.addColumn("description", String.class).setHeaderCaption("Description").setExpandRatio(1);
    versionGrid.addColumn("readOnly", Boolean.class).setHeaderCaption("Read Only").setMaximumWidth(100)
            .setRenderer(new HtmlRenderer(), new StringToBooleanConverter() {
                private static final long serialVersionUID = 1L;

                protected String getTrueString() {
                    return FontAwesome.CHECK.getHtml();
                };

                protected String getFalseString() {
                    return "";
                };
            });
    versionGrid.addColumn("createTime", Date.class).setHeaderCaption("Create Time").setWidth(185)
            .setMaximumWidth(200).setRenderer(new DateRenderer(UiConstants.DATETIME_FORMAT)).setEditable(false);

    versionGrid.setContainerDataSource(versionGridContainer);
    versionGrid.setEditorFieldFactory(new FieldFactory());

    versionGrid.getEditorFieldGroup().addCommitHandler(new FieldGroup.CommitHandler() {

        private static final long serialVersionUID = 1L;

        @Override
        public void preCommit(CommitEvent commitEvent) throws CommitException {
        }

        @Override
        public void postCommit(CommitEvent commitEvent) throws CommitException {
            ProjectVersion item = (ProjectVersion) versionGrid.getEditedItemId();
            IConfigurationService configurationService = context.getConfigurationService();
            configurationService.save(item);
            projectGrid.markAsDirty();
        }
    });

    versionGrid.addSelectionListener((event) -> {
        int numberSelected = versionGrid.getSelectedRows().size();
        boolean currentlyEditing = projectGrid.getEditedItemId() != null;
        boolean selected = numberSelected > 0 && !currentlyEditing;
        openButton.setEnabled(selected);
        newButton.setEnabled(selected);
        removeButton.setEnabled(selected);
        editButton.setEnabled(selected);
    });
    versionGrid.addItemClickListener(new GridClickListener(versionGrid));
    layout.addComponent(versionGrid);
    layout.setExpandRatio(versionGrid, 1);
    layout.addComponent(new Label(" "));
    versionGridContainer.addAll(versions);
    versionGrid.sort("versionLabel", SortDirection.DESCENDING);

    return layout;
}

From source file:org.jumpmind.vaadin.ui.common.CommonUiUtils.java

License:Open Source License

@SuppressWarnings("unchecked")
public static Grid putResultsInGrid(final ResultSet rs, List<Integer> pkcolumns, int maxResultSize,
        final boolean showRowNumbers, String... excludeValues) throws SQLException {

    final Grid grid = new Grid();
    grid.setImmediate(true);/*from w w  w.  j a  v a 2 s. c  o  m*/
    grid.setSelectionMode(SelectionMode.MULTI);
    grid.setColumnReorderingAllowed(true);
    grid.setData(new HashMap<Object, List<Object>>());

    final ResultSetMetaData meta = rs.getMetaData();
    int columnCount = meta.getColumnCount();
    grid.addColumn("#", Integer.class).setHeaderCaption("#").setHidable(true);
    Set<String> columnNames = new HashSet<String>();
    Set<Integer> skipColumnIndexes = new HashSet<Integer>();
    int[] types = new int[columnCount];
    for (int i = 1; i <= columnCount; i++) {
        String realColumnName = meta.getColumnName(i);
        String columnName = realColumnName;
        if (!Arrays.asList(excludeValues).contains(columnName)) {

            int index = 1;
            while (columnNames.contains(columnName)) {
                columnName = realColumnName + "_" + index++;
            }
            columnNames.add(columnName);

            Class<?> typeClass = Object.class;
            int type = meta.getColumnType(i);
            types[i - 1] = type;
            switch (type) {
            case Types.FLOAT:
            case Types.DOUBLE:
            case Types.NUMERIC:
            case Types.REAL:
            case Types.DECIMAL:
                typeClass = BigDecimal.class;
                break;
            case Types.TINYINT:
            case Types.SMALLINT:
            case Types.BIGINT:
            case Types.INTEGER:
                typeClass = Long.class;
                break;
            case Types.VARCHAR:
            case Types.CHAR:
            case Types.NVARCHAR:
            case Types.NCHAR:
            case Types.CLOB:
                typeClass = String.class;
            default:
                break;
            }
            Column column = grid.addColumn(columnName, typeClass).setHeaderCaption(columnName).setHidable(true);
            if (typeClass.equals(Long.class)) {
                column.setConverter(new StringToLongConverter() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public String convertToPresentation(Long value, Class<? extends String> targetType,
                            Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException {
                        if (value == null) {
                            return NULL_TEXT;
                        } else {
                            return value.toString();
                        }
                    }
                });
            } else if (typeClass.equals(BigDecimal.class)) {
                column.setConverter(new StringToBigDecimalConverter() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public String convertToPresentation(BigDecimal value, Class<? extends String> targetType,
                            Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException {
                        if (value == null) {
                            return NULL_TEXT;
                        } else {
                            return value.toString();
                        }
                    }
                });
            } else {
                column.setConverter(new Converter<String, Object>() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public Object convertToModel(String value, Class<? extends Object> targetType,
                            Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException {
                        return null;
                    }

                    @Override
                    public String convertToPresentation(Object value, Class<? extends String> targetType,
                            Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException {
                        if (value == null) {
                            return NULL_TEXT;
                        } else {
                            return value.toString();
                        }
                    }

                    @Override
                    public Class<Object> getModelType() {
                        return Object.class;
                    }

                    @Override
                    public Class<String> getPresentationType() {
                        return String.class;
                    }

                });
            }
        } else {
            skipColumnIndexes.add(i - 1);
        }

    }
    int rowNumber = 1;
    while (rs.next() && rowNumber <= maxResultSize) {
        Object[] row = new Object[columnNames.size() + 1];
        row[0] = new Integer(rowNumber);
        int rowIndex = 1;
        for (int i = 0; i < columnCount; i++) {
            if (!skipColumnIndexes.contains(i)) {
                Object o = getObject(rs, i + 1);
                int type = types[i];
                switch (type) {
                case Types.FLOAT:
                case Types.DOUBLE:
                case Types.REAL:
                case Types.NUMERIC:
                case Types.DECIMAL:
                    if (o != null && !(o instanceof BigDecimal)) {
                        o = new BigDecimal(castToNumber(o.toString()));
                    }
                    break;
                case Types.TINYINT:
                case Types.SMALLINT:
                case Types.BIGINT:
                case Types.INTEGER:
                    if (o != null && !(o instanceof Long)) {
                        o = new Long(castToNumber(o.toString()));
                    }
                    break;
                default:
                    break;
                }
                List<Object> primaryKeys = new ArrayList<Object>();
                for (Integer pkcolumn : pkcolumns) {
                    primaryKeys.add(getObject(rs, pkcolumn + 1));
                }
                ((HashMap<Object, List<Object>>) grid.getData()).put(o, primaryKeys);
                row[rowIndex] = o;
                rowIndex++;
            }
        }
        grid.addRow(row);
        rowNumber++;
    }

    if (rowNumber < 100) {
        grid.getColumn("#").setWidth(75);
    } else if (rowNumber < 1000) {
        grid.getColumn("#").setWidth(95);
    } else {
        grid.getColumn("#").setWidth(115);
    }

    if (!showRowNumbers) {
        grid.getColumn("#").setHidden(true);
    } else {
        grid.setFrozenColumnCount(1);
    }

    return grid;
}

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

/**
 * Creates a table with datasource of IndexedContainer
 * @return the Grid for InstallationSummary
 *//*www  .  j ava  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;
}