Implementing ThresholdList.Evaluator

To get an integer from an Issue, extract the priority.

Note

The issue priorities are P1 (most important) to P5 (least important), but this is the opposite of what works best for JSlider. It uses low values on the left and high values on the right, but we want P1 to be furthest to the right. Therefore we flip the priority value by subtracting it from six.

import ca.odell.glazedlists.*;
// 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 ThresholdList.Evaluator {
  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;
  }
}

Create a ThresholdList with the new IssuePriorityThresholdEvaluator, and embed it in the pipeline of list transformations:

  /**
   * 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());
      ...
  }

Warning

A side effect of ThresholdList is that it sorts your elements by their integer evaluation. This makes ThresholdList particularly performant when adjusting the range values, but it may override your preferred ordering. You can overcome this issue by applying the SortedList transformation after the ThresholdList transformation.