本文整理了Java中com.vaadin.ui.Grid
类的一些代码示例,展示了Grid
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Grid
类的具体详情如下:
包路径:com.vaadin.ui.Grid
类名称:Grid
[英]A grid component for displaying tabular data.
[中]用于显示表格数据的网格组件。
代码示例来源:origin: com.vaadin/vaadin-server
/**
* 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);
}
代码示例来源:origin: com.vaadin/vaadin-server
@Override
protected void doReadDesign(Element design, DesignContext context) {
Attributes attrs = design.attributes();
if (design.hasAttr(DECLARATIVE_DATA_ITEM_TYPE)) {
String itemType = design.attr(DECLARATIVE_DATA_ITEM_TYPE);
setBeanType(itemType);
}
if (attrs.hasKey("selection-mode")) {
setSelectionMode(DesignAttributeHandler.readAttribute(
"selection-mode", attrs, SelectionMode.class));
}
Attributes attr = design.attributes();
if (attr.hasKey("selection-allowed")) {
setReadOnly(DesignAttributeHandler
.readAttribute("selection-allowed", attr, Boolean.class));
}
if (attrs.hasKey("rows")) {
setHeightByRows(DesignAttributeHandler.readAttribute("rows", attrs,
double.class));
}
readStructure(design, context);
// Read frozen columns after columns are read.
if (attrs.hasKey("frozen-columns")) {
setFrozenColumnCount(DesignAttributeHandler
.readAttribute("frozen-columns", attrs, int.class));
}
}
代码示例来源:origin: com.vaadin/vaadin-server
/**
* Creates a grid using a custom {@link PropertySet} implementation for
* creating a default set of columns and for resolving property names with
* {@link #addColumn(String)} and
* {@link Column#setEditorComponent(HasValue)}.
* <p>
* This functionality is provided as static method instead of as a public
* constructor in order to make it possible to use a custom property set
* without creating a subclass while still leaving the public constructors
* focused on the common use cases.
*
* @see Grid#Grid()
* @see Grid#Grid(Class)
*
* @param propertySet
* the property set implementation to use, not <code>null</code>.
* @return a new grid using the provided property set, not <code>null</code>
*/
public static <BEAN> Grid<BEAN> withPropertySet(
PropertySet<BEAN> propertySet) {
return new Grid<>(propertySet);
}
代码示例来源:origin: com.vaadin/vaadin-server
/**
* Removes all columns from this Grid.
*
* @since 8.0.2
*/
public void removeAllColumns() {
for (Column<T, ?> column : getColumns()) {
removeColumn(column);
}
}
代码示例来源:origin: com.vaadin/vaadin-server
ValueProvider<V, P> presentationProvider,
AbstractRenderer<? super T, ? super P> renderer) {
String generatedIdentifier = getGeneratedIdentifier();
Column<T, V> column = createColumn(valueProvider, presentationProvider,
renderer);
addColumn(generatedIdentifier, column);
return column;
代码示例来源:origin: eclipse/hawkbit
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;
}
代码示例来源:origin: jreznot/electron-java-app
tasksGrid.select(task);
});
removeButton.setEnabled(false);
removeButton.addClickListener(event -> {
Set<Task> selectedItems = tasksGrid.getSelectedItems();
tasks.removeAll(selectedItems);
dataProvider.refreshAll();
tasksGrid.select(iterator.next());
tasksGrid = new Grid<>(Task.class);
tasksGrid.setDataProvider(dataProvider);
tasksGrid.setSizeFull();
tasksGrid.getEditor().setEnabled(true);
tasksGrid.setSelectionMode(Grid.SelectionMode.SINGLE);
Grid.Column<Task, Boolean> doneColumn = (Grid.Column<Task, Boolean>) tasksGrid.getColumn("done");
doneColumn.setEditorComponent(new CheckBox());
tasksGrid.getColumn("summary")
.setCaption("Summary")
.setEditorComponent(new TextField());
tasksGrid.setColumnOrder("done", "summary");
tasksGrid.addSelectionListener(event -> {
boolean enableRemove = !event.getAllSelectedItems().isEmpty();
removeButton.setEnabled(enableRemove);
代码示例来源:origin: kingbbode/spring-boot-ehcache-monitor
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;
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework
bindInstance(ListPresenter.class, listPresenter);
grid = Grid.withPropertySet(listPresenter.getPropertySet());
grid.setSizeFull();
grid.setSelectionMode(definition.isMultiSelect() ? Grid.SelectionMode.MULTI : Grid.SelectionMode.SINGLE);
grid.addSelectionListener(event -> valueContext.current().set(SelectedItems.of(event.getAllSelectedItems())));
grid.addItemClickListener(event -> {
grid.deselectAll();
grid.select(event.getItem());
});
ts.stream().forEach(grid::select);
} else {
grid.deselectAll();
grid.setDataProvider(listPresenter.getDataProvider());
代码示例来源:origin: eclipse/hawkbit
private Grid createGrid() {
final Grid statusGrid = new Grid(uploads);
statusGrid.addStyleName(SPUIStyleDefinitions.UPLOAD_STATUS_GRID);
statusGrid.setId(UIComponentIdProvider.UPLOAD_STATUS_POPUP_GRID);
statusGrid.setSelectionMode(SelectionMode.NONE);
statusGrid.setHeaderVisible(true);
statusGrid.setImmediate(true);
statusGrid.setSizeFull();
return statusGrid;
}
代码示例来源:origin: kingbbode/spring-boot-ehcache-monitor
private Grid<Cache> createCacheGrid(CacheManager cacheManager) {
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(Arrays.stream(cacheManager.getCacheNames())
.map(cacheManager::getCache)
.collect(Collectors.toList()));
grid.setSizeFull();
grid.setSelectionMode(Grid.SelectionMode.NONE);
int cacheSize = cacheManager.getCacheNames().length;
if (cacheSize != 0) {
grid.setHeightByRows(cacheSize > 10 ? 10 : cacheSize);
}
return grid;
}
}
代码示例来源:origin: com.vaadin/vaadin-server
/**
* 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());
}
代码示例来源:origin: AxonIQ/giftcard-demo
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;
}
代码示例来源:origin: com.vaadin/vaadin-server
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);
getHeader().readDesign(child, context);
} else if (child.tagName().equals("tbody")) {
readData(child, providers);
} else if (child.tagName().equals("tfoot")) {
getFooter().readDesign(child, context);
if (getDefaultHeaderRow() != null) {
for (Column<T, ?> c : getColumns()) {
HeaderCell headerCell = getDefaultHeaderRow().getCell(c);
if (headerCell.getCellType() == GridStaticCellType.TEXT) {
c.setCaption(headerCell.getText());
代码示例来源:origin: com.vaadin/vaadin-server
private Column<T, ?> getColumnOrThrow(String columnId) {
Objects.requireNonNull(columnId, "Column id cannot be null");
Column<T, ?> column = getColumn(columnId);
if (column == null) {
throw new IllegalStateException(
"There is no column with the id " + columnId);
}
return column;
}
代码示例来源:origin: org.eclipse.hawkbit/hawkbit-ui
private void setGridColumnProperties() {
grid.getColumn(COLUMN_STATUS).setRenderer(new StatusRenderer());
grid.getColumn(COLUMN_PROGRESS).setRenderer(new ProgressBarRenderer());
grid.setColumnOrder(COLUMN_STATUS, COLUMN_PROGRESS, COLUMN_FILE_NAME, SPUILabelDefinitions.NAME_VERSION,
COLUMN_REASON);
setColumnWidth();
grid.getColumn(SPUILabelDefinitions.NAME_VERSION)
.setHeaderCaption(i18n.getMessage("upload.swModuleTable.header"));
grid.setFrozenColumnCount(5);
}
代码示例来源:origin: com.vaadin/vaadin-server
@Override
protected void internalSetDataProvider(DataProvider<T, ?> dataProvider) {
super.internalSetDataProvider(dataProvider);
for (Column<T, ?> column : getColumns()) {
column.updateSortable();
}
}
}
代码示例来源:origin: com.vaadin/vaadin-server
/**
* Constructs a MultiSelect wrapper for given Grid.
*
* @param grid
* the grid to wrap
*/
public GridMultiSelect(Grid<T> grid) {
GridSelectionModel<T> selectionModel = grid.getSelectionModel();
if (!(selectionModel instanceof MultiSelectionModel)) {
throw new IllegalStateException(
"Grid is not in multiselect mode, it needs to be explicitly set to such with setSelectionModel(MultiSelectionModel) before being able to use multiselection features.");
}
model = (MultiSelectionModel<T>) selectionModel;
}
代码示例来源:origin: org.eclipse.hawkbit/hawkbit-ui
private void setUpDetails(final Long swId, final String metaDatakey) {
resetDetails();
metadataWindow.clearOriginalValues();
if (swId != null) {
metaDataGrid.getContainerDataSource().removeAllItems();
populateGrid();
metaDataGrid.getSelectionModel().reset();
if (!metaDataGrid.getContainerDataSource().getItemIds().isEmpty()) {
if (metaDatakey == null) {
metaDataGrid.select(metaDataGrid.getContainerDataSource().getIdByIndex(0));
} else {
metaDataGrid.select(metaDatakey);
}
} else if (hasCreatePermission()) {
enableEditing();
addIcon.setEnabled(false);
}
}
}
代码示例来源:origin: com.vaadin/vaadin-server
private void addColumn(String identifier, Column<T, ?> column) {
if (getColumns().contains(column)) {
return;
}
column.extend(this);
columnSet.add(column);
columnKeys.put(identifier, column);
column.setInternalId(identifier);
addDataGenerator(column.getDataGenerator());
getState().columnOrder.add(identifier);
getHeader().addColumn(identifier);
getFooter().addColumn(identifier);
if (getDefaultHeaderRow() != null) {
getDefaultHeaderRow().getCell(column).setText(column.getCaption());
}
column.updateSortable();
}
内容来源于网络,如有侵权,请联系作者删除!