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