7e51ede103ce8c1d35c2c49c761b30d2da421919
[gpl/argeo-suite.git] / org.argeo.suite.workbench.rap / src / org / argeo / suite / workbench / parts / DefaultDashboardEditor.java
1 package org.argeo.suite.workbench.parts;
2
3 import javax.jcr.Node;
4 import javax.jcr.NodeIterator;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.argeo.connect.people.PeopleConstants;
9 import org.argeo.connect.people.PeopleTypes;
10 import org.argeo.connect.people.workbench.rap.PeopleRapUtils;
11 import org.argeo.connect.ui.workbench.Refreshable;
12 import org.argeo.connect.util.ConnectJcrUtils;
13 import org.argeo.eclipse.ui.EclipseUiUtils;
14 import org.argeo.suite.workbench.AsUiPlugin;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Composite;
19
20 /** Argeo Suite Default Dashboard */
21 public class DefaultDashboardEditor extends AbstractSuiteDashboard implements Refreshable {
22         final static Log log = LogFactory.getLog(DefaultDashboardEditor.class);
23         public final static String ID = AsUiPlugin.PLUGIN_ID + ".defaultDashboardEditor";
24
25         // Default gadget dimensions
26         private int wh = 300;
27         private int hh = 350;
28
29         private Composite projectsGadget;
30
31         @Override
32         public void createPartControl(Composite parent) {
33                 super.createPartControl(parent);
34
35                 parent.setLayout(new GridLayout());
36                 // Main Layout
37                 Composite body = getFormToolkit().createComposite(parent);
38                 body.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
39
40                 GridLayout bodyLayout = new GridLayout(2, true);
41                 bodyLayout.horizontalSpacing = 20;
42                 bodyLayout.verticalSpacing = 20;
43                 body.setLayout(bodyLayout);
44
45                 // Last updated doc List
46                 projectsGadget = createGadgetCmp(body, wh, hh);
47                 // refreshDocListGadget(projectsGadget);
48
49                 // Contacts
50                 Composite contactGadget = createGadgetCmp(body, wh, hh);
51                 populateContactsGadget(contactGadget);
52         }
53
54         @Override
55         public void forceRefresh(Object object) {
56                 refreshDocListGadget();
57         }
58
59         @Override
60         public void setFocus() {
61                 refreshDocListGadget();
62         }
63
64         /** Links to the various last updated docs */
65         private void refreshDocListGadget() {
66                 EclipseUiUtils.clear(projectsGadget);
67                 projectsGadget.setLayout(EclipseUiUtils.noSpaceGridLayout());
68                 createGadgetTitleCmp(projectsGadget, "Last updated documents");
69                 Composite bodyCmp = createGadgetBodyCmp(projectsGadget);
70
71                 NodeIterator nit = getDocumentsService().getLastUpdatedDocuments(getSession());
72                 while (nit.hasNext()) {
73                         Node file = nit.nextNode();
74                         createOpenEntityEditorLink(getAppWorkbenchService(), bodyCmp, ConnectJcrUtils.getName(file), file);
75                 }
76                 projectsGadget.layout(true, true);
77         }
78
79         /** Links to the various contact search pages */
80         private void populateContactsGadget(Composite parent) {
81                 parent.setLayout(EclipseUiUtils.noSpaceGridLayout());
82                 createGadgetTitleCmp(parent, "Contacts");
83                 Composite bodyCmp = createGadgetBodyCmp(parent);
84
85                 PeopleRapUtils.createOpenSearchEditorLink(getAppWorkbenchService(), bodyCmp, "Persons",
86                                 PeopleTypes.PEOPLE_PERSON, getPeopleService().getBasePath(PeopleTypes.PEOPLE_PERSON));
87
88                 PeopleRapUtils.createOpenSearchEditorLink(getAppWorkbenchService(), bodyCmp, "Organisations",
89                                 PeopleTypes.PEOPLE_ORG, getPeopleService().getBasePath(PeopleTypes.PEOPLE_ORG));
90
91                 Node tagParent = getPeopleService().getResourceService().getTagLikeResourceParent(getSession(),
92                                 PeopleTypes.PEOPLE_MAILING_LIST);
93                 PeopleRapUtils.createOpenSearchEditorLink(getAppWorkbenchService(), bodyCmp, "Mailing lists",
94                                 PeopleTypes.PEOPLE_MAILING_LIST, ConnectJcrUtils.getPath(tagParent));
95
96                 PeopleRapUtils.createOpenSearchEditorLink(getAppWorkbenchService(), bodyCmp, "Tasks", PeopleTypes.PEOPLE_TASK,
97                                 getPeopleService().getBasePath(null));
98
99                 tagParent = getPeopleService().getResourceService().getTagLikeResourceParent(getSession(),
100                                 PeopleConstants.RESOURCE_TAG);
101
102                 PeopleRapUtils.createOpenSearchEditorLink(getAppWorkbenchService(), bodyCmp, "Tags",
103                                 PeopleTypes.PEOPLE_TAG_INSTANCE, ConnectJcrUtils.getPath(tagParent));
104
105         }
106 }