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
.ui
.workbench
.osgi
;
21 import org
.argeo
.cms
.ui
.workbench
.WorkbenchUiPlugin
;
22 import org
.argeo
.eclipse
.ui
.ColumnViewerComparator
;
23 import org
.argeo
.eclipse
.ui
.specific
.EclipseUiSpecificUtils
;
24 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
25 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
26 import org
.eclipse
.jface
.viewers
.TableViewer
;
27 import org
.eclipse
.jface
.viewers
.TableViewerColumn
;
28 import org
.eclipse
.jface
.viewers
.Viewer
;
29 import org
.eclipse
.swt
.SWT
;
30 import org
.eclipse
.swt
.widgets
.Composite
;
31 import org
.eclipse
.ui
.part
.ViewPart
;
32 import org
.osgi
.framework
.Bundle
;
33 import org
.osgi
.framework
.BundleContext
;
36 * Overview of the bundles as a table. Equivalent to Equinox 'ss' console
39 public class BundlesView
extends ViewPart
{
40 private TableViewer viewer
;
43 public void createPartControl(Composite parent
) {
44 viewer
= new TableViewer(parent
);
45 viewer
.setContentProvider(new BundleContentProvider());
46 viewer
.getTable().setHeaderVisible(true);
48 EclipseUiSpecificUtils
.enableToolTipSupport(viewer
);
51 TableViewerColumn column
= new TableViewerColumn(viewer
, SWT
.NONE
);
52 column
.getColumn().setWidth(30);
53 column
.getColumn().setText("ID");
54 column
.getColumn().setAlignment(SWT
.RIGHT
);
55 column
.setLabelProvider(new ColumnLabelProvider() {
56 private static final long serialVersionUID
= -3122136344359358605L;
58 public String
getText(Object element
) {
59 return Long
.toString(((Bundle
) element
).getBundleId());
62 new ColumnViewerComparator(column
);
65 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
66 column
.getColumn().setWidth(18);
67 column
.getColumn().setText("State");
68 column
.setLabelProvider(new StateLabelProvider());
69 new ColumnViewerComparator(column
);
72 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
73 column
.getColumn().setWidth(250);
74 column
.getColumn().setText("Symbolic Name");
75 column
.setLabelProvider(new ColumnLabelProvider() {
76 private static final long serialVersionUID
= -4280840684440451080L;
78 public String
getText(Object element
) {
79 return ((Bundle
) element
).getSymbolicName();
82 new ColumnViewerComparator(column
);
85 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
86 column
.getColumn().setWidth(150);
87 column
.getColumn().setText("Version");
88 column
.setLabelProvider(new ColumnLabelProvider() {
89 private static final long serialVersionUID
= 6871926308708629989L;
91 public String
getText(Object element
) {
92 Bundle bundle
= (org
.osgi
.framework
.Bundle
) element
;
93 return bundle
.getVersion().toString();
96 new ColumnViewerComparator(column
);
98 viewer
.setInput(WorkbenchUiPlugin
.getDefault().getBundle().getBundleContext());
103 public void setFocus() {
105 viewer
.getControl().setFocus();
108 /** Content provider managing the array of bundles */
109 private static class BundleContentProvider
implements IStructuredContentProvider
{
110 private static final long serialVersionUID
= -8533792785725875977L;
112 public Object
[] getElements(Object inputElement
) {
113 if (inputElement
instanceof BundleContext
) {
114 BundleContext bc
= (BundleContext
) inputElement
;
115 return bc
.getBundles();
120 public void dispose() {
123 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {