]> git.argeo.org Git - gpl/argeo-jcr.git/blob - swt/org.argeo.tool.devops.e4/src/org/argeo/cms/e4/monitoring/BundlesView.java
Prepare next development cycle
[gpl/argeo-jcr.git] / swt / org.argeo.tool.devops.e4 / src / org / argeo / cms / e4 / monitoring / BundlesView.java
1 //package org.argeo.eclipse.ui.workbench.osgi;
2 //public class BundlesView {}
3
4 package org.argeo.cms.e4.monitoring;
5
6 import org.argeo.eclipse.ui.ColumnViewerComparator;
7 import org.eclipse.e4.ui.di.Focus;
8 import org.eclipse.jface.viewers.ColumnLabelProvider;
9 import org.eclipse.jface.viewers.IStructuredContentProvider;
10 import org.eclipse.jface.viewers.TableViewer;
11 import org.eclipse.jface.viewers.TableViewerColumn;
12 import org.eclipse.jface.viewers.Viewer;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.widgets.Composite;
15 import org.osgi.framework.Bundle;
16 import org.osgi.framework.BundleContext;
17 import org.osgi.framework.FrameworkUtil;
18
19 import jakarta.annotation.PostConstruct;
20
21 /**
22 * Overview of the bundles as a table. Equivalent to Equinox 'ss' console
23 * command.
24 */
25 public class BundlesView {
26 private final static BundleContext bc = FrameworkUtil.getBundle(BundlesView.class).getBundleContext();
27 private TableViewer viewer;
28
29 @PostConstruct
30 public void createPartControl(Composite parent) {
31 viewer = new TableViewer(parent);
32 viewer.setContentProvider(new BundleContentProvider());
33 viewer.getTable().setHeaderVisible(true);
34
35 //EclipseUiSpecificUtils.enableToolTipSupport(viewer);
36
37 // ID
38 TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
39 column.getColumn().setWidth(30);
40 column.getColumn().setText("ID");
41 column.getColumn().setAlignment(SWT.RIGHT);
42 column.setLabelProvider(new ColumnLabelProvider() {
43 private static final long serialVersionUID = -3122136344359358605L;
44
45 public String getText(Object element) {
46 return Long.toString(((Bundle) element).getBundleId());
47 }
48 });
49 new ColumnViewerComparator(column);
50
51 // State
52 column = new TableViewerColumn(viewer, SWT.NONE);
53 column.getColumn().setWidth(18);
54 column.getColumn().setText("State");
55 column.setLabelProvider(new StateLabelProvider());
56 new ColumnViewerComparator(column);
57
58 // Symbolic name
59 column = new TableViewerColumn(viewer, SWT.NONE);
60 column.getColumn().setWidth(250);
61 column.getColumn().setText("Symbolic Name");
62 column.setLabelProvider(new ColumnLabelProvider() {
63 private static final long serialVersionUID = -4280840684440451080L;
64
65 public String getText(Object element) {
66 return ((Bundle) element).getSymbolicName();
67 }
68 });
69 new ColumnViewerComparator(column);
70
71 // Version
72 column = new TableViewerColumn(viewer, SWT.NONE);
73 column.getColumn().setWidth(250);
74 column.getColumn().setText("Version");
75 column.setLabelProvider(new ColumnLabelProvider() {
76 private static final long serialVersionUID = 6871926308708629989L;
77
78 public String getText(Object element) {
79 Bundle bundle = (org.osgi.framework.Bundle) element;
80 return bundle.getVersion().toString();
81 }
82 });
83 new ColumnViewerComparator(column);
84
85 viewer.setInput(bc);
86
87 }
88
89 @Focus
90 public void setFocus() {
91 if (viewer != null)
92 viewer.getControl().setFocus();
93 }
94
95 /** Content provider managing the array of bundles */
96 private static class BundleContentProvider implements IStructuredContentProvider {
97 private static final long serialVersionUID = -8533792785725875977L;
98
99 public Object[] getElements(Object inputElement) {
100 if (inputElement instanceof BundleContext) {
101 BundleContext bc = (BundleContext) inputElement;
102 return bc.getBundles();
103 }
104 return null;
105 }
106
107 public void dispose() {
108 }
109
110 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
111 }
112 }
113 }