com.vaadin.data.provider.Query Java Examples
The following examples show how to use
com.vaadin.data.provider.Query.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ComboBoxMultiselect.java From vaadin-combobox-multiselect with Apache License 2.0 | 7 votes |
/** * {@inheritDoc} * <p> * Filtering will use a case insensitive match to show all items where the filter text is a substring of the caption displayed for that item. */ @Override public void setItems(final Collection<T> items) { final ListDataProvider<T> listDataProvider = DataProvider.ofCollection(items); setDataProvider(listDataProvider); // sets the PageLength to 10. // if there are less then 10 items in the combobox, PageLength will get the amount of items. setPageLength(getDataProvider().size(new Query<>()) >= ComboBoxMultiselect.DEFAULT_PAGE_LENGTH ? ComboBoxMultiselect.DEFAULT_PAGE_LENGTH : getDataProvider().size(new Query<>())); }
Example #2
Source File: CardSummaryDataProvider.java From giftcard-demo with Apache License 2.0 | 6 votes |
@Override @Synchronized protected int sizeInBackEnd(Query<CardSummary, Void> query) { if (countQueryResult != null) { countQueryResult.cancel(); countQueryResult = null; } CountCardSummariesQuery countCardSummariesQuery = new CountCardSummariesQuery(filter); log.trace("submitting {}", countCardSummariesQuery); countQueryResult = queryGateway.subscriptionQuery(countCardSummariesQuery, ResponseTypes.instanceOf(CountCardSummariesResponse.class), ResponseTypes.instanceOf(CountChangedUpdate.class)); /* When the count changes (new giftcards issued), the UI has to do an entirely new query (this is * how the Vaadin grid works). When we're bulk issuing, it doesn't make sense to do that on every single * issue event. Therefore, we buffer the updates for 250 milliseconds using reactor, and do the new * query at most once per 250ms. */ countQueryResult.updates().buffer(Duration.ofMillis(250)).subscribe( countChanged -> { log.trace("processing query update for {}: {}", countCardSummariesQuery, countChanged); /* This won't do, would lead to immediate new queries, looping a few times. */ // fireEvent(new DataChangeEvent(this)); executorService.execute(() -> fireEvent(new DataChangeEvent<>(this))); }); return countQueryResult.initialResult().block().getCount(); }
Example #3
Source File: DemoUI.java From vaadin-grid-util with MIT License | 6 votes |
/** * generates a simple totalCount footer * * @param grid * @param items */ private void initFooterRow(final Grid<Inhabitants> grid, List<Inhabitants> items) { final FooterRow footerRow = grid.appendFooterRow(); footerRow.getCell("id") .setHtml("total:"); final FooterCell footerCell = footerRow.join("gender", "name", "bodySize", "birthday", "onFacebook", "country"); // inital total count footerCell.setHtml("<b>" + items.size() + "</b>"); // filter change count recalculate grid.getDataProvider().addDataProviderListener(event -> { List<Inhabitants> data = event.getSource() .fetch(new Query<>()).collect(Collectors.toList()); footerCell.setHtml("<b>" + data.size() + "</b>"); }); }
Example #4
Source File: PagedDataProviderTest.java From GridExtensionPack with Apache License 2.0 | 6 votes |
@Test public void testFilterProvidedByQuery() { controls.setPageLength(15); Query<String, SerializablePredicate<String>> noFilterQuery = new Query<>(); Assert.assertEquals(controls.getPageLength(), pagedDP.size(noFilterQuery)); Assert.assertEquals(controls.getPageLength(), pagedDP.fetch(noFilterQuery).count()); Query<String, SerializablePredicate<String>> filterQuery = new Query<>(x -> x.startsWith("Item 2")); Assert.assertEquals(controls.getPageLength(), pagedDP.size(filterQuery)); Assert.assertEquals(controls.getPageLength(), pagedDP.fetch(filterQuery).count()); filterQuery = new Query<>(x -> x.startsWith("Item 3")); Assert.assertEquals(11, pagedDP.size(filterQuery)); Assert.assertEquals(11, pagedDP.fetch(filterQuery).count()); }
Example #5
Source File: PagedDataProviderTest.java From GridExtensionPack with Apache License 2.0 | 6 votes |
@Test public void testOffsetAndLimitProvidedByQuery() { Query<String, SerializablePredicate<String>> implicitLimitQuery = new Query<>(); Assert.assertEquals(controls.getPageLength(), pagedDP.size(implicitLimitQuery)); Query<String, SerializablePredicate<String>> explicitLimitQuery = new Query<>( 1, controls.getPageLength() - 2, implicitLimitQuery.getSortOrders(), implicitLimitQuery.getInMemorySorting(), implicitLimitQuery.getFilter().orElse(null)); Assert.assertEquals(controls.getPageLength(), pagedDP.size(explicitLimitQuery)); Assert.assertEquals(controls.getPageLength()- 2, pagedDP.fetch(explicitLimitQuery).count()); controls.nextPage(); Assert.assertEquals(controls.getPageLength(), pagedDP.size(explicitLimitQuery)); Assert.assertEquals(controls.getPageLength() - 2, pagedDP.fetch(explicitLimitQuery).count()); }
Example #6
Source File: PagedDataProviderTest.java From GridExtensionPack with Apache License 2.0 | 6 votes |
@Test public void testLimitProvidedByQuery() { Query<String, SerializablePredicate<String>> implicitLimitQuery = new Query<>(); Assert.assertEquals(controls.getPageLength(), pagedDP.size(implicitLimitQuery)); Query<String, SerializablePredicate<String>> explicitLimitQuery = new Query<>( implicitLimitQuery.getOffset(), controls.getPageLength() - 1, implicitLimitQuery.getSortOrders(), implicitLimitQuery.getInMemorySorting(), implicitLimitQuery.getFilter().orElse(null)); Assert.assertEquals(controls.getPageLength(), pagedDP.size(explicitLimitQuery)); Assert.assertEquals(controls.getPageLength() - 1, pagedDP.fetch(explicitLimitQuery).count()); controls.nextPage(); Assert.assertEquals(controls.getPageLength(), pagedDP.size(explicitLimitQuery)); Assert.assertEquals(controls.getPageLength() - 1, pagedDP.fetch(explicitLimitQuery).count()); }
Example #7
Source File: PagedDataProviderTest.java From GridExtensionPack with Apache License 2.0 | 6 votes |
@Test public void testOffsetProvidedByQuery() { Query<String, SerializablePredicate<String>> zeroOffsetQuery = new Query<>(); Assert.assertEquals(controls.getPageLength(), pagedDP.size(zeroOffsetQuery)); Query<String, SerializablePredicate<String>> singleOffsetQuery = new Query<>( 1, zeroOffsetQuery.getLimit(), zeroOffsetQuery.getSortOrders(), zeroOffsetQuery.getInMemorySorting(), zeroOffsetQuery.getFilter().orElse(null)); Assert.assertEquals(controls.getPageLength(), pagedDP.size(singleOffsetQuery)); Assert.assertEquals(controls.getPageLength() - 1, pagedDP.fetch(singleOffsetQuery).count()); controls.nextPage(); Assert.assertEquals(controls.getPageLength(), pagedDP.size(singleOffsetQuery)); Assert.assertEquals(controls.getPageLength() - 1, pagedDP.fetch(singleOffsetQuery).count()); }
Example #8
Source File: PagedDataProviderTest.java From GridExtensionPack with Apache License 2.0 | 6 votes |
@Test public void testPageLengthNotAligned() { controls = pagedDP.getPagingControls(); controls.setPageLength(299); Assert.assertEquals("Page should be 0 when page length was changed.", 0, controls.getPageNumber()); controls.nextPage(); Assert.assertEquals(1, controls.getPageNumber()); Assert.assertEquals("Last page should have only one item.", 1, pagedDP.size(new Query<>())); controls.setPageLength(297); Assert.assertEquals("Page should be 0 when page length was changed.", 0, controls.getPageNumber()); controls.nextPage(); Assert.assertEquals(1, controls.getPageNumber()); Assert.assertEquals("Last page should have only three items.", 3, pagedDP.size(new Query<>())); }
Example #9
Source File: TableSelectionModel.java From GridExtensionPack with Apache License 2.0 | 5 votes |
public TableSelectionModel() { registerRpc(new ShiftSelectRpc() { @Override public void selectRange(int start, int length) { if (length == 0) { return; } BinaryOperator<SerializableComparator<T>> operator = (comparator1, comparator2) -> { /* * thenComparing is defined to return a serializable * comparator as long as both original comparators are also * serializable */ return comparator1.thenComparing(comparator2)::compare; }; Comparator<T> inMemorySorting = getParent().getSortOrder().stream() .map(order -> order.getSorted().getComparator(order.getDirection())) .reduce((x, y) -> 0, operator); List<QuerySortOrder> sortProperties = new ArrayList<>(); getParent().getSortOrder().stream().map(order -> order.getSorted().getSortOrder(order.getDirection())) .forEach(s -> s.forEach(sortProperties::add)); getParent().getDataProvider().fetch(new Query<>(start, length, sortProperties, inMemorySorting, null)); } }); }
Example #10
Source File: PagedDataProvider.java From GridExtensionPack with Apache License 2.0 | 5 votes |
int getBackendSize(Query<T, F> query) { if (backendSize == null) { setBackendSize(dataProvider.size(query)); filter = query.getFilter().orElse(null); } return backendSize; }
Example #11
Source File: PagingControls.java From GridExtensionPack with Apache License 2.0 | 5 votes |
<T, F> Query<T, F> alignQuery(Query<T, F> query) { BigInteger pageNumber = BigInteger.valueOf(this.pageNumber); BigInteger pageLength = BigInteger.valueOf(this.pageLength); BigInteger queryOffset = BigInteger.valueOf(query.getOffset()); BigInteger queryLimit = BigInteger.valueOf(query.getLimit()); BigInteger maxInteger = BigInteger .valueOf(Integer.MAX_VALUE); BigInteger offset = pageNumber .multiply(pageLength) .add(queryOffset) .max(BigInteger.ZERO) .min(maxInteger); BigInteger limit = pageLength.subtract(queryOffset) .min(queryLimit) .max(BigInteger.ZERO) .min(maxInteger); return new Query<>( offset.intValue(), limit.intValue(), query.getSortOrders(), query.getInMemorySorting(), query.getFilter().orElse(null)); }
Example #12
Source File: ComboBoxMultiselect.java From vaadin-combobox-multiselect with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * <p> * Filtering will use a case insensitive match to show all items where the filter text is a substring of the caption displayed for that item. */ @Override public void setItems(final Collection<T> items) { final ListDataProvider<T> listDataProvider = DataProvider.ofCollection(items); setDataProvider(listDataProvider); // sets the PageLength to 10. // if there are less then 10 items in the combobox, PageLength will get the amount of items. setPageLength(getDataProvider().size(new Query<>()) >= ComboBoxMultiselect.DEFAULT_PAGE_LENGTH ? ComboBoxMultiselect.DEFAULT_PAGE_LENGTH : getDataProvider().size(new Query<>())); }
Example #13
Source File: PagedDataProviderTest.java From GridExtensionPack with Apache License 2.0 | 5 votes |
@Test public void testPageNumberGoingBelow0WhenBackendIsEmpty() { Assert.assertEquals(0, controls.getPageNumber()); dp.setFilter(x -> false); Assert.assertEquals(0, dp.size(new Query<>())); Assert.assertEquals(0, dp.fetch(new Query<>()).count()); Assert.assertEquals(0, controls.getPageCount()); Assert.assertEquals(0, controls.getPageNumber()); }
Example #14
Source File: DataGridDataProvider.java From cuba with Apache License 2.0 | 5 votes |
@Override public Stream<T> fetch(Query<T, SerializablePredicate<T>> query) { if (dataGridItems.getState() == BindingState.INACTIVE) { return Stream.empty(); } return dataGridItems.getItems() .skip(query.getOffset()) .limit(query.getLimit()); }
Example #15
Source File: PagedDataProviderTest.java From GridExtensionPack with Apache License 2.0 | 5 votes |
@Test public void testOffsetProvidedByQueryIsOnePageLength() { Query<String, SerializablePredicate<String>> zeroOffsetQuery = new Query<>(); Assert.assertEquals(controls.getPageLength(), pagedDP.size(zeroOffsetQuery)); Query<String, SerializablePredicate<String>> singlePageOffsetQuery = new Query<>( controls.getPageLength(), zeroOffsetQuery.getLimit(), zeroOffsetQuery.getSortOrders(), zeroOffsetQuery.getInMemorySorting(), zeroOffsetQuery.getFilter().orElse(null)); Assert.assertEquals(controls.getPageLength(), pagedDP.size(singlePageOffsetQuery)); Assert.assertEquals(0, pagedDP.fetch(singlePageOffsetQuery).count()); }
Example #16
Source File: PagedDataProviderTest.java From GridExtensionPack with Apache License 2.0 | 5 votes |
@Test public void testOffsetProvidedByQueryIsTwoPageLengths() { Query<String, SerializablePredicate<String>> zeroOffsetQuery = new Query<>(); Assert.assertEquals(controls.getPageLength(), pagedDP.size(zeroOffsetQuery)); Query<String, SerializablePredicate<String>> twoPageOffsetQuery = new Query<>( controls.getPageLength() * 2, zeroOffsetQuery.getLimit(), zeroOffsetQuery.getSortOrders(), zeroOffsetQuery.getInMemorySorting(), zeroOffsetQuery.getFilter().orElse(null)); Assert.assertEquals(controls.getPageLength(), pagedDP.size(twoPageOffsetQuery)); Assert.assertEquals(0, pagedDP.fetch(twoPageOffsetQuery).count()); }
Example #17
Source File: DataGridDataProvider.java From cuba with Apache License 2.0 | 5 votes |
@Override public int size(Query<T, SerializablePredicate<T>> query) { // FIXME: gg, query? if (dataGridItems.getState() == BindingState.INACTIVE) { return 0; } return dataGridItems.size(); }
Example #18
Source File: TelemetryTools.java From anx with Apache License 2.0 | 5 votes |
private void updateComponent() { Optional<String> selected = sensorGroupSelect.getSelectedItem().map(x -> x.getText("sensor-group-identifier")); sensorGroupSelect.setItems(getSensorGroups()); sensorGroupSelect.setSelectedItem(null); sensorGroupSelect.getDataProvider().fetch(new Query<>()) .filter(x -> x.getText("sensor-group-identifier").equals(selected.orElse(null))) .findAny().ifPresent(sensorGroupSelect::setSelectedItem); }
Example #19
Source File: CardSummaryDataProvider.java From giftcard-demo with Apache License 2.0 | 5 votes |
@Override @Synchronized protected Stream<CardSummary> fetchFromBackEnd(Query<CardSummary, Void> query) { /* * If we are already doing a query (and are subscribed to it), cancel are subscription * and forget about the query. */ if (fetchQueryResult != null) { fetchQueryResult.cancel(); fetchQueryResult = null; } FetchCardSummariesQuery fetchCardSummariesQuery = new FetchCardSummariesQuery(query.getOffset(), query.getLimit(), filter); log.trace("submitting {}", fetchCardSummariesQuery); /* * Submitting our query as a subscriptionquery, specifying both the initially expected * response type (multiple CardSummaries) as wel as the expected type of the updates * (single CardSummary object). The result is a SubscriptionQueryResult which contains * a project reactor Mono for the initial response, and a Flux for the updates. */ fetchQueryResult = queryGateway.subscriptionQuery(fetchCardSummariesQuery, ResponseTypes.multipleInstancesOf(CardSummary.class), ResponseTypes.instanceOf(CardSummary.class)); /* * Subscribing to the updates before we get the initial results. */ fetchQueryResult.updates().subscribe( cardSummary -> { log.trace("processing query update for {}: {}", fetchCardSummariesQuery, cardSummary); /* This is a Vaadin-specific call to update the UI as a result of data changes. */ fireEvent(new DataChangeEvent.DataRefreshEvent<>(this, cardSummary)); }); /* * Returning the initial result. */ return fetchQueryResult.initialResult().block().stream(); }
Example #20
Source File: PagedDataProvider.java From GridExtensionPack with Apache License 2.0 | 4 votes |
@Override public Stream<T> fetch(Query<T, F> query) { Query<T, F> newQuery = getPagingControls().alignQuery(query); return dataProvider.fetch(newQuery); }
Example #21
Source File: PagedDataProvider.java From GridExtensionPack with Apache License 2.0 | 4 votes |
int getBackendSize() { return getBackendSize(new Query<>(filter)); }
Example #22
Source File: TelemetryTools.java From anx with Apache License 2.0 | 4 votes |
Component createComponent() { HorizontalLayout telemetryTools = new HorizontalLayout(); telemetryTools.setSizeUndefined(); telemetryTools.setDefaultComponentAlignment(Alignment.BOTTOM_LEFT); sensorGroupSelect = new ComboBox<>("Telemetry Tools"); sensorGroupSelect.setIcon(VaadinIcons.DASHBOARD); sensorGroupSelect.setEmptySelectionCaption("Select or input sensor group name"); sensorGroupSelect.setWidth("325px"); sensorGroupSelect.setItemCaptionGenerator(x -> x.getText("sensor-group-identifier")); sensorGroupSelect.setNewItemHandler(name -> { XMLElement group = new XMLElement(NS_TELEMETRY, "sensor-group") .withTextChild("sensor-group-identifier", name) .withChild("sensor-paths"); List<XMLElement> sensorGroups = sensorGroupSelect.getDataProvider().fetch(new Query<>()) .collect(Collectors.toList()); sensorGroups.add(group); sensorGroupSelect.setItems(sensorGroups); sensorGroupSelect.setSelectedItem(group); }); Button sensorGroupEdit = new Button("Edit", VaadinIcons.EDIT); sensorGroupEdit.addClickListener(x -> showGroupEditor(sensorGroupSelect.getValue())); sensorGroupEdit.setEnabled(false); Button sensorGroupSubscribe = new Button("Live data", VaadinIcons.PIE_BAR_CHART); sensorGroupSubscribe.addClickListener(x -> showGroupSubscribe(sensorGroupSelect.getValue())); sensorGroupSubscribe.setEnabled(false); sensorGroupSelect.addValueChangeListener(x -> { sensorGroupEdit.setEnabled(!sensorGroupSelect.isEmpty()); sensorGroupSubscribe.setEnabled(!sensorGroupSelect.isEmpty()); }); Button searchCLI = new Button("CLI to YANG", VaadinIcons.INPUT); searchCLI.addClickListener(x -> showCLISearchWindow()); updateComponent(); telemetryTools.addComponents(sensorGroupSelect, sensorGroupEdit, sensorGroupSubscribe, searchCLI); return telemetryTools; }