Module MaterialFX

Class MFXFilterPane<T>

Type Parameters:
T -
All Implemented Interfaces:
Styleable, EventTarget, Skinnable

public class MFXFilterPane<T> extends Control
This control allows to produce a Predicate for a given object type interactively, meaning that the filter is assembled from the user choices. To produce a filter the user must choose the object's field, input/choose a query and a way to evaluate the object's field against the query.

From now on all code examples to better understand the functionalities of this control will use these POJO classes:
 
      public enum Gender {
          MALE, FEMALE
      }

      public class Person {
          private final String name;
          private final int age;
          private final Gender gender;
          private final City city;

          public Person(String name, int age, Gender gender, City city) {
              this.name = name;
              this.age = age;
              this.gender = gender;
              this.city = city;
          }

          public String name() {
              return name;
          }

          public int age() {
              return age;
          }

          public Gender gender() {
              return gender;
          }

          public City city() {
              return city;
          }
      }

      public class City {
          private final String name;
          private final long population;

          public City(String name, long population) {
              this.name = name;
              this.population = population;
          }

          public String name() {
              return name;
          }

          public long population() {
              return population;
          }
      }
 
 

To specify on which fields to operate the filters must be added like this:
 
      MFXFilterPane<Person> fp = new MFXFilterPane<>();
      AbstractFilter<Person, String> nameFilter = new StringFilter<>("Name", Person::name)
      AbstractFilter<Person, Integer> ageFilter = new IntegerFilter<>("Age", Person:.age);

      // MFXFilterPane is so powerful and versatile that you can also filter by nested objects, something like this for example...
      AbstractFilter<Person, Long> populationFilter = new LongFilter<>("City Population", person -> person.city().population());

      // It even works for enumerators...
      AbstractFilter<Person, Enum<Gender>> genderFilter = new EnumFilter<>("Gender", Person::gender, Gender.class); // Note that the type is necessary

      // Finally...
      fp.getFilters().addAll(nameFilter, ageFilter, populationFilter, genderFilter);
 
 

When a filter is created through the add button, a FilterBean is created and added to a list which holds the "active filters", getActiveFilters().

Note that the list is not unmodifiable, potentially, you could even add your own custom filters, the UI will be updated anyway.

As you can read in the FilterBean documentation, they can be chained according to the specified FilterBean.getMode(), this is also interactive, meaning that when you build more than one filter, a node will appear between them, that node specifies the ChainMode, by clicking on it, you can switch between modes.

Once filters you have finished you can produce a filter by calling filter().

The control also offers to icons that are intended to produce a filter or reset the control, to set their behavior use setOnFilter(EventHandler) and setOnReset(EventHandler).