1 //package org.argeo.eclipse.ui.workbench.osgi;
2 //public class BundlesView {}
5 * Copyright (C) 2007-2012 Argeo GmbH
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 package org
.argeo
.cms
.e4
.monitoring
;
21 import javax
.annotation
.PostConstruct
;
23 import org
.argeo
.eclipse
.ui
.ColumnViewerComparator
;
24 import org
.argeo
.eclipse
.ui
.specific
.EclipseUiSpecificUtils
;
25 import org
.eclipse
.e4
.ui
.di
.Focus
;
26 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
27 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
28 import org
.eclipse
.jface
.viewers
.TableViewer
;
29 import org
.eclipse
.jface
.viewers
.TableViewerColumn
;
30 import org
.eclipse
.jface
.viewers
.Viewer
;
31 import org
.eclipse
.swt
.SWT
;
32 import org
.eclipse
.swt
.widgets
.Composite
;
33 import org
.osgi
.framework
.Bundle
;
34 import org
.osgi
.framework
.BundleContext
;
35 import org
.osgi
.framework
.FrameworkUtil
;
38 * Overview of the bundles as a table. Equivalent to Equinox 'ss' console
41 public class BundlesView
{
42 private final static BundleContext bc
= FrameworkUtil
.getBundle(BundlesView
.class).getBundleContext();
43 private TableViewer viewer
;
46 public void createPartControl(Composite parent
) {
47 viewer
= new TableViewer(parent
);
48 viewer
.setContentProvider(new BundleContentProvider());
49 viewer
.getTable().setHeaderVisible(true);
51 EclipseUiSpecificUtils
.enableToolTipSupport(viewer
);
54 TableViewerColumn column
= new TableViewerColumn(viewer
, SWT
.NONE
);
55 column
.getColumn().setWidth(30);
56 column
.getColumn().setText("ID");
57 column
.getColumn().setAlignment(SWT
.RIGHT
);
58 column
.setLabelProvider(new ColumnLabelProvider() {
59 private static final long serialVersionUID
= -3122136344359358605L;
61 public String
getText(Object element
) {
62 return Long
.toString(((Bundle
) element
).getBundleId());
65 new ColumnViewerComparator(column
);
68 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
69 column
.getColumn().setWidth(18);
70 column
.getColumn().setText("State");
71 column
.setLabelProvider(new StateLabelProvider());
72 new ColumnViewerComparator(column
);
75 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
76 column
.getColumn().setWidth(250);
77 column
.getColumn().setText("Symbolic Name");
78 column
.setLabelProvider(new ColumnLabelProvider() {
79 private static final long serialVersionUID
= -4280840684440451080L;
81 public String
getText(Object element
) {
82 return ((Bundle
) element
).getSymbolicName();
85 new ColumnViewerComparator(column
);
88 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
89 column
.getColumn().setWidth(250);
90 column
.getColumn().setText("Version");
91 column
.setLabelProvider(new ColumnLabelProvider() {
92 private static final long serialVersionUID
= 6871926308708629989L;
94 public String
getText(Object element
) {
95 Bundle bundle
= (org
.osgi
.framework
.Bundle
) element
;
96 return bundle
.getVersion().toString();
99 new ColumnViewerComparator(column
);
106 public void setFocus() {
108 viewer
.getControl().setFocus();
111 /** Content provider managing the array of bundles */
112 private static class BundleContentProvider
implements IStructuredContentProvider
{
113 private static final long serialVersionUID
= -8533792785725875977L;
115 public Object
[] getElements(Object inputElement
) {
116 if (inputElement
instanceof BundleContext
) {
117 BundleContext bc
= (BundleContext
) inputElement
;
118 return bc
.getBundles();
123 public void dispose() {
126 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {