private Grid<HeaderGridRow> formatHeaders(String title, Map<String, List<String>> headers) { Grid<HeaderGridRow> grid = new Grid<>(HeaderGridRow.class); grid.removeAllColumns(); Column<HeaderGridRow, String> headerColumn = grid.addColumn(HeaderGridRow::getHeader) .setCaption("Header") .setExpandRatio(1); Column<HeaderGridRow, String> valuesColumn = grid.addColumn(HeaderGridRow::getValues) .setCaption("Values") .setDescriptionGenerator(HeaderGridRow::getValues) .setExpandRatio(1); grid.setItems(headers.entrySet().stream().map(HeaderGridRow::new)); grid.sort(headerColumn); HeaderRow titleRow = grid.prependHeaderRow(); titleRow.join(headerColumn, valuesColumn).setHtml(title); return grid; }
protected Grid createMetadataGrid() { final Grid metadataGrid = new Grid(); metadataGrid.addStyleName(SPUIStyleDefinitions.METADATA_GRID); metadataGrid.setImmediate(true); 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; }
@Override protected void init(VaadinRequest request) { VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); setContent(layout); Grid grid = new Grid(); initializeGrid(grid); grid.setWidth("700px"); grid.setHeight("500px"); applyDemoHacks(grid); layout.addComponent(grid); }
public void applyToGrid(Grid grid) { final StackTraceElement[] trace = new Exception().getStackTrace(); for (StackTraceElement call : trace) { if (!call.getClassName().contains("au.com.vaadinutils")) { if (call.getClassName().contains(".")) { applyToGrid(grid, call.getClassName().substring(call.getClassName().lastIndexOf("."))); } else { applyToGrid(grid, call.getClassName()); } return; } } throw new RuntimeException("Unable to determine calling class name, " + " use applyToTable(Table table, String uniqueTableId) " + " instead of applyToTable(Table table)"); }
private void printConvocationResponses(List<Attendance> attendances) { List<MemberInfo> attends = attendances.stream() .filter(Attendance::isAttend) .map(MemberInfo::from) .collect(Collectors.toList()); Grid<MemberInfo> attendsGrid = new Grid<>("参加者一覧 (" + attends.size() + ")"); attendsGrid.setItems(attends); attendsGrid.addColumn(MemberInfo::getName).setCaption("名前"); attendsGrid.addColumn(MemberInfo::getComment).setCaption("コメント"); attendsGrid.setWidth(100, Unit.PERCENTAGE); attendsGrid.setHeightByRows(attends.size()); addComponent(attendsGrid); List<MemberInfo> cancels = attendances.stream() .filter(a -> !a.isAttend()) .map(MemberInfo::from) .collect(Collectors.toList()); Grid<MemberInfo> cancelsGrid = new Grid<>("キャンセル一覧 (" + cancels.size() + ")"); cancelsGrid.setItems(cancels); cancelsGrid.addColumn(MemberInfo::getName).setCaption("名前"); cancelsGrid.addColumn(MemberInfo::getComment).setCaption("コメント"); cancelsGrid.setWidth(100, Unit.PERCENTAGE); cancelsGrid.setHeightByRows(cancels.size()); addComponent(cancelsGrid); }
private void printAllMembers() { List<Membership> memberships; try { memberships = membershipService.getAll(); } catch (RuntimeException e) { ErrorView.show("会員一覧の取得に失敗しました。", e); return; } Grid<MemberInfo> membershipGrid = new Grid<>(); membershipGrid.setItems(memberships.stream().map(MemberInfo::from).collect(Collectors.toList())); membershipGrid.addColumn(MemberInfo::getName).setCaption("名前"); membershipGrid.addColumn(MemberInfo::getJavaTerm).setCaption("Java研修"); membershipGrid.addColumn(MemberInfo::getJava8Term).setCaption("Java8研修"); membershipGrid.addColumn(MemberInfo::getGoTerm).setCaption("Go研修"); membershipGrid.setWidth(100, Unit.PERCENTAGE); membershipGrid.setHeightByRows(memberships.size()); addComponent(membershipGrid); }
public DataTablesView() { setFlexDirection(FlexDirection.COLUMN); setAlignSelf(AlignSelf.BASELINE); addStyleName(Margins.All.LARGE); addStyleName(Spacings.Bottom.LARGE); setWidth(100, Unit.PERCENTAGE); Grid g1 = createGrid(); CssLayout c1 = createCard(g1); Grid g2 = createGrid(); DataTableHeader h2 = new DataTableHeader("Nutrition", g2); CssLayout c2 = createCard(h2, g2); addComponents(c1, c2); }
private Grid createGrid() { Grid<Dessert> grid = new Grid<>(); grid.setItems(desserts); grid.setSelectionMode(Grid.SelectionMode.MULTI); grid.setWidth(100, Unit.PERCENTAGE); grid.addColumn(Dessert::getName).setCaption("Dessert (100g serving"); grid.addColumn(Dessert::getCalories).setCaption("Calories"); grid.addColumn(Dessert::getFat).setCaption("Fat (g)"); grid.addColumn(Dessert::getCarbs).setCaption("Carbs (g)"); grid.addColumn(Dessert::getProtein).setCaption("Protein (g)"); grid.addColumn(Dessert::getSodium).setCaption("Sodium (mg)"); grid.addColumn(Dessert::getCalcium).setCaption("Calcium (%)"); grid.addColumn(Dessert::getIron).setCaption("Iron (%)"); grid.setHeight(Metrics.Table.COLUMN_HEADER_HEIGHT + desserts.size() * Metrics.Table.ROW_HEIGHT, Unit.PIXELS); return grid; }
private Component getRestGrid(Collection<MetricsRest> metrics, Series httpSerie) { List<MetricsRest> metricsItems = metrics.stream() .filter(m -> m.valid() && m.getStatus().series() == httpSerie) .collect(Collectors.toList()); if(metricsItems.isEmpty()) { return new Label("No requests"); } else { Grid<MetricsRest> gridCache = new Grid<>(MetricsRest.class); gridCache.removeAllColumns(); gridCache.addColumn(MetricsRest::getName).setCaption("Path").setExpandRatio(1); gridCache.addColumn(m -> m.getStatus() + " " + m.getStatus().getReasonPhrase()).setCaption("HTTP Status"); gridCache.addColumn(MetricsRest::getValue).setCaption("Hits"); gridCache.addColumn(MetricsRest::getLastResponseTime).setCaption("Last Response Time (ms)"); gridCache.setItems(metricsItems); if(metricsItems.size() < 10) { gridCache.setHeightByRows(metricsItems.size()); } gridCache.setWidth(100, Unit.PERCENTAGE); return gridCache; } }
private Grid<MetricsCacheGridRow> getCacheGrid(Collection<MetricsCache> metricsCaches) { List<MetricsCacheGridRow> metricsCacheItems = metricsCaches.stream() .map(MetricsCacheGridRow::new) .collect(Collectors.toList()); Grid<MetricsCacheGridRow> gridCache = new Grid<>(MetricsCacheGridRow.class); gridCache.removeAllColumns(); gridCache.addColumn(MetricsCacheGridRow::getName).setCaption("Name").setExpandRatio(1); gridCache.addColumn(MetricsCacheGridRow::getSize).setCaption("Size"); gridCache.addColumn(MetricsCacheGridRow::getHit).setCaption("Hit"); gridCache.addColumn(MetricsCacheGridRow::getMiss).setCaption("Miss"); gridCache.setItems(metricsCacheItems); gridCache.setHeightByRows(metricsCacheItems.size()); return gridCache; }
private Grid<TraceGridRow> getTracesGrid(List<Trace> traces) { List<TraceGridRow> tracesInfos = traces.stream() .map(TraceGridRow::new) .collect(Collectors.toList()); Grid<TraceGridRow> grid = new Grid<>(TraceGridRow.class); grid.removeAllColumns(); grid.addColumn(TraceGridRow::getTimestamp).setCaption("Date"); grid.addColumn(t -> t.getMethod() + " " + t.getPath()).setCaption("HTTP Request").setExpandRatio(1); grid.addColumn(t -> { if(t.getResponseHttp().isPresent()) { return t.getResponseHttp().get() + " " + t.getResponseHttp().get().getReasonPhrase(); } return ""; }).setCaption("HTTP Response"); grid.addColumn(t -> t.getTimeTaken().isPresent() ? t.getTimeTaken().get().toMillis() : -1).setCaption("Time taken (ms)"); this.requestDetailsPopup(grid); grid.setItems(tracesInfos); grid.setSizeFull(); return grid; }
private void initApplicationsGrid() { grid = new Grid<>(); // Columns grid.removeAllColumns(); Column<Application, String> appColumn = grid.addColumn(Application::getName).setCaption("Application").setExpandRatio(0); Column<Application, String> envColumn = grid.addColumn(Application::getEnvironment).setCaption("Environment").setExpandRatio(0); Column<Application, String> urlColumn = grid.addColumn(Application::getUrl).setCaption("URL").setExpandRatio(1); // Items grid.setItems(applications); // Header filter row initFilterRow(appColumn, envColumn, urlColumn); // Style grid.setStyleGenerator(app -> app.isUp() ? null : "app-down"); grid.addItemClickListener(applicationOnClick()); grid.setSizeFull(); grid.setHeightByRows(applications.size()); grid.sort(appColumn); grid.setRowHeight(40); }
@Override public void setSelectionMode(com.holonplatform.vaadin.components.Selectable.SelectionMode selectionMode) { ObjectUtils.argumentNotNull(selectionMode, "SelectionMode must be not null"); this.selectionMode = selectionMode; switch (selectionMode) { case MULTI: getGrid().setSelectionMode(com.vaadin.ui.Grid.SelectionMode.MULTI); ((MultiSelectionModel<T>) getGrid().getSelectionModel()) .setSelectAllCheckBoxVisibility((selectAllCheckBoxVisibility != null) ? selectAllCheckBoxVisibility : SelectAllCheckBoxVisibility.DEFAULT); break; case NONE: getGrid().setSelectionMode(com.vaadin.ui.Grid.SelectionMode.NONE); break; case SINGLE: getGrid().setSelectionMode(com.vaadin.ui.Grid.SelectionMode.SINGLE); break; default: break; } }
@Bean @Scope(scopeName = "prototype") @SuppressWarnings("unchecked") public <ITEM> Grid<ITEM> configureBeanGrid(DependencyDescriptor dependencyDescriptor) { logger.debug("Configuring Vaadin Grid as bean"); long timestamp = System.currentTimeMillis(); ResolvableType injectionPointType = dependencyDescriptor.getResolvableType(); if (!injectionPointType.hasGenerics()) { throw new IllegalStateException("Grid injection point is expected to declare a static item type"); } ResolvableType genericType = injectionPointType.getGeneric(); Class<ITEM> itemType = (Class<ITEM>) genericType.resolve(); logger.debug("Vaadin Grid will use " + itemType.getCanonicalName() + " as item type"); Grid<ITEM> grid = configureGridInstance(itemType); long configTime = System.currentTimeMillis() - timestamp; logger.debug("Done configuring Grid for " + itemType.getName() + " in " + configTime + "ms"); return grid; }
@PostConstruct public void init() { roleGrid.setWidth("500px"); roleGrid.setHeightMode(HeightMode.UNDEFINED); roleGrid.addColumn(Role::getId).setCaption("Id").setWidth(50); roleGrid.addColumn(Role::getName).setCaption("Name"); roleGrid.setSelectionMode(Grid.SelectionMode.NONE); roleGrid.addStyleName("kumoHandPointer"); addComponents(roleGrid, btnAddNew); roleGrid.addItemClickListener((ItemClickListener<Role>) itemClick -> navigateTo(RoleEditView.VIEW_NAME + "/" + itemClick.getItem().getId())); btnAddNew.addClickListener((Button.ClickListener) clickEvent -> { handler.addNewRole(this); }); }
@Override protected void init(VaadinRequest vaadinRequest) { final VerticalLayout layout = new VerticalLayout(); initMessageTable(); final Grid grid = new Grid(); initGrid(grid); initNavigation(grid); layout.setMargin(true); layout.setSpacing(true); layout.addComponent(grid); layout.addComponent(messageTable); layout.setSizeFull(); setContent(layout); }
public void setHierarchyColumn(Object propertyId) { Column hierarchyColumn = getColumn(propertyId); if (hierarchyColumn == null) { logger.warning(String.format("Column does not exist with propertyId: %s", propertyId.toString())); return; } GridColumnState columnState = null; // Using reflection to access Grid.Column's private getState() method try { Method getStateMethod = Grid.Column.class.getDeclaredMethod("getState"); getStateMethod.setAccessible(true); columnState = (GridColumnState) getStateMethod.invoke(hierarchyColumn); } catch (Exception e) { e.printStackTrace(); } if (columnState != null) { getState().hierarchyColumnId = columnState.id; } }
@Override public void presentTableData(RootResult rootrResult) { ResultToListConverter resultToListConverter = new ResultToListConverter(); List<Result> resultList = resultToListConverter.apply(rootrResult); Collections.sort(resultList, new Inverter<>(new ResultComparator())); Grid<Result> grid = new Grid<>(TABLE_TITLE); grid.addColumn(result -> result.getName()).setCaption(TABLE_COLUMN_METHOD_NAME).setId(TABLE_COLUMN_METHOD_NAME); grid.addColumn(result -> result.getValue() + NONE).setCaption(TABLE_COLUMN_VALUE_NAME) .setId(TABLE_COLUMN_VALUE_NAME); grid.setColumnOrder(TABLE_COLUMN_METHOD_NAME, TABLE_COLUMN_VALUE_NAME); grid.setStyleGenerator(result -> { if (result.getValue() > MAX_ALLOWED_VALUES) return ERROR_STYLE; return NONE; }); grid.setItems(resultList); grid.setSizeFull(); grid.setWidth(70, Unit.REM); mainPanel.addComponent(grid); mainPanel.setComponentAlignment(grid, Alignment.MIDDLE_CENTER); }
@Override protected void init(VaadinRequest request) { // Show it in the middle of the screen final VerticalLayout layout = new VerticalLayout(); layout.setStyleName("demoContentLayout"); layout.setSizeFull(); setContent(layout); Grid grid = new Grid(); grid.addColumn("name", String.class).setHeaderCaption("Name"); grid.addColumn("icon", String.class) .setHeaderCaption("icon") .setRenderer(new FontIconRenderer(e -> Notification.show(e.toString()))); grid.getDefaultHeaderRow().join("name", "icon").setText("Brand"); grid.addRow("Android", FontAwesome.ANDROID.getHtml()); grid.addRow("Ios", FontAwesome.APPLE.getHtml()); grid.addRow("Who cares", FontAwesome.WINDOWS.getHtml()); layout.addComponent(grid); }
/** * Init */ private void init() { // Init the grid with Caption, alternatively can initialize the same // with passing the datasource grid = new Grid("My Basic Grid"); grid.setContainerDataSource(getDatasource()); // new Customer(15432, "Test", new Date(), "myCity") grid.setImmediate(true); initSelectionMode(); initGridProperties(); // Init the columns initGridColumns(); initLabel(); initSelectionListeners(); }
private void generateData(Grid<RowData> g, int cols, int rows) { g.addColumn(RowData::getRowNumber).setCaption("#"); for (int x = 0; x < cols; ++x) { int row = x; g.addColumn(t -> row < t.getValues().length ? t.getValues()[row] : "Empty") .setCaption("Yet another dummy column with extremely long and pointless title " + (x + 1)); } List<RowData> data = new ArrayList<>(); Random r = new Random(); for (int y = 0; y < rows; ++y) { String[] values = new String[cols]; for (int x = 0; x < cols; ++x) { values[x] = "" + r.nextInt() + " babies born last year"; } data.add(new RowData(y, values)); } g.setItems(data); }
public ReleasesView() { setSizeFull(); setMargin(false); ButtonBar buttonBar = new ButtonBar(); addButton = buttonBar.addButton("Add", FontAwesome.PLUS, e -> add()); editButton = buttonBar.addButton("Edit", FontAwesome.EDIT, e -> edit()); exportButton = buttonBar.addButton("Export", FontAwesome.DOWNLOAD, e -> export()); archiveButton = buttonBar.addButton("Archive", FontAwesome.ARCHIVE, e -> archive()); // TODO add support for the archive button archiveButton.setVisible(false); finalizeButton = buttonBar.addButton("Finalize", FontAwesome.CUBE, e -> finalize()); addComponent(buttonBar); enableDisableButtonsForSelectionSize(0); grid = new Grid(); grid.setSizeFull(); grid.setSelectionMode(SelectionMode.MULTI); grid.addItemClickListener(e->rowClicked(e)); grid.addSelectionListener((e) -> rowSelected(e)); container = new BeanItemContainer<>(ReleasePackage.class); grid.setContainerDataSource(container); grid.setColumns("name", "versionLabel", "releaseDate", "released"); grid.sort("releaseDate", SortDirection.DESCENDING); addComponent(grid); setExpandRatio(grid, 1); progressBar = new ProgressBar(0.0f); }
protected void buildGrid() { grid = new Grid(); grid.setSelectionMode(SelectionMode.NONE); grid.setSizeFull(); grid.setEditorEnabled(!readOnly); container = new BeanItemContainer<Record>(Record.class); grid.setContainerDataSource(container); grid.setColumnOrder("entityName", "attributeName", "excelMapping"); HeaderRow filterRow = grid.appendHeaderRow(); addColumn("entityName", filterRow); addColumn("attributeName", filterRow); TextField tfExcelMapping = new TextField(); tfExcelMapping.addBlurListener(e->saveExcelMappingSettings()); tfExcelMapping.setWidth(100, Unit.PERCENTAGE); tfExcelMapping.setImmediate(true); grid.getColumn("excelMapping").setEditorField(tfExcelMapping).setExpandRatio(1); addShowPopulatedFilter("excelMapping", filterRow); grid.setEditorBuffered(false); addComponent(grid); setExpandRatio(grid, 1); }
public FilterableGrid(String caption, Container.Indexed dataSource) { super(caption, dataSource); if (!(dataSource instanceof Container.Filterable)) { throw new IllegalArgumentException("Container must be Filterable"); } setSelectionMode(Grid.SelectionMode.SINGLE); setSizeFull(); setWidth("100%"); setHeight("100%"); makeSearchHeader( (Container.Filterable) dataSource, dataSource.getContainerPropertyIds(), searchFieldRow); }
public void init(String uniqueId, Class<E> entityClazz) { if (!getSecurityManager().canUserView()) { this.setSizeFull(); this.setCompositionRoot(new Label("Sorry, you do not have permission to access " + getTitle())); return; } container = getContainer(); grid = new Grid(new GeneratedPropertyContainer(container)); grid.setSizeFull(); searchBar = buildSearchBar(); mainLayout = new VerticalLayout(); mainLayout.setSizeFull(); addTitle(mainLayout); mainLayout.addComponent(searchBar); mainLayout.addComponent(grid); mainLayout.setExpandRatio(grid, 1); this.setCompositionRoot(mainLayout); headingPropertySet = getHeadingPropertySet(); headingPropertySet.setDeferLoadSettings(true); headingPropertySet.applyToGrid(entityClazz, grid, uniqueId); }
@SuppressWarnings("unchecked") private GeneratedPropertyListContainer<E> wrapGridContainer(final Class<E> entityClass, final Grid grid) { final Indexed gridContainer = grid.getContainerDataSource(); if (gridContainer instanceof GeneratedPropertyListContainer) { return (GeneratedPropertyListContainer<E>) gridContainer; } final GeneratedPropertyListContainer<E> gplc = new GeneratedPropertyListContainer<>(entityClass); gplc.setCollection((Collection<E>) gridContainer.getItemIds()); final Collection<?> containerPropertyIds = gridContainer.getContainerPropertyIds(); if (!containerPropertyIds.isEmpty()) { gplc.setContainerPropertyIds(containerPropertyIds.toArray(new String[containerPropertyIds.size()])); } grid.setContainerDataSource(gplc); return gplc; }
private void createSelectedGrid() { selectedGrid = new Grid(); selectedGrid.setContainerDataSource(createSelectedContainer()); selectedGrid.setWidth(DEFAULT_COLUMN_WIDTH, Unit.PIXELS); selectedGrid.setHeight(DEFAULT_COLUMN_HEIGHT, Unit.PIXELS); selectedGrid.addItemClickListener(new ItemClickListener() { private static final long serialVersionUID = 1L; @Override public void itemClick(ItemClickEvent event) { if (event.isDoubleClick()) { removeButton.click(); } } }); createSelectedHeadings().applyToGrid(selectedGrid); // initialised = true; }
/** * Grid initialization * @param grid Grid to initialize */ protected void initGrid(Grid grid) { // reset selection model grid.setSelectionMode(com.vaadin.ui.Grid.SelectionMode.NONE); grid.setRowStyleGenerator(this); grid.setCellStyleGenerator(this); // editor FieldGroup grid.setEditorFieldGroup(new PropertyGridFieldGroup()); }
private void addDataGrid() { Grid<app.Event> grid = dataGrid.get(); grid.setWidth("100%"); HorizontalLayout bottomLayout = new HorizontalLayout(); bottomLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER); bottomLayout.addComponent(grid); bottomLayout.setWidth("100%"); addComponent(bottomLayout); }
@PostConstruct public void build() { grid = new Grid<>(); grid.addColumn(Event::getId).setCaption("Event ID"); grid.addColumn(Event::getType).setCaption("Event Type"); grid.addColumn(Event::getTime).setCaption("Event Time"); }
@PostConstruct public void build() { grid = new Grid<>(); grid.addColumn(Event::getId).setCaption("ID"); grid.addColumn(Event::getType).setCaption("Type"); grid.addColumn(Event::getTime).setCaption("Time"); }
private Grid<MetricsDatasource> getDatasourceGrid(Collection<MetricsDatasource> metrics) { Grid<MetricsDatasource> grid = new Grid<>(MetricsDatasource.class); grid.removeAllColumns(); grid.addColumn(MetricsDatasource::getName).setCaption("Datasource name").setExpandRatio(1); grid.addColumn(MetricsDatasource::getActiveConnections).setCaption("Active connections"); grid.addColumn(MetricsDatasource::getConnectionPoolUsage).setCaption("Connection pool usage"); grid.setItems(metrics); grid.setHeightByRows(metrics.size()); return grid; }
private Grid<MetricsGridRow> getAllMetricsGrid(Map<String, Number> metrics) { allMetricsRows = metrics.entrySet().stream() .map(MetricsGridRow::new) .collect(Collectors.toList()); Grid<MetricsGridRow> grid = new Grid<>(MetricsGridRow.class); grid.removeAllColumns(); Column<MetricsGridRow, String> nameColumn = grid.addColumn(MetricsGridRow::getName) .setCaption("Name") .setExpandRatio(1); grid.addColumn(MetricsGridRow::getValue).setCaption("Value"); grid.setItems(allMetricsRows); grid.sort(nameColumn); grid.setSizeFull(); grid.setRowHeight(40); TextField filterInput = new TextField(); filterInput.setPlaceholder("filter by metric..."); filterInput.addValueChangeListener(e -> updateMetrics(e.getValue())); filterInput.setValueChangeMode(ValueChangeMode.LAZY); filterInput.setSizeFull(); // Header row HeaderRow filterRow = grid.addHeaderRowAt(grid.getHeaderRowCount()); filterRow.getCell(nameColumn).setComponent(filterInput); return grid; }
/** * Init internal Grid. * @param grid Grid */ protected void initGrid(Grid<T> grid) { this.grid = grid; grid.setWidth(100, Unit.PERCENTAGE); // reset selection model grid.setSelectionMode(com.vaadin.ui.Grid.SelectionMode.NONE); // row style generator grid.setStyleGenerator(i -> generateRowStyle(i)); Editor<T> editor = grid.getEditor(); if (editor != null) { editor.addSaveListener(e -> { if (isBuffered()) { requireDataSource().update(e.getBean()); if (isCommitOnSave()) { requireDataSource().commit(); } } else { requireDataSource().getConfiguration().getCommitHandler().ifPresent(ch -> { ch.commit(Collections.emptySet(), Collections.singleton(e.getBean()), Collections.emptySet()); }); } }); } super.setWidth(100, Unit.PERCENTAGE); addStyleName("h-itemlisting", false); setCompositionRoot(grid); }
@SuppressWarnings("unchecked") private <ITEM, RENDERER_TYPE, PROPERTY_TYPE> void refreshColumnSummary(Grid<ITEM> grid, ColumnDefinition definition) { FooterCell footerCell = grid.getFooterRow(0).getCell(definition.getPropertyName()); footerCell.setStyleName(definition.getColumnAlignment().getAlignmentName()); if (definition.isStaticTextSummarizable()) { String translatedStaticText = gridConfigurationProvider .resolveTranslationKey(definition.getStaticTextSummarizerTranslationKey()); footerCell.setText(translatedStaticText); } else { Summarizer<PROPERTY_TYPE> summarizerFor = getSummarizerFor(definition); if (ListDataProvider.class.isAssignableFrom(grid.getDataProvider().getClass())) { ListDataProvider<ITEM> dataProvider = ListDataProvider.class.cast(grid.getDataProvider()); List<PROPERTY_TYPE> propertyValues = (List<PROPERTY_TYPE>) dataProvider.getItems().stream() .map(item -> invokeRead(definition.getReadMethod(), item)).collect(Collectors.toList()); if (summarizerFor.canSummarize(definition, propertyValues)) { String summaryText = summarizerFor.summarize(definition, propertyValues); footerCell.setText(summaryText); } else { footerCell.setText("-"); } } } }
@Override protected void init(VaadinRequest vaadinRequest) { BeanItemContainer<Workout> container = new BeanItemContainer<>( Workout.class, new WorkoutDataReader().run()); Grid grid = new Grid(); grid.setContainerDataSource(container); grid.getColumn("sport").setRenderer(new ImageRenderer()); grid.setSizeFull(); setContent(grid); }
@PostConstruct public void init() { badgeGrid.setWidth("800px"); badgeGrid.setHeightMode(HeightMode.ROW); badgeGrid.setSelectionMode(Grid.SelectionMode.NONE); badgeGrid.addStyleName("kumoHandPointer"); addComponent(badgeGrid); addComponent(btnAddNew); badgeGrid.addItemClickListener((ItemClickListener<Badge>) itemClick -> navigateTo(BadgeEditView.VIEW_NAME + "/" + itemClick.getItem().getId())); btnAddNew.addClickListener((Button.ClickListener) clickEvent -> { navigateTo(BadgeEditView.VIEW_NAME + "/"); }); }
@Override public void enter(ViewChangeEvent event) { leftLayout = new VerticalLayout(); rightLayout = new VerticalLayout(); infoLayout = new VerticalLayout(); infoLayout.setSpacing(false); infoLayout.setMargin(false); attackButton = new Button("Attaquer", VaadinIcons.SWORD); attackButton.addStyleName(ValoTheme.BUTTON_LARGE); attackButton.addStyleName(ValoTheme.BUTTON_PRIMARY); attackButton.setVisible(false); Grid<Monster> monsterGrid = new Grid<>(); monsterGrid.setSelectionMode(SelectionMode.SINGLE); monsterGrid.addColumn(Monster::getChallengeRating).setCaption("DD").setId("challengeRating"); monsterGrid.addColumn(Monster::getName).setCaption("Nom").setId("name"); monsterGrid.setItems(Services.getMonsterService().findAll()); monsterGrid.addSelectionListener(selection -> { showMonsterInfo(selection.getFirstSelectedItem()); }); leftLayout.addComponent(monsterGrid); rightLayout.addComponents(infoLayout, attackButton); addComponents(leftLayout, rightLayout); setWidth(100, Unit.PERCENTAGE); setExpandRatio(leftLayout, 1); setExpandRatio(rightLayout, 1); }
public SubSetSelector(Class<ET> elementType) { this.elementType = elementType; cb = new ComboBox<>(); grid = new Grid<>(); setHeight("300px"); toprow = new FHorizontalLayout(cb).withWidth("100%"); verticalLayout = new FVerticalLayout(toprow).withMargin(new MarginInfo(true, false)); verticalLayout.addComponentsAndExpand(grid); grid.setHeightByRows(5); grid.setRowHeight(40); grid.setWidth(100, Unit.PERCENTAGE); grid.addComponentColumn(entity -> createDeleteButton(entity)).setWidth(75).setId("Remove"); cb.setPlaceholder("Add to selection..."); cb.setEmptySelectionAllowed(false); cb.addValueChangeListener(new ValueChangeListener<ET>() { private static final long serialVersionUID = 2474890452288971675L; @Override public void valueChange(com.vaadin.data.HasValue.ValueChangeEvent<ET> event) { if (event.getValue() != null) { ET pojo = event.getValue(); C newValue = cloneSelected(); newValue.add(pojo); fireEvent(new ElementAddedEvent<ET>(SubSetSelector.this, pojo)); setValue(newValue); } } }); }