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