The ThresholdEvaluator Interface

For the priority property of an Issue object, it makes sense to use the integer value of the priority level as the object evaluation. So let's create a simple IssueEvaluator that given an Issue returns the priority level.

import ca.odell.glazedlists.ThresholdEvaluator;
// a simple issues library
import ca.odell.issuezilla.*;

/**
 * Evaluates an issue by returning its threshold value.
 * 
 * @author <a href="mailto:jesse@odel.on.ca">Jesse Wilson</a>
 */
public class IssuePriorityThresholdEvaluator implements ThresholdEvaluator {
  public int evaluate(Object a) {
    Issue issue = (Issue)a;
    
    // rating is between 1 and 5, lower is more important
    int issueRating = issue.getPriority().getValue();
    
    // flip: now rating is between 1 and 5, higher is more important
    int inverseRating = 6 - issueRating;
    return inverseRating;
  }
}

Now that we have a concrete ThresholdEvaluator, we can create a ThresholdList. In the run() method of IssuesBrowser we need to create a ThresholdList that has the list of issues as data.

  /**
   * Display a frame for browsing issues. This should only be run on the Swing
   * event dispatch thread.
   */
  public void run() {
      ...
      UsersSelect usersSelect = new UsersSelect(issuesEventList);
      FilterList userFilteredIssues = new FilterList(issuesEventList, usersSelect);
      TextFilterList textFilteredIssues = new TextFilterList(userFilteredIssues, new IssueTextFilterator());
      ThresholdList priorityFilteredIssues = new ThresholdList(textFilteredIssues, new IssuePriorityThresholdEvaluator());
      SortedList sortedIssues = new SortedList(priorityFilteredIssues, new IssueComparator());
      ...
  }

Something worth noting is how the lists were layered. The ThresholdList enforces a sort order on the list when you use it. While this might seem strange to sort the values, this is done to make the ThresholdList high-performance. As a result, you may have to sort a list after the ThresholdList is applied to present it in an ordering that makes the most sense for your application. That is why the ThresholdList decorates the source list before the the SortedList in applied in our issue browser. Now that we have a ThresholdList, we need to bind it to a widget to allow for user interaction.