]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/maintenance/DeploymentEntryPoint.java
[maven-release-plugin] prepare release argeo-commons-2.1.46
[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 // FIXME manage authentication if needed
31 // if (!CurrentUser.roles().contains(AuthConstants.ROLE_ADMIN))
32 // return;
33
34 // parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
35 if (isDesktop()) {
36 parent.setLayout(new GridLayout(2, true));
37 } else {
38 // TODO add scrolling
39 parent.setLayout(new GridLayout(1, true));
40 }
41
42 initHighLevelSummary(parent);
43
44 Group securityGroup = createHighLevelGroup(parent, "Security");
45 securityGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
46 new SecurityDeploymentUi(securityGroup, SWT.NONE);
47
48 Group dataGroup = createHighLevelGroup(parent, "Data");
49 dataGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
50 new DataDeploymentUi(dataGroup, SWT.NONE);
51
52 Group logGroup = createHighLevelGroup(parent, "Notifications");
53 logGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
54 new LogDeploymentUi(logGroup, SWT.NONE);
55
56 Group connectivityGroup = createHighLevelGroup(parent, "Connectivity");
57 new ConnectivityDeploymentUi(connectivityGroup, SWT.NONE);
58 connectivityGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
59
60 }
61
62 private void initHighLevelSummary(Composite parent) {
63 Composite composite = new Composite(parent, SWT.NONE);
64 GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
65 if (isDesktop())
66 gridData.horizontalSpan = 3;
67 composite.setLayoutData(gridData);
68 composite.setLayout(new FillLayout());
69
70 ServiceReference<NodeState> nodeStateRef = bc.getServiceReference(NodeState.class);
71 if (nodeStateRef == null)
72 throw new IllegalStateException("No CMS state available");
73 NodeState nodeState = bc.getService(nodeStateRef);
74 ServiceReference<NodeDeployment> nodeDeploymentRef = bc.getServiceReference(NodeDeployment.class);
75 Label label = new Label(composite, SWT.WRAP);
76 CmsUtils.markup(label);
77 if (nodeDeploymentRef == null) {
78 label.setText("Not yet deployed on <br>" + nodeState.getHostname() + "</br>, please configure below.");
79 } else {
80 Object stateUuid = nodeStateRef.getProperty(NodeConstants.CN);
81 NodeDeployment nodeDeployment = bc.getService(nodeDeploymentRef);
82 GregorianCalendar calendar = new GregorianCalendar();
83 calendar.setTimeInMillis(nodeDeployment.getAvailableSince());
84 calendar.setTimeZone(TimeZone.getDefault());
85 label.setText("[" + "<b>" + nodeState.getHostname() + "</b>]# " + "Deployment state " + stateUuid
86 + ", available since <b>" + calendar.getTime() + "</b>");
87 }
88 }
89
90 private static Group createHighLevelGroup(Composite parent, String text) {
91 Group group = new Group(parent, SWT.NONE);
92 group.setText(text);
93 CmsUtils.markup(group);
94 return group;
95 }
96
97 private boolean isDesktop() {
98 return true;
99 }
100 }