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