1b0b9500eabc71c4f587dc8c7219530429f9529c
[gpl/argeo-suite.git] / org.argeo.suite.workbench.rap / src / org / argeo / suite / workbench / parts / AbstractSuiteDashboard.java
1 package org.argeo.suite.workbench.parts;
2
3 import javax.jcr.Repository;
4 import javax.jcr.Session;
5
6 import org.argeo.cms.util.CmsUtils;
7 import org.argeo.connect.people.PeopleService;
8 import org.argeo.connect.people.workbench.rap.PeopleStyles;
9 import org.argeo.connect.people.workbench.rap.editors.util.EntityEditorInput;
10 import org.argeo.connect.ui.workbench.AppWorkbenchService;
11 import org.argeo.connect.util.ConnectJcrUtils;
12 import org.argeo.eclipse.ui.EclipseUiUtils;
13 import org.argeo.jcr.JcrUtils;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.layout.GridLayout;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Label;
21 import org.eclipse.ui.IEditorInput;
22 import org.eclipse.ui.IEditorSite;
23 import org.eclipse.ui.PartInitException;
24 import org.eclipse.ui.forms.widgets.FormToolkit;
25 import org.eclipse.ui.part.EditorPart;
26
27 /** Generic dashboard for Argeo Suite applications */
28 public abstract class AbstractSuiteDashboard extends EditorPart {
29
30 // DEPENDENCY INJECTION
31 private Repository repository;
32 private PeopleService peopleService;
33 private AppWorkbenchService appWorkbenchService;
34
35 private Session session;
36
37 // UI Objects
38 private Image logoImg;
39 private FormToolkit toolkit;
40
41 @Override
42 public void init(IEditorSite site, IEditorInput input) throws PartInitException {
43 setSite(site);
44 setInput(input);
45
46 session = ConnectJcrUtils.login(repository);
47 // initialiseImg();
48 updateTooltip(input);
49 }
50
51 private void updateTooltip(IEditorInput input) {
52 if (input instanceof EntityEditorInput) {
53 EntityEditorInput sei = (EntityEditorInput) input;
54 sei.setTooltipText("My Dashboard");
55 }
56 }
57
58 // private void initialiseImg() {
59 // InputStream is = null;
60 // try {
61 // String imgPath = peopleService.getInstanceConfPath() + "/"
62 // + AoNames.AO_DEFAULT_LOGO;
63 // if (session.nodeExists(imgPath)) {
64 // Node imageNode = session.getNode(imgPath).getNode(
65 // Node.JCR_CONTENT);
66 // is = imageNode.getProperty(Property.JCR_DATA).getBinary()
67 // .getStream();
68 // logoImg = new Image(this.getSite().getShell().getDisplay(), is);
69 // }
70 // } catch (RepositoryException re) {
71 // throw new AoException(
72 // "Unable to initialise specific logo for demo app", re);
73 // } finally {
74 // IOUtils.closeQuietly(is);
75 // }
76 // }
77
78 /**
79 * Implementing classes must call super in order to create the correct form
80 * toolkit
81 */
82 @Override
83 public void createPartControl(Composite parent) {
84 toolkit = new FormToolkit(getSite().getShell().getDisplay());
85 }
86
87 // UTILS
88 protected Composite createGadgetCmp(Composite parent, int widthHint, int heightHint) {
89 Composite gadgetCmp = toolkit.createComposite(parent, SWT.BORDER);
90 GridData gd = new GridData(SWT.CENTER, SWT.CENTER, false, false);
91 gd.widthHint = widthHint;
92 gd.heightHint = heightHint;
93 gadgetCmp.setLayoutData(gd);
94 CmsUtils.style(gadgetCmp, PeopleStyles.PEOPLE_CLASS_GADGET);
95 return gadgetCmp;
96 }
97
98 protected Composite createGadgetTitleCmp(Composite parent, String title) {
99 Composite titleCmp = toolkit.createComposite(parent, SWT.BACKGROUND | SWT.INHERIT_NONE);
100 CmsUtils.style(titleCmp, PeopleStyles.GADGET_HEADER);
101 titleCmp.setBackground(null);
102 GridData gd = new GridData(SWT.FILL, SWT.TOP, true, false);
103 titleCmp.setLayoutData(gd);
104 titleCmp.setLayout(new GridLayout());
105
106 Label titleLbl = toolkit.createLabel(titleCmp, title + " ", SWT.BOLD);
107 CmsUtils.style(titleLbl, PeopleStyles.GADGET_HEADER);
108 titleLbl.setBackground(null);
109 return titleCmp;
110 }
111
112 protected Composite createGadgetBodyCmp(Composite parent) {
113 Composite bodyCmp = toolkit.createComposite(parent, SWT.BACKGROUND | SWT.INHERIT_NONE);
114 bodyCmp.setLayoutData(EclipseUiUtils.fillAll());
115 bodyCmp.setLayout(new GridLayout());
116 return bodyCmp;
117 }
118
119 // LIFE CYCLE
120 @Override
121 public void dispose() {
122 JcrUtils.logoutQuietly(session);
123 if (logoImg != null)
124 logoImg.dispose();
125 super.dispose();
126 }
127
128 @Override
129 public void doSave(IProgressMonitor monitor) {
130 }
131
132 @Override
133 public void doSaveAs() {
134 }
135
136 @Override
137 public boolean isDirty() {
138 return false;
139 }
140
141 @Override
142 public boolean isSaveAsAllowed() {
143 return false;
144 }
145
146 @Override
147 public void setFocus() {
148 // Do nothing
149 }
150
151 // Expose to implementing classes
152 protected PeopleService getPeopleService() {
153 return peopleService;
154 }
155
156 protected AppWorkbenchService getAppWorkbenchService() {
157 return appWorkbenchService;
158 }
159
160 protected Session getSession() {
161 return session;
162 }
163
164 protected Image getLogoImg() {
165 return logoImg;
166 }
167
168 protected FormToolkit getFormToolkit() {
169 return toolkit;
170 }
171
172 /* DEPENDENCY INJECTION */
173 public void setRepository(Repository repository) {
174 this.repository = repository;
175 }
176
177 public void setAppWorkbenchService(AppWorkbenchService appWorkbenchService) {
178 this.appWorkbenchService = appWorkbenchService;
179 }
180
181 public void setPeopleService(PeopleService peopleService) {
182 this.peopleService = peopleService;
183 }
184 }