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