1 package org.argeo.people.web.pages;
2
3 import java.io.InputStream;
4
5 import javax.jcr.Node;
6 import javax.jcr.Property;
7 import javax.jcr.RepositoryException;
8 import javax.jcr.Value;
9
10 import org.apache.commons.io.IOUtils;
11 import org.argeo.cms.ui.CmsUiProvider;
12 import org.argeo.cms.util.CmsUtils;
13 import org.argeo.connect.ConnectNames;
14 import org.argeo.connect.resources.ResourcesService;
15 import org.argeo.connect.util.ConnectJcrUtils;
16 import org.argeo.eclipse.ui.EclipseUiUtils;
17 import org.argeo.people.PeopleNames;
18 import org.argeo.people.PeopleService;
19 import org.argeo.people.web.PeopleWebConstants;
20 import org.argeo.people.web.providers.OrgOverviewLP;
21 import org.eclipse.jface.viewers.ILabelProvider;
22 import org.eclipse.rap.rwt.RWT;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.events.SelectionAdapter;
25 import org.eclipse.swt.events.SelectionEvent;
26 import org.eclipse.swt.graphics.Image;
27 import org.eclipse.swt.layout.GridData;
28 import org.eclipse.swt.layout.GridLayout;
29 import org.eclipse.swt.layout.RowLayout;
30 import org.eclipse.swt.widgets.Button;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Control;
33 import org.eclipse.swt.widgets.Label;
34
35
36 public class OrganizationPage implements CmsUiProvider {
37
38
39 private ResourcesService resourcesService;
40 private PeopleService peopleService;
41
42 @Override
43 public Control createUi(Composite parent, Node context) throws RepositoryException {
44
45 Composite body = new Composite(parent, SWT.NO_FOCUS);
46 body.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
47 body.setLayout(EclipseUiUtils.noSpaceGridLayout());
48
49
50 Composite headerCmp = new Composite(body, SWT.NO_FOCUS);
51 headerCmp.setLayoutData(EclipseUiUtils.fillWidth());
52 createHeader(headerCmp, context);
53
54
55 Composite mlCmp = new Composite(body, SWT.NO_FOCUS);
56 mlCmp.setLayoutData(EclipseUiUtils.fillWidth());
57 createMailingListPanel(mlCmp, context);
58
59
60 Composite contactCmp = new Composite(body, SWT.NO_FOCUS);
61 contactCmp.setLayoutData(EclipseUiUtils.fillWidth());
62 createContactPanel(contactCmp, context);
63
64
65 Composite activityCmp = new Composite(body, SWT.NO_FOCUS);
66 activityCmp.setLayoutData(EclipseUiUtils.fillWidth());
67 createActivityPanel(activityCmp, context);
68
69 parent.layout();
70 return body;
71 }
72
73 private void createHeader(Composite parent, Node context) {
74
75 InputStream is = null;
76 Image itemPicture = null;
77
78 try {
79 if (context.hasNode(ConnectNames.CONNECT_PHOTO)) {
80 Node imageNode = context.getNode(ConnectNames.CONNECT_PHOTO).getNode(Node.JCR_CONTENT);
81 is = imageNode.getProperty(Property.JCR_DATA).getBinary().getStream();
82 itemPicture = new Image(parent.getShell().getDisplay(), is);
83 } else
84 itemPicture = null;
85 } catch (Exception e) {
86 } finally {
87 IOUtils.closeQuietly(is);
88 }
89
90 if (itemPicture != null) {
91 parent.setLayout(new GridLayout(2, false));
92 Composite imgCmp = new Composite(parent, SWT.NO_FOCUS | SWT.NO_SCROLL | SWT.NO_TRIM);
93 imgCmp.setLayout(EclipseUiUtils.noSpaceGridLayout());
94 imgCmp.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
95 new ImageLabel(imgCmp, SWT.NO_FOCUS, itemPicture);
96
97 Composite rightCmp = new Composite(parent, SWT.NO_FOCUS);
98 rightCmp.setLayoutData(EclipseUiUtils.fillWidth());
99 parent = rightCmp;
100
101 }
102 parent.setLayout(new GridLayout());
103
104 final Label readOnlyInfoLbl = new Label(parent, SWT.WRAP);
105 readOnlyInfoLbl.setData(RWT.MARKUP_ENABLED, Boolean.TRUE);
106 ILabelProvider labelProvider = new OrgOverviewLP(resourcesService, peopleService,
107 PeopleWebConstants.OVERVIEW_TYPE_HEADER);
108 readOnlyInfoLbl.setText(labelProvider.getText(context));
109 }
110
111 private void createMailingListPanel(Composite parent, final Node context) throws RepositoryException {
112 RowLayout rl = new RowLayout(SWT.HORIZONTAL);
113 rl.wrap = true;
114 rl.spacing = 8;
115 parent.setLayout(rl);
116 if (context.hasProperty(PeopleNames.PEOPLE_MAILING_LISTS)) {
117
118 Value[] values = context.getProperty(PeopleNames.PEOPLE_MAILING_LISTS).getValues();
119 for (Value value : values) {
120 final String valueStr = value.getString();
121 new Label(parent, SWT.NONE).setText(valueStr);
122
123 Button icon = new Button(parent, SWT.NONE);
124 icon.setLayoutData(CmsUtils.rowData16px());
125 icon.setData(RWT.CUSTOM_VARIANT, "cms_icon_delete");
126 icon.addSelectionListener(new SelectionAdapter() {
127 private static final long serialVersionUID = 1L;
128
129 @Override
130 public void widgetSelected(SelectionEvent e) {
131 ConnectJcrUtils.removeStringFromMultiValuedProp(context, PeopleNames.PEOPLE_MAILING_LISTS,
132 valueStr);
133
134
135 }
136 });
137 }
138 }
139 }
140
141 private void createContactPanel(Composite parent, Node context) {
142 }
143
144 private void createActivityPanel(Composite parent, Node context) {
145 }
146
147
148 private class ImageLabel extends Label {
149 private static final long serialVersionUID = 1L;
150
151 private final Image image;
152
153 private ImageLabel(Composite parent, int style, Image image) {
154 super(parent, style);
155 this.image = image;
156 this.setBackground(parent.getBackground());
157 this.setImage(image);
158
159
160 this.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
161 }
162
163 @Override
164 public void dispose() {
165 if (image != null)
166 image.dispose();
167 super.dispose();
168 }
169
170 }
171
172
173 public void setResourcesService(ResourcesService resourcesService) {
174 this.resourcesService = resourcesService;
175 }
176
177 public void setPeopleService(PeopleService peopleService) {
178 this.peopleService = peopleService;
179 }
180 }