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 java
.util
.Comparator
;
23 import org
.argeo
.cms
.ui
.workbench
.WorkbenchUiPlugin
;
24 import org
.argeo
.eclipse
.ui
.ColumnViewerComparator
;
25 import org
.argeo
.eclipse
.ui
.specific
.EclipseUiSpecificUtils
;
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
.eclipse
.ui
.part
.ViewPart
;
34 import org
.osgi
.framework
.Bundle
;
35 import org
.osgi
.framework
.BundleContext
;
38 * Overview of the bundles as a table. Equivalent to Equinox 'ss' console
41 public class BundlesView
extends ViewPart
{
42 private TableViewer viewer
;
45 public void createPartControl(Composite parent
) {
46 viewer
= new TableViewer(parent
);
47 viewer
.setContentProvider(new BundleContentProvider());
48 viewer
.getTable().setHeaderVisible(true);
50 EclipseUiSpecificUtils
.enableToolTipSupport(viewer
);
53 TableViewerColumn column
= new TableViewerColumn(viewer
, SWT
.NONE
);
54 column
.getColumn().setWidth(30);
55 column
.getColumn().setText("ID");
56 column
.getColumn().setAlignment(SWT
.RIGHT
);
57 column
.setLabelProvider(new ColumnLabelProvider() {
58 private static final long serialVersionUID
= -3122136344359358605L;
60 public String
getText(Object element
) {
61 return Long
.toString(((Bundle
) element
).getBundleId());
64 new ColumnViewerComparator
<Bundle
>(column
, new Comparator
<Bundle
>() {
65 public int compare(Bundle o1
, Bundle o2
) {
66 return (int) (o1
.getBundleId() - o2
.getBundleId());
71 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
72 column
.getColumn().setWidth(18);
73 column
.getColumn().setText("State");
74 column
.setLabelProvider(new StateLabelProvider());
75 new ColumnViewerComparator
<Bundle
>(column
, new Comparator
<Bundle
>() {
76 public int compare(Bundle o1
, Bundle o2
) {
77 return o1
.getState() - o2
.getState();
82 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
83 column
.getColumn().setWidth(250);
84 column
.getColumn().setText("Symbolic Name");
85 column
.setLabelProvider(new ColumnLabelProvider() {
86 private static final long serialVersionUID
= -4280840684440451080L;
88 public String
getText(Object element
) {
89 return ((Bundle
) element
).getSymbolicName();
92 new ColumnViewerComparator
<Bundle
>(column
, new Comparator
<Bundle
>() {
93 public int compare(Bundle o1
, Bundle o2
) {
94 return o1
.getSymbolicName().compareTo(o2
.getSymbolicName());
99 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
100 column
.getColumn().setWidth(150);
101 column
.getColumn().setText("Version");
102 column
.setLabelProvider(new ColumnLabelProvider() {
103 private static final long serialVersionUID
= 6871926308708629989L;
105 public String
getText(Object element
) {
106 Bundle bundle
= (org
.osgi
.framework
.Bundle
) element
;
107 return bundle
.getVersion().toString();
110 new ColumnViewerComparator
<Bundle
>(column
, new Comparator
<Bundle
>() {
111 public int compare(Bundle o1
, Bundle o2
) {
112 return o1
.getVersion().compareTo(o2
.getVersion());
116 viewer
.setInput(WorkbenchUiPlugin
.getDefault().getBundle()
117 .getBundleContext());
122 public void setFocus() {
124 viewer
.getControl().setFocus();
127 /** Content provider managing the array of bundles */
128 private static class BundleContentProvider
implements
129 IStructuredContentProvider
{
130 private static final long serialVersionUID
= -8533792785725875977L;
132 public Object
[] getElements(Object inputElement
) {
133 if (inputElement
instanceof BundleContext
) {
134 BundleContext bc
= (BundleContext
) inputElement
;
135 return bc
.getBundles();
140 public void dispose() {
143 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {