Example usage for com.vaadin.ui Grid setHeight

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

Introduction

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

Prototype

@Override
public void setHeight(float height, Unit unit) 

Source Link

Document

Note: This method will set the height mode to be HeightMode#CSS .

Usage

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 ww .jav  a2 s  . c o  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.metl.ui.views.design.ManageProjectsPanel.java

License:Open Source License

protected void newVersion(Grid grid) {
    Collection<Object> selected = grid.getSelectedRows();
    if (selected.size() == 1) {
        IConfigurationService configurationService = context.getConfigurationService();
        ProjectVersion originalVersion = (ProjectVersion) selected.iterator().next();
        PromptDialog.prompt("New Version",
                String.format("Copying version '%s' of '%s'. What do you want to name new version?",
                        originalVersion.getVersionLabel(), originalVersion.getProject().getName()),
                (newVersionLabel) -> {
                    if (StringUtils.isNotBlank(newVersionLabel)) {
                        ProjectVersion newVersion = configurationService.saveNewVersion(newVersionLabel,
                                originalVersion);
                        Indexed indexed = grid.getContainerDataSource();
                        indexed.addItemAfter(originalVersion, newVersion);
                        grid.setHeight(grid.getHeight() + ROW_EM, Unit.EM);
                        return true;
                    } else {
                        NotifyDialog.show("Please specify a version number", "Please specify a version number",
                                null, Type.WARNING_MESSAGE);
                        return false;
                    }//from   w w w.j a va  2s. c o m
                });
    }

}

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

License:Open Source License

protected void removeVersion(Grid grid) {
    ConfirmDialog.show("Delete Version(s)?", "Are you sure you want to delete the selected version(s)?", () -> {
        Collection<Object> selected = grid.getSelectedRows();
        for (Object object : selected) {
            ProjectVersion item = (ProjectVersion) object;
            grid.getContainerDataSource().removeItem(item);
            item.setDeleted(true);//from  w  w w .  jav a 2  s  .  c  om
            context.getConfigurationService().save(item);
        }
        grid.setHeight(grid.getHeight() - (ROW_EM * selected.size()), Unit.EM);
        sort();
        setButtonsEnabled();
        return true;
    });
}

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

private void setGridHeight(Grid grid, int size) {
    grid.setWidth("100%");
    if (size == 0)
        // FIXME in case of an empty grid, the grid should be omitted and a "Nothing to see here" message should be displayed.
        // Right now only a empty grid is displayed to the user. The height of 39 is the height of the grid header
        grid.setHeight(39, Sizeable.Unit.PIXELS);
    else/*from w  w w .j a v  a2 s  . c om*/
        grid.setHeightByRows(size);
}