Example usage for com.vaadin.ui Grid addSelectionListener

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

Introduction

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

Prototype

public Registration addSelectionListener(SelectionListener<T> listener) throws UnsupportedOperationException 

Source Link

Document

Adds a selection listener to the current selection model.

Usage

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);/*  w  w w. ja v  a 2s  . 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.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);//from   w w w .jav a2 s  .c om
    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:probe.com.view.core.MultiSelectionTable.java

/**
 *
 *///from   w  w w.  j av a2s  .c  om

public MultiSelectionTable() {
    setSpacing(true);
    // Set up combo boxes with possible values         
    setWidth(100, Unit.PERCENTAGE);
    // Editor is not enabled when
    setEnabled(false);

    Indexed datares = new BeanContainer(null);

    // Create new Grid with BeanItemContainer filled with BugEntries
    Grid grid = new Grid(datares);
    grid.setSizeFull();

    // Hide the "changed" property
    grid.removeColumn("changed");

    // Activate multi selection mode
    grid.setSelectionMode(SelectionMode.MULTI);

    // Add a rowstyle generator to display recently changed items.
    // Also uses another style for closed entries
    grid.setRowStyleGenerator(new RowStyleGenerator() {

        @Override
        public String getStyle(RowReference rowReference) {
            Item item = rowReference.getItem();
            boolean closed = item.getItemProperty("status").getValue() == Status.CLOSED;
            boolean changed = (Boolean) item.getItemProperty("changed").getValue();
            if (closed) {
                if (changed) {
                    // Combined style
                    return "changed closed";
                }
                // Closed style
                return "closed";
            } else if (changed) {
                // Modified style
                return "changed";
            }
            // No style
            return null;
        }
    });

    // Make Editor listen to changes in the selection of this Grid
    grid.addSelectionListener(this);

}