]> git.argeo.org Git - gpl/argeo-jcr.git/blob - swt/org.argeo.tool.devops.e4/src/org/argeo/cms/e4/maintenance/DeploymentEntryPoint.java
Move Argeo SLC JCR components to Argeo JCR
[gpl/argeo-jcr.git] / swt / org.argeo.tool.devops.e4 / src / org / argeo / cms / e4 / maintenance / DeploymentEntryPoint.java
1 package org.argeo.cms.e4.maintenance;
2
3 import java.util.GregorianCalendar;
4 import java.util.TimeZone;
5
6 import org.argeo.api.cms.CmsConstants;
7 import org.argeo.api.cms.CmsContext;
8 import org.argeo.api.cms.CmsDeployment;
9 import org.argeo.api.cms.CmsState;
10 import org.argeo.cms.swt.CmsSwtUtils;
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 {
23 private final BundleContext bc = FrameworkUtil.getBundle(getClass()).getBundleContext();
24
25 protected void createContents(Composite parent) {
26 // FIXME manage authentication if needed
27 // if (!CurrentUser.roles().contains(AuthConstants.ROLE_ADMIN))
28 // return;
29
30 // parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
31 if (isDesktop()) {
32 parent.setLayout(new GridLayout(2, true));
33 } else {
34 // TODO add scrolling
35 parent.setLayout(new GridLayout(1, true));
36 }
37
38 initHighLevelSummary(parent);
39
40 Group securityGroup = createHighLevelGroup(parent, "Security");
41 securityGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
42 new SecurityDeploymentUi(securityGroup, SWT.NONE);
43
44 Group dataGroup = createHighLevelGroup(parent, "Data");
45 dataGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
46 new DataDeploymentUi(dataGroup, SWT.NONE);
47
48 Group logGroup = createHighLevelGroup(parent, "Notifications");
49 logGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
50 new LogDeploymentUi(logGroup, SWT.NONE);
51
52 Group connectivityGroup = createHighLevelGroup(parent, "Connectivity");
53 new ConnectivityDeploymentUi(connectivityGroup, SWT.NONE);
54 connectivityGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
55
56 }
57
58 private void initHighLevelSummary(Composite parent) {
59 Composite composite = new Composite(parent, SWT.NONE);
60 GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
61 if (isDesktop())
62 gridData.horizontalSpan = 3;
63 composite.setLayoutData(gridData);
64 composite.setLayout(new FillLayout());
65
66 ServiceReference<CmsState> nodeStateRef = bc.getServiceReference(CmsState.class);
67 if (nodeStateRef == null)
68 throw new IllegalStateException("No CMS state available");
69 CmsState nodeState = bc.getService(nodeStateRef);
70 ServiceReference<CmsContext> nodeDeploymentRef = bc.getServiceReference(CmsContext.class);
71 Label label = new Label(composite, SWT.WRAP);
72 CmsSwtUtils.markup(label);
73 if (nodeDeploymentRef == null) {
74 label.setText("Not yet deployed on, please configure below.");
75 } else {
76 Object stateUuid = nodeStateRef.getProperty(CmsConstants.CN);
77 CmsContext nodeDeployment = bc.getService(nodeDeploymentRef);
78 GregorianCalendar calendar = new GregorianCalendar();
79 calendar.setTimeInMillis(nodeDeployment.getAvailableSince());
80 calendar.setTimeZone(TimeZone.getDefault());
81 label.setText("Deployment state " + stateUuid + ", available since <b>" + calendar.getTime() + "</b>");
82 }
83 }
84
85 private static Group createHighLevelGroup(Composite parent, String text) {
86 Group group = new Group(parent, SWT.NONE);
87 group.setText(text);
88 CmsSwtUtils.markup(group);
89 return group;
90 }
91
92 private boolean isDesktop() {
93 return true;
94 }
95 }