1 package org.argeo.people.ui.exports;
2
3 import static org.argeo.eclipse.ui.EclipseUiUtils.notEmpty;
4
5 import java.util.List;
6
7 import javax.jcr.Node;
8 import javax.jcr.RepositoryException;
9
10 import org.argeo.connect.util.ConnectJcrUtils;
11 import org.argeo.people.PeopleException;
12 import org.argeo.people.PeopleNames;
13 import org.argeo.people.util.PeopleJcrUtils;
14 import org.eclipse.jface.viewers.ColumnLabelProvider;
15
16
17
18
19
20
21 public class NotPrimContactValueLP extends ColumnLabelProvider {
22 private static final long serialVersionUID = 2085668424125329226L;
23
24 private String selectorName;
25 private String propertyName;
26
27 public NotPrimContactValueLP(String selectorName, String propertyName) {
28 if (notEmpty(selectorName))
29 this.selectorName = selectorName;
30 this.propertyName = propertyName;
31 }
32
33 @Override
34 public String getText(Object element) {
35 try {
36 Node currNode = ConnectJcrUtils.getNodeFromElement(element, selectorName);
37
38 List<Node> nodes = PeopleJcrUtils.getContactOfType(currNode, propertyName);
39
40 StringBuilder builder = new StringBuilder();
41 loop: for (Node currContact : nodes) {
42
43 if (currContact.hasProperty(PeopleNames.PEOPLE_IS_PRIMARY)
44 && currContact.getProperty(PeopleNames.PEOPLE_IS_PRIMARY).getBoolean())
45 continue loop;
46
47 builder.append(currContact.getProperty(PeopleNames.PEOPLE_CONTACT_VALUE).getString());
48 builder.append(", ");
49 }
50
51 String result = builder.toString();
52 if (result.lastIndexOf(", ") > 0)
53 result = result.substring(0, result.length() - 2);
54
55 return result;
56 } catch (RepositoryException re) {
57 throw new PeopleException("Unable to get text from row " + element, re);
58 }
59 }
60 }