List of usage examples for com.vaadin.ui Grid setColumns
public void setColumns(String... columnIds)
From source file:de.datenhahn.vaadin.componentrenderer.demo.NotABeanGridWithDecoratorTab.java
License:Apache License
private void init() { setSizeFull();//from w ww. ja va2 s.c om setMargin(true); setSpacing(true); addComponent( new Label("Look at the sourcecode to see the difference between the typed ComponentGrid and using" + " the classic grid")); Grid grid = new Grid(); grid.addColumn("foo"); grid.addRow("1"); grid.addRow("2"); grid.addRow("3"); grid.addRow("4"); ComponentGridDecorator componentGridDecorator = new ComponentGridDecorator<>(grid, null); addComponent(ViewComponents.createEnableDisableCheckBox(grid)); grid.setSizeFull(); // Initialize DetailsGenerator (Caution: the DetailsGenerator is set to null // when grid#setContainerDatasource is called, so make sure you call setDetailsGenerator // after setContainerDatasource grid.setDetailsGenerator(new CustomerDetailsGenerator()); componentGridDecorator.addComponentColumn("Just some", e -> new Label("some" + e)); grid.setColumns("Just some"); addComponent(grid); setExpandRatio(grid, 1.0f); }
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 .j ava 2s .co 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; }