/** * Adds a new text column to this {@link Grid} with a value provider. The * column will use a {@link TextRenderer}. The value is converted to a * String using {@link Object#toString()}. In-memory sorting will use the * natural ordering of elements if they are mutually comparable and * otherwise fall back to comparing the string representations of the * values. * * @param valueProvider * the value provider * * @return the new column */ public <V> Column<T, V> addColumn(ValueProvider<T, V> valueProvider) { return addColumn(valueProvider, new TextRenderer()); }
/** * Adds a new column with the given property name. The column will use a * {@link TextRenderer}. The value is converted to a String using * {@link Object#toString()}. The property name will be used as the * {@link Column#getId() column id} and the {@link Column#getCaption() * column caption} will be set based on the property definition. * <p> * This method can only be used for a <code>Grid</code> created using * {@link Grid#Grid(Class)} or {@link #withPropertySet(PropertySet)}. * <p> * You can add columns for nested properties with dot notation, eg. * <code>"property.nestedProperty"</code> * * @param propertyName * the property name of the new column, not <code>null</code> * @return the newly added column, not <code>null</code> */ public Column<T, ?> addColumn(String propertyName) { return addColumn(propertyName, new TextRenderer()); }
/** * Adds a column that shows components. * <p> * This is a shorthand for {@link #addColum()} with a * {@link ComponentRenderer}. * * @param componentProvider * a value provider that will return a component for the given * item * @return the new column * @param <V> * the column value type, extends component * @since 8.1 */ public <V extends Component> Column<T, V> addComponentColumn( ValueProvider<T, V> componentProvider) { return addColumn(componentProvider, new ComponentRenderer()); }
/** * Adds a new column to this {@link Grid} with typed renderer and value * provider. * * @param valueProvider * the value provider * @param renderer * the column value renderer * @param <V> * the column value type * * @return the new column * * @see AbstractRenderer */ public <V> Column<T, V> addColumn(ValueProvider<T, V> valueProvider, AbstractRenderer<? super T, ? super V> renderer) { return addColumn(valueProvider, ValueProvider.identity(), renderer); }
/** * Adds a new column to this {@link Grid} with value provider and * presentation provider. * <p> * <strong>Note:</strong> The presentation type for this method is set to be * String. To use any custom renderer with the presentation provider, use * {@link #addColumn(ValueProvider, ValueProvider, AbstractRenderer)}. * * @param valueProvider * the value provider * @param presentationProvider * the value presentation provider * @param <V> * the column value type * * @see #addColumn(ValueProvider, ValueProvider, AbstractRenderer) * * @return the new column * @since 8.1 */ public <V> Column<T, V> addColumn(ValueProvider<T, V> valueProvider, ValueProvider<V, String> presentationProvider) { return addColumn(valueProvider, presentationProvider, new TextRenderer()); }
/** * Sets the columns and their order based on their column ids. Columns * currently in this grid that are not present in the list of column ids are * removed. This includes any column that has no id. Similarly, any new * column in columns will be added to this grid. New columns can only be * added for a <code>Grid</code> created using {@link Grid#Grid(Class)} or * {@link #withPropertySet(PropertySet)}. * * * @param columnIds * the column ids to set * * @see Column#setId(String) */ public void setColumns(String... columnIds) { // Must extract to an explicitly typed variable because otherwise javac // cannot determine which overload of setColumnOrder to use Column<T, ?>[] newColumnOrder = Stream.of(columnIds) .map((Function<String, Column<T, ?>>) id -> { Column<T, ?> column = getColumn(id); if (column == null) { column = addColumn(id); } return column; }).toArray(Column[]::new); setColumnOrder(newColumnOrder); // The columns to remove are now at the end of the column list getColumns().stream().skip(columnIds.length) .forEach(this::removeColumn); }
Column<T, V> column = createColumn(valueProvider, presentationProvider, renderer); addColumn(generatedIdentifier, column); return column;
Column<T, ?> column = addColumn(definition.getGetter(), (AbstractRenderer) renderer).setId(definition.getName()) .setCaption(definition.getCaption());
Column<T, ?> column; if (property.isPresent()) { column = addColumn(id); } else { DeclarativeValueProvider<T> provider = new DeclarativeValueProvider<>(); column = createColumn(provider, ValueProvider.identity(), new HtmlRenderer()); addColumn(getGeneratedIdentifier(), column); if (id != null) { column.setId(id);
@Override public void setGridGetters() { Grid<User> g = getGrid(); g.addColumn(User::getId).setId("id"); g.addColumn(User::getName).setId("name"); g.addColumn(User::getNick).setId("nick"); g.addColumn(User::getEmail).setId("email"); g.addColumn(User::isActive).setId("active"); g.addColumn(User::isDeleted).setId("deleted"); g.addColumn(User::isVerified).setId("verified"); g.addColumn(User::getStartDate).setId("startDate"); g.addColumn(User::getEndDate).setId("endDate"); g.addColumn(User::isForcePasswordChange).setId("forcePasswordChange"); g.addColumn(User::getLastLogin).setId("lastLogin"); g.addColumn(User::getPasswordChanged).setId("passwordChanged"); g.addColumn(User::getLoginAttempts).setId("loginAttempts"); }
/** * Add a <em>virtual</em> column to the listing, i.e. a column which is not directly bound to a bean property. * @param <V> Column value type * @param id Column id (not null) * @param type Column value type (not null) * @param valueProvider Column value provider (not null) */ public <V> void addVirtualColumn(String id, Class<V> type, ValueProvider<T, V> valueProvider) { getGrid().addColumn(propertySet.addVirtualProperty(type, valueProvider, id)); }
@Override public void setGridGetters() { Grid<GLTransaction> grid = getGrid(); grid.addColumn(GLTransaction::getId).setId("id"); grid.addColumn(GLTransaction::getDetail).setId("detail"); grid.addColumn(glTransaction -> glTransaction.getJournal().getName()).setId("journal"); grid.addColumn(glTransaction -> postDateFormat.format(glTransaction.getPostDate())).setId("postDate"); grid.addColumn(glTransaction -> glTransaction.getTags() != null ? glTransaction.getTags().toString() : "").setId("tags"); grid.addColumn(GLTransaction::getTimestamp).setId("timestamp"); }
@Override public void setGridGetters() { Grid<Consumer> g = getGrid(); g.addColumn(Consumer::getId).setId("id"); g.addColumn(consumer -> consumer.getRolesAsString()).setId("roles"); g.addColumn(Consumer::getStartDate).setId("startDate"); g.addColumn(Consumer::getEndDate).setId("endDate"); g.addColumn(consumer -> consumer.getUser().getNickAndId()).setId("user"); g.addColumn(Consumer::isActive).setId("active"); g.addColumn(Consumer::isDeleted).setId("deleted"); //select first item on user combobox userComboBox.setValue(userComboBox.getDataProvider().fetch(new Query<>()).findFirst().orElse(null)); }
/** * Adds a column definition which uses given {@link VirtualProperty} value provider to provide the column contents. * @param <T> Property type * @param property Column property * @return if the property was not already present in listing property set and it was added to the set, return the * column name, <code>null</code> otherwise */ public <T> String addColumn(VirtualProperty<T> property) { String name = propertySet.addVirtualProperty(property); if (name != null) { getGrid().addColumn(name); } return name; }
private Grid summaryGrid() { cardSummaryDataProvider = new CardSummaryDataProvider(queryGateway); Grid<CardSummary> grid = new Grid<>(); grid.addColumn(CardSummary::getId).setCaption("Card ID"); grid.addColumn(CardSummary::getInitialValue).setCaption("Initial value"); grid.addColumn(CardSummary::getRemainingValue).setCaption("Remaining value"); grid.setSizeFull(); grid.setDataProvider(cardSummaryDataProvider); return grid; }
private Grid<Cache> createCacheInfoGrid() { Grid<Cache> grid = new Grid<>(); grid.addColumn(Cache::getName).setCaption("Name"); grid.addColumn(cache -> ((Double) (((double) cache.getStatistics().cacheHitCount()) / ((double) (cache.getStatistics().cacheMissCount() + cache.getStatistics().cacheHitCount())) * 100)).intValue() + "%").setCaption("Hit Ratio"); grid.addColumn(cache -> cache.getCacheConfiguration().getMaxEntriesLocalHeap()).setCaption("Max Size"); grid.addColumn(Cache::getSize).setCaption("Size"); grid.addColumn(Cache::getStatus).setCaption("Status"); grid.addColumn(cache -> cache.getCacheConfiguration().getTimeToIdleSeconds()).setCaption("TTldle(s)"); grid.addColumn(cache -> cache.getCacheConfiguration().getTimeToLiveSeconds()).setCaption("TTLive(s)"); grid.addColumn(cache -> cache.getStatistics().cacheHitCount()).setCaption("hit"); grid.addColumn(cache -> cache.getStatistics().cacheMissExpiredCount()).setCaption("miss : Expire"); grid.addColumn(cache -> cache.getStatistics().cacheMissNotFoundCount()).setCaption("miss : Not Found"); grid.setItems(Collections.singletonList(this.ehcache)); grid.setWidth("100%"); grid.setSelectionMode(Grid.SelectionMode.NONE); grid.setHeightByRows(1); return grid; }
@Override public void setVisible(boolean visible) { if (this.visible != visible) { this.visible = visible; Grid<E> grid = owner.getComponent(); if (visible) { Grid.Column<E, ?> gridColumn = grid.addColumn(new EntityValueProvider<>(getPropertyPath())); owner.setupGridColumnProperties(gridColumn, this); grid.setColumnOrder(owner.getColumnOrder()); } else { grid.removeColumn(getId()); setGridColumn(null); } } }
protected void addColumnInternal(ColumnImpl<E> column, int index) { Grid.Column<E, ?> gridColumn = component.addColumn( new EntityValueProvider<>(column.getPropertyPath())); columns.put(column.getId(), column); columnsOrder.add(index, column); final String caption = StringUtils.capitalize(column.getCaption() != null ? column.getCaption() : generateColumnCaption(column)); column.setCaption(caption); if (column.getOwner() == null) { column.setOwner(this); } MetaPropertyPath propertyPath = column.getPropertyPath(); if (propertyPath != null) { MetaProperty metaProperty = propertyPath.getMetaProperty(); MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath); String storeName = metadataTools.getStoreName(propertyMetaClass); if (metadataTools.isLob(metaProperty) && !persistenceManagerClient.supportsLobSortingAndFiltering(storeName)) { column.setSortable(false); } } setupGridColumnProperties(gridColumn, column); component.setColumnOrder(getColumnOrder()); }