Adapt to changes in Connect
[gpl/argeo-suite.git] / org.argeo.suite.workbench.rap / src / org / argeo / suite / workbench / internal / EntitySingleColumnLabelProvider.java
1 package org.argeo.suite.workbench.internal;
2
3 import javax.jcr.Node;
4 import javax.jcr.Property;
5 import javax.jcr.RepositoryException;
6 import javax.jcr.nodetype.NodeType;
7
8 import org.argeo.activities.ActivitiesService;
9 import org.argeo.activities.ActivitiesTypes;
10 import org.argeo.activities.ui.ActivityListLabelProvider;
11 import org.argeo.connect.resources.ResourcesService;
12 import org.argeo.connect.ui.ConnectUiConstants;
13 import org.argeo.connect.ui.SystemWorkbenchService;
14 import org.argeo.connect.ui.util.TagLabelProvider;
15 import org.argeo.connect.util.ConnectUtils;
16 import org.argeo.people.PeopleException;
17 import org.argeo.people.PeopleNames;
18 import org.argeo.people.PeopleService;
19 import org.argeo.people.PeopleTypes;
20 import org.argeo.people.workbench.rap.providers.GroupLabelProvider;
21 import org.argeo.people.workbench.rap.providers.OrgListLabelProvider;
22 import org.argeo.people.workbench.rap.providers.PersonListLabelProvider;
23 import org.argeo.tracker.TrackerTypes;
24 import org.argeo.tracker.ui.TrackerSingleColLP;
25 import org.eclipse.jface.viewers.LabelProvider;
26 import org.eclipse.swt.graphics.Image;
27
28 /**
29 * Provide a single column label provider for entity lists. Icon and displayed
30 * text vary with the element node type
31 */
32 public class EntitySingleColumnLabelProvider extends LabelProvider implements PeopleNames {
33 private static final long serialVersionUID = 3111885324210673320L;
34
35 private SystemWorkbenchService systemWorkbenchService;
36
37 private ActivityListLabelProvider activityLP;
38 private TrackerSingleColLP trackerLP;
39 private OrgListLabelProvider orgLp;
40 private PersonListLabelProvider personLp;
41 private GroupLabelProvider groupLp = new GroupLabelProvider(ConnectUiConstants.LIST_TYPE_SMALL);
42 private TagLabelProvider mlInstanceLp;
43
44 public EntitySingleColumnLabelProvider(ResourcesService resourceService, ActivitiesService activitiesService,
45 PeopleService peopleService, SystemWorkbenchService systemWorkbenchService) {
46 this.systemWorkbenchService = systemWorkbenchService;
47 activityLP = new ActivityListLabelProvider(activitiesService);
48 trackerLP = new TrackerSingleColLP(activitiesService);
49 personLp = new PersonListLabelProvider(peopleService);
50 orgLp = new OrgListLabelProvider(resourceService, peopleService);
51 mlInstanceLp = new TagLabelProvider(resourceService, ConnectUiConstants.LIST_TYPE_SMALL);
52 }
53
54 @Override
55 public String getText(Object element) {
56 try {
57 Node entity = (Node) element;
58 String result;
59
60 if (entity.isNodeType(TrackerTypes.TRACKER_TASK) || entity.isNodeType(TrackerTypes.TRACKER_PROJECT)
61 || entity.isNodeType(TrackerTypes.TRACKER_MILESTONE))
62 result = trackerLP.getText(element);
63 else if (entity.isNodeType(ActivitiesTypes.ACTIVITIES_ACTIVITY))
64 result = activityLP.getText(element);
65 else if (entity.isNodeType(PeopleTypes.PEOPLE_PERSON))
66 result = personLp.getText(element);
67 else if (entity.isNodeType(PeopleTypes.PEOPLE_ORG))
68 result = orgLp.getText(element);
69 else if (entity.isNodeType(PeopleTypes.PEOPLE_MAILING_LIST))
70 result = mlInstanceLp.getText(element);
71 else if (entity.isNodeType(PeopleTypes.PEOPLE_GROUP))
72 result = groupLp.getText(element);
73 else if (entity.isNodeType(NodeType.MIX_TITLE) && entity.hasProperty(Property.JCR_TITLE))
74 result = entity.getProperty(Property.JCR_TITLE).getString();
75 else
76 result = "";
77 return ConnectUtils.replaceAmpersand(result);
78 } catch (RepositoryException re) {
79 throw new PeopleException("Unable to get formatted value for node", re);
80 }
81 }
82
83 /** Overwrite this method to provide project specific images */
84 @Override
85 public Image getImage(Object element) {
86 return systemWorkbenchService.getIconForType((Node) element);
87 }
88 }