Example usage for com.vaadin.data.provider Query Query

List of usage examples for com.vaadin.data.provider Query Query

Introduction

In this page you can find the example usage for com.vaadin.data.provider Query Query.

Prototype

public Query() 

Source Link

Document

Constructs a Query for all rows from 0 to Integer#MAX_VALUE without sorting and filtering.

Usage

From source file:de.symeda.sormas.ui.utils.GridExportStreamResource.java

License:Open Source License

public GridExportStreamResource(Grid<?> grid, String tempFilePrefix, String filename,
        String... ignoredPropertyIds) {
    super(new StreamSource() {
        @SuppressWarnings({ "unchecked", "rawtypes" })
        @Override//from  ww w . j a va2  s.c  o m
        public InputStream getStream() {
            List<String> ignoredPropertyIdsList = Arrays.asList(ignoredPropertyIds);
            List<Column> columns = new ArrayList<>(grid.getColumns());
            columns.removeIf(c -> c.isHidden());
            columns.removeIf(c -> ignoredPropertyIdsList.contains(c.getId()));

            try (ByteArrayOutputStream byteStream = new ByteArrayOutputStream()) {
                try (CSVWriter writer = CSVUtils.createCSVWriter(
                        new OutputStreamWriter(byteStream, StandardCharsets.UTF_8.name()),
                        FacadeProvider.getConfigFacade().getCsvSeparator())) {

                    List<String> headerRow = new ArrayList<>();
                    columns.forEach(c -> {
                        headerRow.add(c.getCaption());
                    });
                    writer.writeNext(headerRow.toArray(new String[headerRow.size()]));

                    String[] rowValues = new String[columns.size()];

                    int totalRowCount = grid.getDataProvider().size(new Query());
                    for (int i = 0; i < totalRowCount; i += 100) {
                        grid.getDataProvider().fetch(new Query(i, 100, grid.getSortOrder(), null, null))
                                .forEach(row -> {
                                    for (int c = 0; c < columns.size(); c++) {
                                        Column column = columns.get(c);
                                        Object value = column.getValueProvider().apply(row);
                                        String valueString;
                                        if (value != null) {
                                            if (value instanceof Date) {
                                                valueString = DateHelper.formatLocalDateTime((Date) value);
                                            } else if (value instanceof Boolean) {
                                                if ((Boolean) value == true) {
                                                    valueString = I18nProperties
                                                            .getEnumCaption(YesNoUnknown.YES);
                                                } else
                                                    valueString = I18nProperties
                                                            .getEnumCaption(YesNoUnknown.NO);
                                            } else {
                                                valueString = value.toString();
                                            }
                                        } else {
                                            valueString = "";
                                        }
                                        rowValues[c] = valueString;
                                    }
                                    writer.writeNext(rowValues);
                                });
                        writer.flush();
                    }
                }
                return new BufferedInputStream(new ByteArrayInputStream(byteStream.toByteArray()));
            } catch (IOException e) {
                // TODO This currently requires the user to click the "Export" button again or reload the page as the UI
                // is not automatically updated; this should be changed once Vaadin push is enabled (see #516)
                new Notification(I18nProperties.getString(Strings.headingExportFailed),
                        I18nProperties.getString(Strings.messageExportFailed), Type.ERROR_MESSAGE, false)
                                .show(Page.getCurrent());
                return null;
            }
        }
    }, filename);
    setMIMEType("text/csv");
    setCacheTime(0);
}

From source file:org.jpos.qi.eeuser.ConsumersView.java

License:Open Source License

@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));
}

From source file:org.jpos.qi.minigl.TransactionsView.java

License:Open Source License

private HorizontalLayout createFilters() {
    HorizontalLayout controls = new HorizontalLayout();
    controls.setWidth("100%");
    journals = new JournalsCombo(true);
    journals.setValue(journals.getDataProvider().fetch(new Query<>()).findFirst().orElse(null));
    controls.addComponents(journals, dateRangeComponent);
    controls.setComponentAlignment(dateRangeComponent, Alignment.MIDDLE_LEFT);
    controls.setComponentAlignment(journals, Alignment.MIDDLE_RIGHT);
    controls.setExpandRatio(journals, 0f);
    controls.setExpandRatio(dateRangeComponent, 1f);
    controls.setMargin(new MarginInfo(false, true, true, true));
    controls.setSpacing(true);/*www. j  a va 2 s  . c  o  m*/
    return controls;
}

From source file:org.openthinclient.web.pkgmngr.ui.view.PackageDetailsView.java

private boolean hasProvides() {
    return provides.getDataProvider().size(new Query<>()) != 0;
}

From source file:org.openthinclient.web.pkgmngr.ui.view.PackageDetailsView.java

private boolean hasConflicts() {
    return conflicts.getDataProvider().size(new Query<>()) != 0;
}

From source file:org.openthinclient.web.pkgmngr.ui.view.PackageDetailsView.java

private boolean hasDependencies() {
    return dependencies.getDataProvider().size(new Query<>()) != 0;
}