Our goal is to create a list containing the users for each issue. For example, if
the first element of our issue list contained an Issue
object
that belonged to user "jessewilson", then the first element of our users list will
simply contain the element "jessewilson". The size of our users list will be
exactly the same size of the source issues list.
Glazed Lists contains an abstract class to extend for just this purpose called
TransformedList
. It manages the list methods and has a
protected ListEventAssembler
, updates. We will override the
get()
method to return an issue's user instead of the issue itself.
We must implement the listChanged()
method to respond to changes
in our source issues list. In our listChanged()
method we simply
forward an identical event. This maintains our one-to-one relationship with our source
issues list.
// glazed lists import ca.odell.glazedlists.*; import ca.odell.glazedlists.event.*; // a simple issues library import ca.odell.issuezilla.*; /** * An IssuesToUserList is a list of users that is obtained by getting * the reporters from the issues list. * * @author <a href="mailto:jesse@odel.on.ca">Jesse Wilson</a> */ public class IssueToUserList extends TransformedList { /** * Construct an IssuesToUserList from an EventList that contains only * Issue objects. */ public IssuesToUserList(EventList source) { super(source); source.addListEventListener(this); } /** * Gets the user at the specified index. */ public Object get(int index) { Issue issue = (Issue)source.get(index); return issue.getReporter(); } /** * When the source issues list changes, propogate the exact same changes * for the users list. */ public void listChanged(ListEvent listChanges) { updates.forwardEvent(listChanges); } }