Add missing setter
[gpl/argeo-suite.git] / org.argeo.suite.web / src / org / argeo / suite / web / DefaultMainPage.java
1 package org.argeo.suite.web;
2
3 import java.nio.file.spi.FileSystemProvider;
4 import java.util.Locale;
5 import java.util.Map;
6
7 import javax.jcr.Node;
8 import javax.jcr.RepositoryException;
9 import javax.jcr.Session;
10 import javax.jcr.nodetype.NodeType;
11
12 import org.argeo.cms.CmsMsg;
13 import org.argeo.cms.auth.CurrentUser;
14 import org.argeo.cms.ui.CmsUiProvider;
15 import org.argeo.cms.ui.CmsView;
16 import org.argeo.cms.ui.LifeCycleUiProvider;
17 import org.argeo.cms.util.CmsUtils;
18 import org.argeo.cms.widgets.auth.CmsLogin;
19 import org.argeo.connect.AppMaintenanceService;
20 import org.argeo.connect.ConnectTypes;
21 import org.argeo.connect.resources.ResourcesService;
22 import org.argeo.eclipse.ui.EclipseUiUtils;
23 import org.argeo.people.PeopleService;
24 import org.argeo.people.PeopleTypes;
25 import org.argeo.people.web.pages.PeopleDefaultPage;
26 import org.argeo.suite.web.fs.MyFilesBrowserPage;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.events.SelectionListener;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.Button;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Control;
34 import org.eclipse.swt.widgets.Label;
35
36 /**
37 * Default entry point for the Argeo Suite CMS. Forwards the request to the
38 * relevant CmsUiProvider
39 */
40 public class DefaultMainPage implements LifeCycleUiProvider {
41
42 private CmsUiProvider dashboardPage;
43 private CmsUiProvider peoplePage;
44 private CmsUiProvider fsBrowserPage;
45
46 /* DEPENDENCY INJECTION */
47 private ResourcesService resourcesService;
48 private PeopleService peopleService;
49 private FileSystemProvider nodeFileSystemProvider;
50 private Map<String, String> peopleIconPaths;
51
52 public DefaultMainPage() {
53 }
54
55 @Override
56 public void init(Session adminSession) throws RepositoryException {
57 dashboardPage = new DefaultDashboard(resourcesService, peopleService, peopleIconPaths);
58 peoplePage = new PeopleDefaultPage(resourcesService, peopleService, peopleIconPaths);
59 fsBrowserPage = new MyFilesBrowserPage(nodeFileSystemProvider);
60 }
61
62 @Override
63 public Control createUi(Composite parent, Node context) throws RepositoryException {
64 if (CurrentUser.isAnonymous())
65 return createAnonymousUi(parent, context);
66
67 if (context.isNodeType(ConnectTypes.CONNECT_ENTITY))
68 return peoplePage.createUi(parent, context);
69 else if (("/" + peopleService.getBaseRelPath(PeopleTypes.PEOPLE_PERSON)).equals(context.getPath()))
70 return peoplePage.createUi(parent, context);
71 else if (context.isNodeType(NodeType.NT_FOLDER) || context.isNodeType(NodeType.NT_FILE))
72 return fsBrowserPage.createUi(parent, context);
73 else
74 return dashboardPage.createUi(parent, context);
75 }
76
77 public Control createAnonymousUi(Composite parent, Node context) throws RepositoryException {
78 parent.setLayout(new GridLayout());
79 Composite body = new Composite(parent, SWT.NO_FOCUS);
80 body.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
81 body.setLayout(new GridLayout());
82
83 Composite loginCmp = new Composite(body, SWT.NO_FOCUS);
84 loginCmp.setLayout(EclipseUiUtils.noSpaceGridLayout());
85 loginCmp.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
86
87 CmsLogin login = new MyCmsLogin(CmsUtils.getCmsView());
88 // Composite credBlockCmp =
89 login.createCredentialsBlock(loginCmp);
90 // Use a custom style that has no border, among other
91 // CmsUtils.style(loginCmp, ArgeoStyles.LOGIN_INLINE_CREDBLOCK);
92
93 Label anonymousLbl = new Label(body, SWT.WRAP);
94 anonymousLbl.setText("You should login or register to access your private dashboard");
95
96 return body;
97
98 }
99
100 private class MyCmsLogin extends CmsLogin {
101
102 public MyCmsLogin(CmsView cmsView) {
103 super(cmsView);
104 }
105
106 @Override
107 protected boolean login() {
108 boolean result = super.login();
109 return result;
110 }
111
112 @Override
113 protected void extendsCredentialsBlock(Composite credentialsBlock, Locale selectedLocale,
114 SelectionListener loginSelectionListener) {
115 Button loginBtn = new Button(credentialsBlock, SWT.PUSH);
116 loginBtn.setText(CmsMsg.login.lead(selectedLocale));
117 loginBtn.setLayoutData(CmsUtils.fillWidth());
118 loginBtn.addSelectionListener(loginSelectionListener);
119 // CmsUtils.style(loginBtn, ArgeoStyles.LOGIN_SIGNIN_BTN);
120 }
121 }
122
123 @Override
124 public void destroy() {
125 }
126
127 /* DEPENDENCY INJECTION */
128 public void setResourcesService(ResourcesService resourcesService) {
129 this.resourcesService = resourcesService;
130 }
131
132 public void setPeopleService(PeopleService peopleService) {
133 this.peopleService = peopleService;
134 }
135
136 public void setNodeFileSystemProvider(FileSystemProvider nodeFileSystemProvider) {
137 this.nodeFileSystemProvider = nodeFileSystemProvider;
138 }
139
140 public void setPeopleIconPaths(Map<String, String> peopleIconPaths) {
141 this.peopleIconPaths = peopleIconPaths;
142 }
143
144 // Only used has a blocker.
145 public void setSuiteMaintenanceService(AppMaintenanceService suiteMaintenanceService) {
146 }
147
148 }