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