本文整理了Java中com.vaadin.ui.Grid.getDataProvider()
方法的一些代码示例,展示了Grid.getDataProvider()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Grid.getDataProvider()
方法的具体详情如下:
包路径:com.vaadin.ui.Grid
类名称:Grid
方法名:getDataProvider
暂无
代码示例来源:origin: com.vaadin/vaadin-server
@Override
public HierarchicalDataProvider<T, ?> getDataProvider() {
if (!(super.getDataProvider() instanceof HierarchicalDataProvider)) {
return null;
}
return (HierarchicalDataProvider<T, ?>) super.getDataProvider();
}
代码示例来源:origin: com.vaadin/vaadin-server
/**
* Returns if the given id belongs to one of the selected items.
*
* @param id
* the id to check for
* @return {@code true} if id is selected, {@code false} if not
*/
protected boolean selectionContainsId(Object id) {
DataProvider<T, ?> dataProvider = getGrid().getDataProvider();
return selection.stream().map(dataProvider::getId)
.anyMatch(i -> id.equals(i));
}
代码示例来源:origin: com.vaadin/vaadin-server
@Override
public void refreshData(T item) {
DataProvider<T, ?> dataProvider = getGrid().getDataProvider();
Object refreshId = dataProvider.getId(item);
for (int i = 0; i < selection.size(); ++i) {
if (dataProvider.getId(selection.get(i)).equals(refreshId)) {
selection.set(i, item);
return;
}
}
}
}
代码示例来源:origin: com.vaadin/vaadin-server
@Override
public boolean isSelected(T item) {
// Quick comparison of objects directly
if (Objects.equals(item, selectedItem)) {
return true;
}
// Id based check
return item != null && selectedItem != null
&& getGrid().getDataProvider().getId(selectedItem)
.equals(getGrid().getDataProvider().getId(item));
}
}
代码示例来源:origin: com.vaadin/vaadin-server
private DataProvider<T, ?> getSourceDataProvider() {
return getGridDragSource().getGrid().getDataProvider();
}
代码示例来源:origin: com.vaadin/vaadin-server
@Override
public void destroyData(T item) {
removeComponent(getGrid().getDataProvider().getId(item));
}
代码示例来源:origin: com.vaadin/vaadin-server
private DataProvider<T, ?> getTargetDataProvider() {
return getGridDropTarget().getGrid().getDataProvider();
}
代码示例来源:origin: com.vaadin/vaadin-server
private void updateSortable() {
boolean inMemory = getGrid().getDataProvider().isInMemory();
boolean hasSortOrder = getSortOrder(SortDirection.ASCENDING)
.count() != 0;
getState().sortable = this.sortable && (inMemory || hasSortOrder);
}
代码示例来源:origin: com.vaadin/vaadin-server
/**
* Writes the data contained in this grid. Used when serializing a grid to
* its declarative representation, if
* {@link DesignContext#shouldWriteData(Component)} returns {@code true} for
* the grid that is being written.
*
* @since 8.1
*
* @param body
* the body element to write the declarative representation of
* data to
* @param designContext
* the design context
*
* @since 8.1
*/
protected void writeData(Element body, DesignContext designContext) {
getDataProvider().fetch(new Query<>())
.forEach(item -> writeRow(body, item, designContext));
}
代码示例来源:origin: com.vaadin/vaadin-server
DataProvider<T, ?> dataProvider = getGrid().getDataProvider();
代码示例来源:origin: com.vaadin/vaadin-server
@Override
public boolean isSelected(T item) {
return isAllSelected()
|| selectionContainsId(getGrid().getDataProvider().getId(item));
}
代码示例来源:origin: com.vaadin/vaadin-server
private void handleTargetGridDrop(GridDropEvent<T> event, final int index,
Collection<T> droppedItems) {
Grid<T> target = getGridDropTarget().getGrid();
if (getTargetDataProviderUpdater() != null) {
getTargetDataProviderUpdater().onDrop(event.getDropEffect(),
target.getDataProvider(), index, droppedItems);
return;
}
ListDataProvider<T> listDataProvider = (ListDataProvider<T>) target
.getDataProvider();
// update the existing to keep filters etc.
List<T> targetItems = (List<T>) listDataProvider.getItems();
if (index != Integer.MAX_VALUE) {
targetItems.addAll(index, droppedItems);
} else {
targetItems.addAll(droppedItems);
}
// instead of using setItems or creating a new data provider,
// refresh the existing one to keep filters etc. in place
listDataProvider.refreshAll();
// if dropped to the end of the grid, the grid should scroll there so
// that the dropped row is visible, but that is just recommended in
// documentation and left for the users to take into use
}
代码示例来源:origin: com.vaadin/vaadin-server
private int calculateDropIndex(GridDropEvent<T> event) {
// use custom calculator if present
if (getDropIndexCalculator() != null) {
return getDropIndexCalculator().calculateDropIndex(event);
}
// if the source and target grids are the same, then the index has been
// calculated before removing the items. In this case the drop location
// is always above, since the items will be starting from that point on
if (shiftedDropIndex != -1) {
return shiftedDropIndex;
}
ListDataProvider<T> targetDataProvider = (ListDataProvider<T>) getGridDropTarget()
.getGrid().getDataProvider();
List<T> items = (List<T>) targetDataProvider.getItems();
int index = items.size();
Optional<T> dropTargetRow = event.getDropTargetRow();
if (dropTargetRow.isPresent()) {
index = items.indexOf(dropTargetRow.get())
+ (event.getDropLocation() == DropLocation.BELOW ? 1 : 0);
}
return index;
}
代码示例来源:origin: com.vaadin/vaadin-server
private void handleSourceGridDrop(GridDropEvent<T> event,
final Collection<T> droppedItems) {
Grid<T> source = getGridDragSource().getGrid();
if (getSourceDataProviderUpdater() != null) {
getSourceDataProviderUpdater().removeItems(event.getDropEffect(),
source.getDataProvider(), droppedItems);
return;
}
ListDataProvider<T> listDataProvider = (ListDataProvider<T>) source
.getDataProvider();
// use the existing data source to keep filters and sort orders etc. in
// place.
Collection<T> sourceItems = listDataProvider.getItems();
// if reordering the same grid and dropping on top of one of the dragged
// rows, need to calculate the new drop index before removing the items
if (getGridDragSource().getGrid() == getGridDropTarget().getGrid()
&& event.getDropTargetRow().isPresent()
&& getDraggedItems().contains(event.getDropTargetRow().get())) {
List<T> sourceItemsList = (List<T>) sourceItems;
shiftedDropIndex = sourceItemsList
.indexOf(event.getDropTargetRow().get());
shiftedDropIndex -= getDraggedItems().stream().filter(
item -> sourceItemsList.indexOf(item) < shiftedDropIndex)
.count();
}
sourceItems.removeAll(droppedItems);
listDataProvider.refreshAll();
}
代码示例来源:origin: com.vaadin/vaadin-server
@SuppressWarnings("unchecked")
private <P> JsonValue generateRendererValue(T item,
ValueProvider<V, P> presentationProvider, Connector renderer) {
P presentationValue = presentationProvider
.apply(valueProvider.apply(item));
// Make Grid track components.
if (renderer instanceof ComponentRenderer
&& presentationValue instanceof Component) {
addComponent(getGrid().getDataProvider().getId(item),
(Component) presentationValue);
}
return ((Renderer<P>) renderer).encode(presentationValue);
}
代码示例来源:origin: com.vaadin/vaadin-server
/**
* Controls whether the select all checkbox is visible in the grid default
* header, or not.
* <p>
* This is updated as a part of {@link #beforeClientResponse(boolean)},
* since the data provider for grid can be changed on the fly.
*
* @see SelectAllCheckBoxVisibility
*/
protected void updateCanSelectAll() {
switch (selectAllCheckBoxVisibility) {
case VISIBLE:
getState(false).selectAllCheckBoxVisible = true;
break;
case HIDDEN:
getState(false).selectAllCheckBoxVisible = false;
break;
case DEFAULT:
getState(false).selectAllCheckBoxVisible = getGrid()
.getDataProvider().isInMemory();
break;
default:
break;
}
}
代码示例来源:origin: com.vaadin/vaadin-server
/**
* Triggered when the user checks the select all checkbox.
*
* @param userOriginated
* {@code true} if originated from client side by user
*/
protected void onSelectAll(boolean userOriginated) {
if (userOriginated) {
verifyUserCanSelectAll();
// all selected state has been updated in client side already
getState(false).allSelected = true;
getUI().getConnectorTracker().getDiffState(this).put("allSelected",
true);
} else {
getState().allSelected = true;
}
Stream<T> allItemsStream;
DataProvider<T, ?> dataProvider = getGrid().getDataProvider();
// this will fetch everything from backend
if (dataProvider instanceof HierarchicalDataProvider) {
allItemsStream = fetchAllHierarchical(
(HierarchicalDataProvider<T, ?>) dataProvider);
} else {
allItemsStream = fetchAll(dataProvider);
}
LinkedHashSet<T> allItems = new LinkedHashSet<>();
allItemsStream.forEach(allItems::add);
updateSelection(allItems, Collections.emptySet(), userOriginated);
}
代码示例来源:origin: com.holon-platform.vaadin/holon-vaadin
@Override
public void refresh() {
if (isBuffered()) {
requireDataSource().refresh();
}
getGrid().getDataProvider().refreshAll();
}
代码示例来源:origin: com.holon-platform.vaadin/holon-vaadin
@Override
public void refreshItem(T item) {
ObjectUtils.argumentNotNull(item, "Item must be not null");
if (isBuffered()) {
requireDataSource().refresh(item);
}
getGrid().getDataProvider().refreshItem(item);
}
代码示例来源:origin: jpos/jPOS-EE
/**
* Refreshes the grid when a search parameter changes
*/
private void refreshGrid() {
DateRange range = dateRangeComponent.getValue();
Journal selectedJournal = journals.getValue();
((TransactionsHelper) getHelper()).setDefaultJournalId(selectedJournal.getId());
ConfigurableFilterDataProvider wrapper = (ConfigurableFilterDataProvider) getGrid().getDataProvider();
wrapper.setFilter(range);
wrapper.refreshAll();
}
内容来源于网络,如有侵权,请联系作者删除!