Example usage for com.vaadin.ui Grid setHeightByRows

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

Introduction

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

Prototype

public void setHeightByRows(double rows) 

Source Link

Document

Sets the number of rows that should be visible in Grid's body.

Usage

From source file:com.rex.components.valo.Tables.java

License:Apache License

static void configure(Table table, Grid grid, boolean footer, boolean sized, boolean expandRatios,
        boolean stripes, boolean verticalLines, boolean horizontalLines, boolean borderless, boolean headers,
        boolean compact, boolean small, boolean rowIndex, boolean rowCaption, boolean rowIcon,
        boolean componentsInRows) {

    table.setSelectable(true);//from w  w  w  .  ja  va 2 s . com
    table.setMultiSelect(true);
    grid.setSelectionMode(SelectionMode.MULTI);

    table.setSortEnabled(true);
    for (Column c : grid.getColumns()) {
        if (!c.getPropertyId().equals("icon")) {
            c.setSortable(true);
        }
        c.setHidable(true);
    }

    table.setColumnCollapsingAllowed(true);
    table.setColumnReorderingAllowed(true);
    grid.setColumnReorderingAllowed(true);

    table.setPageLength(6);
    grid.setHeightByRows(6);

    table.addActionHandler(ReportEngineUI.getActionHandler());
    table.setDragMode(TableDragMode.MULTIROW);
    table.setDropHandler(new DropHandler() {
        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }

        @Override
        public void drop(DragAndDropEvent event) {
            Notification.show(event.getTransferable().toString());
        }
    });
    table.setColumnAlignment(ReportEngineUI.DESCRIPTION_PROPERTY, Align.RIGHT);
    table.setColumnAlignment(ReportEngineUI.INDEX_PROPERTY, Align.CENTER);

    table.removeContainerProperty("textfield");
    table.removeGeneratedColumn("textfield");
    table.removeContainerProperty("button");
    table.removeGeneratedColumn("button");
    table.removeContainerProperty("label");
    table.removeGeneratedColumn("label");
    table.removeContainerProperty("checkbox");
    table.removeGeneratedColumn("checkbox");
    table.removeContainerProperty("datefield");
    table.removeGeneratedColumn("datefield");
    table.removeContainerProperty("combobox");
    table.removeGeneratedColumn("combobox");
    table.removeContainerProperty("optiongroup");
    table.removeGeneratedColumn("optiongroup");
    table.removeContainerProperty("slider");
    table.removeGeneratedColumn("slider");
    table.removeContainerProperty("progress");
    table.removeGeneratedColumn("progress");

    if (componentsInRows) {
        table.addContainerProperty("textfield", TextField.class, null);
        table.addGeneratedColumn("textfield", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                TextField tf = new TextField();
                tf.setInputPrompt("Type here");
                // tf.addStyleName("compact");
                if ((Integer) itemId % 2 == 0) {
                    tf.addStyleName("borderless");
                }
                return tf;
            }
        });

        table.addContainerProperty("datefield", TextField.class, null);
        table.addGeneratedColumn("datefield", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                DateField tf = new DateField();
                tf.addStyleName("compact");
                if ((Integer) itemId % 2 == 0) {
                    tf.addStyleName("borderless");
                }
                return tf;
            }
        });

        table.addContainerProperty("combobox", TextField.class, null);
        table.addGeneratedColumn("combobox", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                ComboBox tf = new ComboBox();
                tf.setInputPrompt("Select");
                tf.addStyleName("compact");
                if ((Integer) itemId % 2 == 0) {
                    tf.addStyleName("borderless");
                }
                return tf;
            }
        });

        table.addContainerProperty("button", Button.class, null);
        table.addGeneratedColumn("button", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                Button b = new Button("Button");
                b.addStyleName("small");
                return b;
            }
        });

        table.addContainerProperty("label", TextField.class, null);
        table.addGeneratedColumn("label", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                Label label = new Label("Label component");
                label.setSizeUndefined();
                label.addStyleName("bold");
                return label;
            }
        });

        table.addContainerProperty("checkbox", TextField.class, null);
        table.addGeneratedColumn("checkbox", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                CheckBox cb = new CheckBox(null, true);
                return cb;
            }
        });

        table.addContainerProperty("optiongroup", TextField.class, null);
        table.addGeneratedColumn("optiongroup", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                OptionGroup op = new OptionGroup();
                op.addItem("Male");
                op.addItem("Female");
                op.addStyleName("horizontal");
                return op;
            }
        });

        table.addContainerProperty("slider", TextField.class, null);
        table.addGeneratedColumn("slider", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                Slider s = new Slider();
                s.setValue(30.0);
                return s;
            }
        });

        table.addContainerProperty("progress", TextField.class, null);
        table.addGeneratedColumn("progress", new ColumnGenerator() {
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                ProgressBar bar = new ProgressBar();
                bar.setValue(0.7f);
                return bar;
            }
        });
    }
    table.setFooterVisible(footer);
    if (footer) {
        table.setColumnFooter(ReportEngineUI.CAPTION_PROPERTY, "caption");
        table.setColumnFooter(ReportEngineUI.DESCRIPTION_PROPERTY, "description");
        table.setColumnFooter(ReportEngineUI.ICON_PROPERTY, "icon");
        table.setColumnFooter(ReportEngineUI.INDEX_PROPERTY, "index");
    }

    if (sized) {
        table.setWidth("400px");
        grid.setWidth("400px");
        table.setHeight("300px");
        grid.setHeight("300px");
    } else {
        table.setSizeUndefined();
        grid.setSizeUndefined();
    }

    if (componentsInRows) {
        table.setWidth("100%");
    } else {
        table.setWidth(null);
    }

    if (expandRatios) {
        if (!sized) {
            table.setWidth("100%");
        }
    }
    table.setColumnExpandRatio(ReportEngineUI.CAPTION_PROPERTY, expandRatios ? 1.0f : 0);
    table.setColumnExpandRatio(ReportEngineUI.DESCRIPTION_PROPERTY, expandRatios ? 1.0f : 0);

    if (!stripes) {
        table.addStyleName("no-stripes");
    } else {
        table.removeStyleName("no-stripes");
    }

    if (!verticalLines) {
        table.addStyleName("no-vertical-lines");
    } else {
        table.removeStyleName("no-vertical-lines");
    }

    if (!horizontalLines) {
        table.addStyleName("no-horizontal-lines");
    } else {
        table.removeStyleName("no-horizontal-lines");
    }

    if (borderless) {
        table.addStyleName("borderless");
    } else {
        table.removeStyleName("borderless");
    }

    if (!headers) {
        table.addStyleName("no-header");
    } else {
        table.removeStyleName("no-header");
    }

    if (compact) {
        table.addStyleName("compact");
    } else {
        table.removeStyleName("compact");
    }

    if (small) {
        table.addStyleName("small");
    } else {
        table.removeStyleName("small");
    }

    if (!rowIndex && !rowCaption && rowIcon) {
        table.setRowHeaderMode(RowHeaderMode.HIDDEN);
    }

    if (rowIndex) {
        table.setRowHeaderMode(RowHeaderMode.INDEX);
    }

    if (rowCaption) {
        table.setRowHeaderMode(RowHeaderMode.PROPERTY);
        table.setItemCaptionPropertyId(ReportEngineUI.CAPTION_PROPERTY);
    } else {
        table.setItemCaptionPropertyId(null);
    }

    if (rowIcon) {
        table.setRowHeaderMode(RowHeaderMode.ICON_ONLY);
        table.setItemIconPropertyId(ReportEngineUI.ICON_PROPERTY);
    } else {
        table.setItemIconPropertyId(null);
    }
}

From source file:dhbw.clippinggorilla.userinterface.views.AboutUsView.java

public AboutUsView() {
    setMargin(true);/*from  w w w . j  a  v  a2 s.  c  o m*/
    setWidth("55%");

    Label aboutUsHeader = new Label();
    Language.set(Word.ABOUT_US, aboutUsHeader);
    aboutUsHeader.setStyleName(ValoTheme.LABEL_H1);
    addComponent(aboutUsHeader);

    Label aboutUsGroupHeadline = new Label();
    Language.set(Word.GROUP_PROJECT_OF_GROUP_4, aboutUsGroupHeadline);
    aboutUsGroupHeadline.setStyleName(ValoTheme.LABEL_H2);
    addComponent(aboutUsGroupHeadline);

    Label aboutUsText = new Label();
    Language.set(Word.GROUP_PROJECT_BODY, aboutUsText);
    aboutUsText.setWidth("100%");
    aboutUsText.setContentMode(com.vaadin.shared.ui.ContentMode.HTML);
    addComponent(aboutUsText);

    Label theTeamHeader = new Label();
    Language.set(Word.OUR_TEAM, theTeamHeader);
    theTeamHeader.setStyleName(ValoTheme.LABEL_H2);
    addComponent(theTeamHeader);

    Grid<Person> theTeamGrid = new Grid<>();
    List<Person> persons = Arrays.asList(new Person("Dan-Pierre", "Drehlich", Person.Function.TEAMLEADER),
            new Person("Stefan", "Schmid", Person.Function.RESPONSIBLE_FOR_RESEARCH),
            new Person("Jan", "Striegel", Person.Function.TECHNICAL_ASSISTANT),
            new Person("Lisa", "Hartung",
                    Person.Function.RESPONSIBLE_FOR_MODELING_QUALITY_ASSURANCE_AND_DOCUMENTATION),
            new Person("Tim", "Heinzelmann", Person.Function.RESPONSIBLE_FOR_TESTS),
            new Person("Josua", "Frank", Person.Function.RESPONSIBLE_FOR_IMPLEMENTATION));
    Grid.Column c1 = theTeamGrid.addColumn(p -> p.getFirstName());
    Language.setCustom(Word.FIRST_NAME, s -> c1.setCaption(s));
    Grid.Column c2 = theTeamGrid.addColumn(p -> p.getLastName());
    Language.setCustom(Word.LAST_NAME, s -> c2.setCaption(s));
    Grid.Column c3 = theTeamGrid.addColumn(p -> p.getResposibility());
    Language.setCustom(Word.RESPONSIBILITY, s -> {
        c3.setCaption(s);
        theTeamGrid.getDataProvider().refreshAll();
    });
    theTeamGrid.setItems(persons);
    theTeamGrid.setWidth("100%");
    theTeamGrid.setHeightByRows(6);
    addComponent(theTeamGrid);
    SESSIONS.put(VaadinSession.getCurrent(), this);
}

From source file:dhbw.clippinggorilla.userinterface.views.ImpressumView.java

public ImpressumView() {
    setMargin(true);//from  w  w  w .jav  a2 s .  com
    setWidth("55%");

    Label impressumHeader = new Label();
    Language.set(Word.IMPRESSUM, impressumHeader);
    impressumHeader.setStyleName(ValoTheme.LABEL_H1);
    addComponent(impressumHeader);

    Label impressumText = new Label();
    Language.set(Word.IMPRESSUM_BODY, impressumText);
    impressumText.setWidth("100%");
    impressumText.setContentMode(com.vaadin.shared.ui.ContentMode.HTML);
    addComponent(impressumText);

    Grid<Person> studentsGrid = new Grid<>();
    List<Person> persons = Arrays.asList(new Person("Dan-Pierre", "Drehlich", Person.Function.TEAMLEADER),
            new Person("Stefan", "Schmid", Person.Function.RESPONSIBLE_FOR_RESEARCH),
            new Person("Jan", "Striegel", Person.Function.TECHNICAL_ASSISTANT),
            new Person("Lisa", "Hartung",
                    Person.Function.RESPONSIBLE_FOR_MODELING_QUALITY_ASSURANCE_AND_DOCUMENTATION),
            new Person("Tim", "Heinzelmann", Person.Function.RESPONSIBLE_FOR_TESTS),
            new Person("Josua", "Frank", Person.Function.RESPONSIBLE_FOR_IMPLEMENTATION));
    Column c1 = studentsGrid.addColumn(p -> p.getFirstName());
    Language.setCustom(Word.FIRST_NAME, s -> c1.setCaption(s));
    Column c2 = studentsGrid.addColumn(p -> p.getLastName());
    Language.setCustom(Word.LAST_NAME, s -> c2.setCaption(s));
    Column c3 = studentsGrid.addColumn(p -> p.getResposibility());
    Language.setCustom(Word.RESPONSIBILITY, s -> {
        c3.setCaption(s);
        studentsGrid.getDataProvider().refreshAll();
    });

    studentsGrid.setItems(persons);
    studentsGrid.setWidth("100%");
    studentsGrid.setHeightByRows(6);
    addComponent(studentsGrid);

    Label liabilityHeadline = new Label();
    Language.set(Word.LIABILITY, liabilityHeadline);
    liabilityHeadline.setStyleName(ValoTheme.LABEL_H1);
    addComponent(liabilityHeadline);

    Label liabilityContentHeadline = new Label();
    Language.set(Word.LIABILITY_CONTENT, liabilityContentHeadline);
    liabilityContentHeadline.setStyleName(ValoTheme.LABEL_H2);
    addComponent(liabilityContentHeadline);

    Label liabilityContentText = new Label();
    Language.set(Word.LIABILITY_CONTENT_BODY, liabilityContentText);
    liabilityContentText.setWidth("100%");
    addComponent(liabilityContentText);

    Label liabilityLinksHeadline = new Label();
    Language.set(Word.LIABILITY_LINKS, liabilityLinksHeadline);
    liabilityLinksHeadline.setStyleName(ValoTheme.LABEL_H2);
    addComponent(liabilityLinksHeadline);

    Label liabilityLinksText = new Label();
    Language.set(Word.LIABILITY_LINKS_BODY, liabilityLinksText);
    liabilityLinksText.setWidth("100%");
    addComponent(liabilityLinksText);

    Label copyrightHeadline = new Label();
    Language.set(Word.COPYRIGHT, copyrightHeadline);
    copyrightHeadline.setStyleName(ValoTheme.LABEL_H2);
    addComponent(copyrightHeadline);

    Label copyrightText = new Label();
    Language.set(Word.COPYRIGHT_BODY, copyrightText);
    copyrightText.setWidth("100%");
    addComponent(copyrightText);

    Label dataProtectionHeadline = new Label();
    Language.set(Word.DATAPROTECTION, dataProtectionHeadline);
    dataProtectionHeadline.setStyleName(ValoTheme.LABEL_H2);
    addComponent(dataProtectionHeadline);

    Label dataProtectionText = new Label();
    Language.set(Word.DATAPROTECTION_BODY, dataProtectionText);
    dataProtectionText.setWidth("100%");
    addComponent(dataProtectionText);
    SESSIONS.put(VaadinSession.getCurrent(), this);
}

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

License:Apache License

private Component displayIssueTypes() {
    VerticalLayout vl = new VerticalLayout();
    Grid grid = new Grid(TRANSLATOR.translate(ISSUE_TYPE));
    BeanItemContainer<IssueType> types = new BeanItemContainer<>(IssueType.class);
    types.addAll(new IssueTypeJpaController(DataBaseManager.getEntityManagerFactory()).findIssueTypeEntities());
    grid.setContainerDataSource(types);//from   w w  w.j  a  va2  s  .c om
    grid.setSelectionMode(SelectionMode.SINGLE);
    grid.setColumns("typeName", DESC);
    Grid.Column name = grid.getColumn("typeName");
    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 IssueTypeComponent(new IssueType(), 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 -> {
        IssueType selected = (IssueType) ((SingleSelectionModel) grid.getSelectionModel()).getSelectedRow();
        if (selected != null && selected.getId() >= 1000) {
            try {
                new IssueTypeJpaController(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
        IssueType selected = (IssueType) ((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 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  v  a2  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  www . j av a 2  s.com
    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 w w  .  ja  v  a2s  . 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.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/*  w w  w  .  j  a va 2s  .c om*/
        grid.setHeightByRows(size);
}

From source file:org.vaadin.gridfiledownloadertest.GridFileDownloaderUI.java

License:Apache License

@SuppressWarnings("unchecked")
@Override/*from  w  w  w  .j a v  a  2 s . co  m*/
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    setContent(layout);

    final Grid grid = new Grid("Attachment grid");
    grid.setHeightMode(HeightMode.ROW);
    grid.setHeightByRows(5);
    grid.setSelectionMode(SelectionMode.NONE);

    Column column = grid.addColumn("filename");
    column.setHeaderCaption("File name");
    column.setExpandRatio(1);

    Indexed dataSource = grid.getContainerDataSource();
    for (int i = 1; i <= 5; ++i) {
        DownloadPojo cp = new DownloadPojo(i);
        Item item = dataSource.addItem(cp);
        item.getItemProperty("filename").setValue(cp.getName());
    }
    layout.addComponent(grid);
    addGridFileDownloader(grid);

    // set tooltip for the default download column
    grid.setCellDescriptionGenerator(new CellDescriptionGenerator() {

        @Override
        public String getDescription(CellReference cell) {
            if (FontAwesome.DOWNLOAD.equals(cell.getPropertyId())) {
                return "download";
            }
            return null;
        }
    });

    // clear the header
    HeaderCell downloadHeader = grid.getHeaderRow(0).getCell(FontAwesome.DOWNLOAD);
    downloadHeader.setHtml("");
}