Search in sources :

Example 1 with SimpleStringFilter

use of com.vaadin.data.util.filter.SimpleStringFilter in project VaadinUtils by rlsutton1.

the class ExampleLayout method getContainerFilter.

@Override
protected Filter getContainerFilter(String filterText, boolean advancedSearchActive) {
    Filter filter = null;
    String[] searchFields = new String[] { "name" };
    for (String property : searchFields) {
        if (filter == null) {
            filter = new SimpleStringFilter(property, filterText, true, false);
        }
        filter = new Or(new SimpleStringFilter(property, filterText, true, false), filter);
    }
    return filter;
}
Also used : Or(com.vaadin.data.util.filter.Or) Filter(com.vaadin.data.Container.Filter) SimpleStringFilter(com.vaadin.data.util.filter.SimpleStringFilter) SimpleStringFilter(com.vaadin.data.util.filter.SimpleStringFilter)

Example 2 with SimpleStringFilter

use of com.vaadin.data.util.filter.SimpleStringFilter in project VaadinUtils by rlsutton1.

the class ComboBoxWithSearchFieldChooserWindow method getPopupContent2.

@SuppressWarnings("unchecked")
public Component getPopupContent2() {
    grid = new SearchableGrid<T, C>() {

        /**
         */
        private static final long serialVersionUID = 1L;

        @Override
        public GridHeadingPropertySetIfc<T> getHeadingPropertySet() {
            return headingProps;
        }

        @Override
        protected Filter getContainerFilter(String filterString, boolean advancedSearchActive) {
            List<Filter> filters = new ArrayList<>();
            if (baseFilters != null) {
                filters.add(baseFilters);
            }
            if (filterString.length() > 0) {
                filters.add(new SimpleStringFilter(sortColumns[0], filterString, true, false));
            }
            if (filters.size() == 0) {
                return null;
            }
            return new And(filters.toArray(new Filter[] {}));
        }

        @Override
        protected String getTitle() {
            return null;
        }

        @Override
        public C getContainer() {
            return localContainer;
        }

        @Override
        protected AbstractLayout getAdvancedSearchLayout() {
            if (advancedSearchProvider == null) {
                return null;
            }
            return advancedSearchProvider.getAdvancedSearchLayout();
        }

        @Override
        protected AdvancedSearchListener getAdvancedSearchListener() {
            return advancedSearchListener;
        }
    };
    grid.init(caption, (Class<T>) type);
    // grid.getGrid().removeHeaderRow(0);
    ItemClickListener itemClickListener = new ItemClickListener() {

        private static final long serialVersionUID = -4659382639878762429L;

        @Override
        public void itemClick(ItemClickEvent event) {
            listener.selected(event.getItemId());
        }
    };
    Sort sort = Sort.by(sortColumns[0]);
    for (int i = 1; i < sortColumns.length; i++) {
        sort.then(sortColumns[i]);
    }
    grid.sort(sort);
    grid.setSelectionMode(SelectionMode.SINGLE);
    grid.addItemClickListener(itemClickListener);
    grid.setSizeFull();
    holder = new VerticalLayout();
    holder.setWidth("100%");
    holder.setHeight("300");
    holder.addComponent(grid);
    return holder;
}
Also used : ItemClickListener(com.vaadin.event.ItemClickEvent.ItemClickListener) ItemClickEvent(com.vaadin.event.ItemClickEvent) AdvancedSearchListener(au.com.vaadinutils.crud.AdvancedSearchListener) Filter(com.vaadin.data.Container.Filter) SimpleStringFilter(com.vaadin.data.util.filter.SimpleStringFilter) And(com.vaadin.data.util.filter.And) Sort(com.vaadin.data.sort.Sort) VerticalLayout(com.vaadin.ui.VerticalLayout) ArrayList(java.util.ArrayList) List(java.util.List) AbstractLayout(com.vaadin.ui.AbstractLayout) GridHeadingPropertySetIfc(au.com.vaadinutils.crud.GridHeadingPropertySetIfc) SimpleStringFilter(com.vaadin.data.util.filter.SimpleStringFilter)

Example 3 with SimpleStringFilter

use of com.vaadin.data.util.filter.SimpleStringFilter in project VaadinUtils by rlsutton1.

the class ReportParameterTable method init.

protected void init(final String caption, final Class<T> tableClass, final SingularAttribute<T, String> displayField) {
    JpaBaseDao.getGenericDao(tableClass).flushCache();
    container = createContainer(tableClass, displayField);
    UI ui = UI.getCurrent();
    if (ui != null) {
        Runnable runner = new Runnable() {

            @Override
            public void run() {
                try (AutoCloseable closer = EntityManagerProvider.setThreadLocalEntityManagerTryWithResources()) {
                    ReportParameterTable.this.displayField = displayField;
                    layout.setSizeFull();
                    ReportParameterTable.this.caption = caption;
                    TextField searchText = new TextField();
                    searchText.setInputPrompt("Search");
                    searchText.setWidth("100%");
                    searchText.setImmediate(true);
                    searchText.setHeight("20");
                    searchText.addTextChangeListener(new TextChangeListener() {

                        private static final long serialVersionUID = 1315710313315289836L;

                        @Override
                        public void textChange(TextChangeEvent event) {
                            String value = event.getText();
                            removeAllContainerFilters();
                            if (value.length() > 0) {
                                container.addContainerFilter(new SimpleStringFilter(displayField.getName(), value, true, false));
                            }
                        }
                    });
                    grid = new Grid();
                    grid.setImmediate(true);
                    grid.setSizeFull();
                    // table.setHeight("150");
                    grid.setContainerDataSource(container);
                    new GridHeadingPropertySet.Builder<T>().createColumn(caption, displayField.getName()).setLockedState(true).build().applyToGrid(grid);
                    List<SortOrder> orders = new LinkedList<>();
                    orders.add(new SortOrder(displayField.getName(), SortDirection.ASCENDING));
                    grid.setSortOrder(orders);
                    final Label selectionCount = new Label("0 selected");
                    // removed for concertina
                    // layout.addComponent(new Label(caption));
                    layout.addComponent(searchText);
                    layout.addComponent(grid);
                    HorizontalLayout selectionLayout = new HorizontalLayout();
                    selectionLayout.setHeight("30");
                    selectionLayout.setWidth("100%");
                    selectionLayout.addComponent(selectionCount);
                    selectionLayout.setComponentAlignment(selectionCount, Alignment.MIDDLE_RIGHT);
                    layout.addComponent(selectionLayout);
                    grid.addSelectionListener(new SelectionListener() {

                        /**
                         */
                        private static final long serialVersionUID = 1L;

                        @Override
                        public void select(SelectionEvent event) {
                            validate();
                            selectionCount.setValue("" + event.getSelected().size() + " selected");
                        }
                    });
                    layout.setExpandRatio(grid, 1);
                // layout.setComponentAlignment(selectAll,
                // Alignment.BOTTOM_RIGHT);
                } catch (Exception e) {
                    ErrorWindow.showErrorWindow(e);
                }
            }
        };
        UI.getCurrent().accessSynchronously(runner);
    } else {
        logger.warn("No vaadin session available, not setting up UI");
    }
}
Also used : Grid(com.vaadin.ui.Grid) Label(com.vaadin.ui.Label) SortOrder(com.vaadin.data.sort.SortOrder) LinkedList(java.util.LinkedList) HorizontalLayout(com.vaadin.ui.HorizontalLayout) UI(com.vaadin.ui.UI) TextChangeEvent(com.vaadin.event.FieldEvents.TextChangeEvent) SelectionEvent(com.vaadin.event.SelectionEvent) TextField(com.vaadin.ui.TextField) TextChangeListener(com.vaadin.event.FieldEvents.TextChangeListener) SimpleStringFilter(com.vaadin.data.util.filter.SimpleStringFilter) SelectionListener(com.vaadin.event.SelectionEvent.SelectionListener)

Example 4 with SimpleStringFilter

use of com.vaadin.data.util.filter.SimpleStringFilter in project VaadinUtils by rlsutton1.

the class JasperReportScheduleLayout method getContainerFilter.

@Override
protected Filter getContainerFilter(String filterText, boolean advancedSearchActive) {
    Filter filter = null;
    String[] searchFields = new String[] { ReportEmailScheduleEntity_.subject.getName() };
    for (String property : searchFields) {
        if (filter == null) {
            filter = new SimpleStringFilter(property, filterText, true, false);
        }
        filter = new Or(new SimpleStringFilter(property, filterText, true, false), filter);
    }
    return filter;
}
Also used : Or(com.vaadin.data.util.filter.Or) SimpleStringFilter(com.vaadin.data.util.filter.SimpleStringFilter) Filter(com.vaadin.data.Container.Filter) SimpleStringFilter(com.vaadin.data.util.filter.SimpleStringFilter)

Aggregations

SimpleStringFilter (com.vaadin.data.util.filter.SimpleStringFilter)4 Filter (com.vaadin.data.Container.Filter)3 Or (com.vaadin.data.util.filter.Or)2 AdvancedSearchListener (au.com.vaadinutils.crud.AdvancedSearchListener)1 GridHeadingPropertySetIfc (au.com.vaadinutils.crud.GridHeadingPropertySetIfc)1 Sort (com.vaadin.data.sort.Sort)1 SortOrder (com.vaadin.data.sort.SortOrder)1 And (com.vaadin.data.util.filter.And)1 TextChangeEvent (com.vaadin.event.FieldEvents.TextChangeEvent)1 TextChangeListener (com.vaadin.event.FieldEvents.TextChangeListener)1 ItemClickEvent (com.vaadin.event.ItemClickEvent)1 ItemClickListener (com.vaadin.event.ItemClickEvent.ItemClickListener)1 SelectionEvent (com.vaadin.event.SelectionEvent)1 SelectionListener (com.vaadin.event.SelectionEvent.SelectionListener)1 AbstractLayout (com.vaadin.ui.AbstractLayout)1 Grid (com.vaadin.ui.Grid)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Label (com.vaadin.ui.Label)1 TextField (com.vaadin.ui.TextField)1 UI (com.vaadin.ui.UI)1