]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/maintenance/DeploymentEntryPoint.java
6e4d5abcb00e2bbcb045248b54377c3a9bb1aa2e
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / maintenance / DeploymentEntryPoint.java
1 package org.argeo.cms.maintenance;
2
3 import java.util.GregorianCalendar;
4 import java.util.TimeZone;
5
6 import org.argeo.cms.auth.AuthConstants;
7 import org.argeo.cms.auth.CurrentUser;
8 import org.argeo.cms.util.CmsUtils;
9 import org.argeo.node.NodeConstants;
10 import org.argeo.node.NodeDeployment;
11 import org.argeo.node.NodeState;
12 import org.eclipse.rap.rwt.application.AbstractEntryPoint;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.layout.FillLayout;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Group;
19 import org.eclipse.swt.widgets.Label;
20 import org.osgi.framework.BundleContext;
21 import org.osgi.framework.FrameworkUtil;
22 import org.osgi.framework.ServiceReference;
23
24 class DeploymentEntryPoint extends AbstractEntryPoint {
25 private static final long serialVersionUID = -881152502968982437L;
26 private final BundleContext bc = FrameworkUtil.getBundle(getClass()).getBundleContext();
27
28 @Override
29 protected void createContents(Composite parent) {
30 if (!CurrentUser.roles().contains(AuthConstants.ROLE_ADMIN))
31 return;
32
33 // parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
34 if (isDesktop()) {
35 parent.setLayout(new GridLayout(2, true));
36 } else {
37 // TODO add scrolling
38 parent.setLayout(new GridLayout(1, true));
39 }
40
41 initHighLevelSummary(parent);
42
43 Group securityGroup = createHighLevelGroup(parent, "Security");
44 securityGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
45 new SecurityDeploymentUi(securityGroup, SWT.NONE);
46
47 Group dataGroup = createHighLevelGroup(parent, "Data");
48 dataGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
49 new DataDeploymentUi(dataGroup, SWT.NONE);
50
51 Group logGroup = createHighLevelGroup(parent, "Notifications");
52 logGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
53 new LogDeploymentUi(logGroup, SWT.NONE);
54
55 Group connectivityGroup = createHighLevelGroup(parent, "Connectivity");
56 new ConnectivityDeploymentUi(connectivityGroup, SWT.NONE);
57 connectivityGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
58
59 }
60
61 private void initHighLevelSummary(Composite parent) {
62 Composite composite = new Composite(parent, SWT.NONE);
63 GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
64 if (isDesktop())
65 gridData.horizontalSpan = 3;
66 composite.setLayoutData(gridData);
67 composite.setLayout(new FillLayout());
68
69 ServiceReference<NodeState> nodeStateRef = bc.getServiceReference(NodeState.class);
70 if (nodeStateRef == null)
71 throw new IllegalStateException("No CMS state available");
72 NodeState nodeState = bc.getService(nodeStateRef);
73 ServiceReference<NodeDeployment> nodeDeploymentRef = bc.getServiceReference(NodeDeployment.class);
74 Label label = new Label(composite, SWT.WRAP);
75 CmsUtils.markup(label);
76 if (nodeDeploymentRef == null) {
77 label.setText("Not yet deployed on <br>" + nodeState.getHostname() + "</br>, please configure below.");
78 } else {
79 Object stateUuid = nodeStateRef.getProperty(NodeConstants.CN);
80 NodeDeployment nodeDeployment = bc.getService(nodeDeploymentRef);
81 GregorianCalendar calendar = new GregorianCalendar();
82 calendar.setTimeInMillis(nodeDeployment.getAvailableSince());
83 calendar.setTimeZone(TimeZone.getDefault());
84 label.setText("[" + "<b>" + nodeState.getHostname() + "</b>]# " + "Deployment state " + stateUuid
85 + ", available since <b>" + calendar.getTime() + "</b>");
86 }
87 }
88
89 private static Group createHighLevelGroup(Composite parent, String text) {
90 Group group = new Group(parent, SWT.NONE);
91 group.setText(text);
92 CmsUtils.markup(group);
93 return group;
94 }
95
96 private boolean isDesktop() {
97 return true;
98 }
99 }