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