Chapter 5. EventSelectionModel and Custom Filter Lists

Table of Contents

EventSelectionModel
Custom filtering using Matchers
Dynamic filtering using MatcherEditors
So What?

In part five we are transforming the user list that we built in part four into a filter for the issues list. When a user is selected, only issues for that user shall be displayed.

EventSelectionModel

Just as Glazed Lists provides models for lists, combo boxes and tables, it provides a model for list selection. The EventSelectionModel provides two advantages over the standard DefaultListSelectionModel.

  • It provides its own EventList which contains the widget's current selection. You can now access the selected elements like they are the elements of an ArrayList or Vector.

  • It provides a fourth selection mode in addition to the standard modes of single, single range and multiple range selection. With MULTIPLE_INTERVAL_SELECTION, when a row is inserted within a selected range, the inserted row becomes selected. This can be annoying when unfiltering because restored elements may become selected. This problem is solved by EventSelectionModel's default MULTIPLE_INTERVAL_SELECTION_DEFENSIVE mode, which does not add inserted elements to the selection.

When implementing filtering we display an issue only if there are no users selected or if that issue's user is among those selected. This is easy by using the isEmpty() and contains() methods of the selection list.

      if(usersSelectedList.isEmpty()) return true;
      ...
      String user = issue.getAssignedTo();
      return usersSelectedList.contains(user);