List of usage examples for com.vaadin.ui Grid setHeightMode
public void setHeightMode(HeightMode heightMode)
From source file:fi.semantum.strategia.Updates.java
License:Open Source License
private static void updateQueryGrid(final Main main, final FilterState state) { main.gridPanelLayout.removeAllComponents(); main.gridPanelLayout.setMargin(false); final List<String> keys = state.reportColumns; if (keys.isEmpty()) { Label l = new Label("Kysely ei tuottanut yhtn tulosta."); l.addStyleName(ValoTheme.LABEL_BOLD); l.addStyleName(ValoTheme.LABEL_HUGE); main.gridPanelLayout.addComponent(l); return;/*from www . j a v a2 s.c o m*/ } final IndexedContainer container = new IndexedContainer(); for (String key : keys) { container.addContainerProperty(key, String.class, ""); } rows: for (Map<String, ReportCell> map : state.report) { Object item = container.addItem(); for (String key : keys) if (map.get(key) == null) continue rows; for (Map.Entry<String, ReportCell> entry : map.entrySet()) { @SuppressWarnings("unchecked") com.vaadin.data.Property<String> p = container.getContainerProperty(item, entry.getKey()); p.setValue(entry.getValue().get()); } } HorizontalLayout hl = new HorizontalLayout(); hl.setWidth("100%"); final TextField filter = new TextField(); filter.addStyleName(ValoTheme.TEXTFIELD_TINY); filter.setInputPrompt("rajaa hakutuloksia - kirjoitetun sanan tulee lyty rivin teksteist"); filter.setWidth("100%"); final Image clipboard = new Image(); clipboard.setSource(new ThemeResource("page_white_excel.png")); clipboard.setHeight("24px"); clipboard.setWidth("24px"); hl.addComponent(filter); hl.setExpandRatio(filter, 1.0f); hl.setComponentAlignment(filter, Alignment.BOTTOM_CENTER); hl.addComponent(clipboard); hl.setComponentAlignment(clipboard, Alignment.BOTTOM_CENTER); hl.setExpandRatio(clipboard, 0.0f); main.gridPanelLayout.addComponent(hl); main.gridPanelLayout.setExpandRatio(hl, 0f); filter.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 3033918399018888150L; @Override public void valueChange(ValueChangeEvent event) { container.removeAllContainerFilters(); container.addContainerFilter(new QueryFilter(filter.getValue(), true, false)); } }); AbsoluteLayout abs = new AbsoluteLayout(); abs.setSizeFull(); final Grid queryGrid = new Grid(container); queryGrid.setSelectionMode(SelectionMode.NONE); queryGrid.setHeightMode(HeightMode.CSS); queryGrid.setHeight("100%"); queryGrid.setWidth("100%"); for (String key : keys) { Column col = queryGrid.getColumn(key); col.setExpandRatio(1); } abs.addComponent(queryGrid); OnDemandFileDownloader dl = new OnDemandFileDownloader(new OnDemandStreamSource() { private static final long serialVersionUID = 981769438054780731L; File f; Date date = new Date(); @Override public InputStream getStream() { String uuid = UUID.randomUUID().toString(); File printing = new File(Main.baseDirectory(), "printing"); f = new File(printing, uuid + ".xlsx"); Workbook w = new XSSFWorkbook(); Sheet sheet = w.createSheet("Sheet1"); Row header = sheet.createRow(0); for (int i = 0; i < keys.size(); i++) { Cell cell = header.createCell(i); cell.setCellValue(keys.get(i)); } int row = 1; rows: for (Map<String, ReportCell> map : state.report) { for (String key : keys) if (map.get(key) == null) continue rows; Row r = sheet.createRow(row++); int column = 0; for (int i = 0; i < keys.size(); i++) { Cell cell = r.createCell(column++); ReportCell rc = map.get(keys.get(i)); cell.setCellValue(rc.getLong()); } } try { FileOutputStream s = new FileOutputStream(f); w.write(s); s.close(); } catch (Exception e) { e.printStackTrace(); } try { return new FileInputStream(f); } catch (FileNotFoundException e) { e.printStackTrace(); } throw new IllegalStateException(); } @Override public void onRequest() { // TODO Auto-generated method stub } @Override public long getFileSize() { return f.length(); } @Override public String getFileName() { return "Strategiakartta_" + Utils.dateString(date) + ".xlsx"; } }); dl.getResource().setCacheTime(0); dl.extend(clipboard); main.gridPanelLayout.addComponent(abs); main.gridPanelLayout.setExpandRatio(abs, 1f); }
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);/*ww w. j a v a 2s . com*/ 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 w w w . j av 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 ww w . j a v a2 s . 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);//from www . j a v a 2s .c om }); // 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
/** * Creates a table with datasource of IndexedContainer * @return the Grid for InstallationSummary *///from w w w .ja v a 2s. 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.vaadin.gridfiledownloadertest.GridFileDownloaderUI.java
License:Apache License
@SuppressWarnings("unchecked") @Override//from w ww . j a va 2s.c om 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(""); }