View Javadoc
1   package org.argeo.people.ui.providers;
2   
3   import javax.jcr.Node;
4   import javax.jcr.NodeIterator;
5   import javax.jcr.Property;
6   import javax.jcr.RepositoryException;
7   
8   import org.argeo.connect.util.ConnectJcrUtils;
9   import org.argeo.connect.util.ConnectUtils;
10  import org.argeo.eclipse.ui.EclipseUiUtils;
11  import org.argeo.people.PeopleNames;
12  import org.argeo.people.PeopleService;
13  import org.argeo.people.PeopleTypes;
14  import org.eclipse.jface.viewers.LabelProvider;
15  
16  /** Provide a single column label provider for person lists */
17  public class PersonListLabelProvider extends LabelProvider implements PeopleNames {
18  
19  	private static final long serialVersionUID = 1L;
20  	private PeopleService peopleService;
21  
22  	public PersonListLabelProvider(PeopleService peopleService) {
23  		this.peopleService = peopleService;
24  	}
25  
26  	@Override
27  	public String getText(Object element) {
28  		Node person = (Node) element;
29  		StringBuilder builder = new StringBuilder();
30  		builder.append("<b>");
31  		builder.append(peopleService.getDisplayName(person));
32  		builder.append("</b>");
33  		try {
34  			NodeIterator ni = person.getNode(PEOPLE_JOBS).getNodes();
35  			while (ni.hasNext()) {
36  				Node currNode = ni.nextNode();
37  				if (currNode.isNodeType(PeopleTypes.PEOPLE_JOB)) {
38  					Node org = peopleService.getEntityByUid(person.getSession(), null,
39  							currNode.getProperty(PEOPLE_REF_UID).getString());
40  					builder.append(" [");
41  					String role = ConnectJcrUtils.get(currNode, PEOPLE_ROLE);
42  					if (EclipseUiUtils.notEmpty(role))
43  						builder.append(role).append(", ");
44  					builder.append(org != null ? ConnectJcrUtils.get(org, Property.JCR_TITLE) : "-");
45  					builder.append("]");
46  				}
47  			}
48  		} catch (RepositoryException re) {
49  			// Cannot get corresponding jobs, fail silently
50  		}
51  		String result = ConnectUtils.replaceAmpersand(builder.toString());
52  		return result;
53  	}
54  }