1 package org.argeo.people.web.parts;
2
3 import java.io.InputStream;
4
5 import javax.jcr.Node;
6 import javax.jcr.Property;
7 import javax.jcr.RepositoryException;
8
9 import org.apache.commons.io.IOUtils;
10 import org.argeo.cms.ui.CmsUiProvider;
11 import org.argeo.connect.ConnectNames;
12 import org.argeo.connect.resources.ResourcesNames;
13 import org.argeo.connect.resources.ResourcesService;
14 import org.argeo.eclipse.ui.EclipseUiUtils;
15 import org.argeo.people.PeopleNames;
16 import org.argeo.people.PeopleService;
17 import org.argeo.people.web.PeopleWebConstants;
18 import org.argeo.people.web.providers.OrgOverviewLP;
19 import org.eclipse.jface.viewers.ILabelProvider;
20 import org.eclipse.rap.rwt.RWT;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.graphics.Image;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Label;
28
29
30 public class OrgHeaderPart implements CmsUiProvider {
31
32
33 private ResourcesService resourcesService;
34 private PeopleService peopleService;
35 private TagLikeValuesPart tagsPart;
36 private TagLikeValuesPart mailingListsPart;
37
38 public OrgHeaderPart() {
39 }
40
41 public OrgHeaderPart(ResourcesService resourceService, PeopleService peopleService) {
42 this.resourcesService = resourceService;
43 this.peopleService = peopleService;
44 tagsPart = new TagLikeValuesPart(ResourcesNames.CONNECT_TAGS);
45 mailingListsPart = new TagLikeValuesPart(PeopleNames.PEOPLE_MAILING_LISTS);
46 }
47
48 @Override
49 public Control createUi(Composite parent, Node context) throws RepositoryException {
50 InputStream is = null;
51 Image itemPicture = null;
52
53 try {
54 if (context.hasNode(ConnectNames.CONNECT_PHOTO)) {
55 Node imageNode = context.getNode(ConnectNames.CONNECT_PHOTO).getNode(Node.JCR_CONTENT);
56 is = imageNode.getProperty(Property.JCR_DATA).getBinary().getStream();
57 itemPicture = new Image(parent.getShell().getDisplay(), is);
58 } else
59 itemPicture = null;
60 } catch (Exception e) {
61 } finally {
62 IOUtils.closeQuietly(is);
63 }
64
65 if (itemPicture != null) {
66 parent.setLayout(new GridLayout(2, false));
67 Composite imgCmp = new Composite(parent, SWT.NO_FOCUS | SWT.NO_SCROLL | SWT.NO_TRIM);
68 imgCmp.setLayout(EclipseUiUtils.noSpaceGridLayout());
69 imgCmp.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
70 new ImageLabel(imgCmp, SWT.NO_FOCUS, itemPicture);
71
72 Composite rightCmp = new Composite(parent, SWT.NO_FOCUS);
73 rightCmp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
74 parent = rightCmp;
75 }
76 parent.setLayout(new GridLayout());
77
78 final Label readOnlyInfoLbl = new Label(parent, SWT.WRAP);
79 readOnlyInfoLbl.setData(RWT.MARKUP_ENABLED, Boolean.TRUE);
80 ILabelProvider orgLP = new OrgOverviewLP(resourcesService, peopleService,
81 PeopleWebConstants.OVERVIEW_TYPE_HEADER);
82 readOnlyInfoLbl.setText(orgLP.getText(context));
83
84 Composite tagsCmp = new Composite(parent, SWT.NO_FOCUS);
85 tagsCmp.setLayoutData(EclipseUiUtils.fillWidth());
86 tagsCmp.setLayout(EclipseUiUtils.noSpaceGridLayout());
87 tagsPart.createUi(tagsCmp, context);
88
89 Composite mlCmp = new Composite(parent, SWT.NO_FOCUS);
90 mlCmp.setLayoutData(EclipseUiUtils.fillWidth());
91 mlCmp.setLayout(EclipseUiUtils.noSpaceGridLayout());
92 mailingListsPart.createUi(mlCmp, context);
93
94 return parent;
95 }
96
97
98 private class ImageLabel extends Label {
99 private static final long serialVersionUID = 1L;
100
101 private final Image image;
102
103 private ImageLabel(Composite parent, int style, Image image) {
104 super(parent, style);
105 this.image = image;
106 this.setBackground(parent.getBackground());
107 this.setImage(image);
108
109
110 this.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
111 }
112
113 @Override
114 public void dispose() {
115 if (image != null)
116 image.dispose();
117 super.dispose();
118 }
119
120 }
121
122
123 public void setPeopleService(PeopleService peopleService) {
124 this.peopleService = peopleService;
125 }
126
127 public void setResourcesService(ResourcesService resourcesService) {
128 this.resourcesService = resourcesService;
129 }
130
131 public void setTagsPart(TagLikeValuesPart tagsPart) {
132 this.tagsPart = tagsPart;
133 }
134
135 public void setMailingListsPart(TagLikeValuesPart mailingListsPart) {
136 this.mailingListsPart = mailingListsPart;
137 }
138 }