Various small UI enhancements
[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 lastUpdatedDocsGadget;
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 // Contacts
46 Composite contactGadget = createGadgetCmp(body, wh, hh);
47 populateContactsGadget(contactGadget);
48
49 // Last updated doc List
50 lastUpdatedDocsGadget = createGadgetCmp(body, wh, hh);
51 }
52
53 @Override
54 public void forceRefresh(Object object) {
55 refreshDocListGadget();
56 }
57
58 @Override
59 public void setFocus() {
60 refreshDocListGadget();
61 }
62
63 /** Links to the various last updated docs */
64 private void refreshDocListGadget() {
65 EclipseUiUtils.clear(lastUpdatedDocsGadget);
66 lastUpdatedDocsGadget.setLayout(EclipseUiUtils.noSpaceGridLayout());
67 createGadgetTitleCmp(lastUpdatedDocsGadget, "Last updated documents");
68 Composite bodyCmp = createGadgetBodyCmp(lastUpdatedDocsGadget);
69
70 NodeIterator nit = getDocumentsService().getLastUpdatedDocuments(getSession());
71 while (nit.hasNext()) {
72 Node file = nit.nextNode();
73 createOpenEntityEditorLink(getAppWorkbenchService(), bodyCmp, ConnectJcrUtils.getName(file), file);
74 }
75 lastUpdatedDocsGadget.layout(true, true);
76 }
77
78 /** Links to the various contact search pages */
79 private void populateContactsGadget(Composite parent) {
80 parent.setLayout(EclipseUiUtils.noSpaceGridLayout());
81 createGadgetTitleCmp(parent, "Contacts");
82 Composite bodyCmp = createGadgetBodyCmp(parent);
83
84 PeopleRapUtils.createOpenSearchEditorLink(getAppWorkbenchService(), bodyCmp, "Persons",
85 PeopleTypes.PEOPLE_PERSON, getPeopleService().getBasePath(PeopleTypes.PEOPLE_PERSON));
86
87 PeopleRapUtils.createOpenSearchEditorLink(getAppWorkbenchService(), bodyCmp, "Organisations",
88 PeopleTypes.PEOPLE_ORG, getPeopleService().getBasePath(PeopleTypes.PEOPLE_ORG));
89
90 Node tagParent = getPeopleService().getResourceService().getTagLikeResourceParent(getSession(),
91 PeopleTypes.PEOPLE_MAILING_LIST);
92 PeopleRapUtils.createOpenSearchEditorLink(getAppWorkbenchService(), bodyCmp, "Mailing lists",
93 PeopleTypes.PEOPLE_MAILING_LIST, ConnectJcrUtils.getPath(tagParent));
94 PeopleRapUtils.createOpenSearchEditorLink(getAppWorkbenchService(), bodyCmp, "Tasks", PeopleTypes.PEOPLE_TASK,
95 getPeopleService().getBasePath(null));
96
97 tagParent = getPeopleService().getResourceService().getTagLikeResourceParent(getSession(),
98 PeopleConstants.RESOURCE_TAG);
99
100 PeopleRapUtils.createOpenSearchEditorLink(getAppWorkbenchService(), bodyCmp, "Tags",
101 PeopleTypes.PEOPLE_TAG_INSTANCE, ConnectJcrUtils.getPath(tagParent));
102
103 }
104 }