« Return to Thread: TransformedList question

Re: TransformedList question

by wsnyder6 :: Rate this Message:

Reply to Author | View in Thread

Awesome. I will try this.

I also thought that I could use the TransformedList like such:

 class ItemsToLabelsList extends TransformedList {
       
        public IssuesToUsersList(EventList source) {
            super(source);
            for (Object elem : source) {
                addAll( ((Issue)elem).getUsers() );
            }
            source.addListEventListener(this);
        }
       
        public void listChanged(ListEvent listChanges) {
            updates.forwardEvent(listChanges);
        }

    }

Holger Brands-2 wrote:
Hi,

>
> What if each Issue could have more than one User attached to it? How then
> would I implement the TransformedList with Dynamic filtering?  
>

The tutorial shows filtering of issues by the issue reporter: Issue.getReporter()
For the following discussion let's assume you want to filter by
all users of the issue as defined by method Issue.getAllUsers().

You would have to change
a) the IssueToUserList from tutorial chapter 4
b) the IssuesForUsersMatcher from tutorial chapter 5.

a) Instead of using the IssueToUserList I would use a CollectionList like this:

CollectionList<Issue, String> usersNonUnique = new CollectionList<Issue, String>(source, new IssueToUsersModel());


/**
 * Determines all users for an issue.
 */
public class IssueToUsersModel implements CollectionList.Model<Issue, String> {
    public List<String> getChildren(Issue issue) {
        return issue.getAllUsers();
    }
}

The CollectionList is a TransformedList that maps each issue from the source list to the associated users.
It's a kind of parent-child relationship.


b) IssuesForUsersMatcher should be changed to match all issue users using. Issue.getAllUsers():

   /**
    * Test whether to include or not include the specified issue based
    * on whether or not their user is selected.
    */
   public boolean matches(Object o) {
       if(o == null) return false;
       if(users.isEmpty()) return true;
       
       Issue issue = (Issue)o;
       for (Iterator i = issue.getAllUsers().iterator(); i.hasNext(); ) {
         if(users.contains(i.next())) return true;
       }
       return false;
    }


Hope this helps,
Holger

__________________________________________________________________________
Erweitern Sie FreeMail zu einem noch leistungsstärkeren E-Mail-Postfach!
Mehr Infos unter http://freemail.web.de/home/landingpad/?mc=021131

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glazedlists.dev.java.net
For additional commands, e-mail: users-help@glazedlists.dev.java.net

 « Return to Thread: TransformedList question