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
.eclipse
.ui
.workbench
.osgi
;
21 import java
.util
.Comparator
;
23 import org
.argeo
.eclipse
.ui
.ColumnViewerComparator
;
24 import org
.argeo
.eclipse
.ui
.specific
.EclipseUiSpecificUtils
;
25 import org
.argeo
.eclipse
.ui
.workbench
.WorkbenchUiPlugin
;
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
.graphics
.Image
;
33 import org
.eclipse
.swt
.widgets
.Composite
;
34 import org
.eclipse
.ui
.part
.ViewPart
;
35 import org
.osgi
.framework
.Bundle
;
36 import org
.osgi
.framework
.BundleContext
;
39 * Overview of the bundles as a table. Equivalent to Equinox 'ss' console
43 // public class BundlesView {}
45 public class BundlesView
extends ViewPart
{
46 private TableViewer viewer
;
49 public void createPartControl(Composite parent
) {
50 viewer
= new TableViewer(parent
);
51 viewer
.setContentProvider(new BundleContentProvider());
52 viewer
.getTable().setHeaderVisible(true);
54 EclipseUiSpecificUtils
.enableToolTipSupport(viewer
);
57 TableViewerColumn column
= new TableViewerColumn(viewer
, SWT
.NONE
);
58 column
.getColumn().setWidth(30);
59 column
.getColumn().setText("ID");
60 column
.getColumn().setAlignment(SWT
.RIGHT
);
61 column
.setLabelProvider(new ColumnLabelProvider() {
62 private static final long serialVersionUID
= -3122136344359358605L;
64 public String
getText(Object element
) {
65 return Long
.toString(((Bundle
) element
).getBundleId());
68 new ColumnViewerComparator
<Bundle
>(column
, new Comparator
<Bundle
>() {
69 public int compare(Bundle o1
, Bundle o2
) {
70 return (int) (o1
.getBundleId() - o2
.getBundleId());
75 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
76 column
.getColumn().setWidth(18);
77 column
.getColumn().setText("State");
78 column
.setLabelProvider(new StateLabelProvider());
79 new ColumnViewerComparator
<Bundle
>(column
, new Comparator
<Bundle
>() {
80 public int compare(Bundle o1
, Bundle o2
) {
81 return o1
.getState() - o2
.getState();
86 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
87 column
.getColumn().setWidth(300);
88 column
.getColumn().setText("Symbolic Name");
89 column
.setLabelProvider(new ColumnLabelProvider() {
90 private static final long serialVersionUID
= -4280840684440451080L;
92 public String
getText(Object element
) {
93 return ((Bundle
) element
).getSymbolicName();
96 new ColumnViewerComparator
<Bundle
>(column
, new Comparator
<Bundle
>() {
97 public int compare(Bundle o1
, Bundle o2
) {
98 return o1
.getSymbolicName().compareTo(o2
.getSymbolicName());
103 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
104 column
.getColumn().setWidth(150);
105 column
.getColumn().setText("Version");
106 column
.setLabelProvider(new ColumnLabelProvider() {
107 private static final long serialVersionUID
= 6871926308708629989L;
109 public String
getText(Object element
) {
112 // FIXME triggers compilation failure
113 Bundle bundle
= (org
.osgi
.framework
.Bundle
) element
;
114 return bundle
.getVersion().toString();
117 new ColumnViewerComparator
<Bundle
>(column
, new Comparator
<Bundle
>() {
118 public int compare(Bundle o1
, Bundle o2
) {
120 // FIXME getVersion() triggers compilation failure
121 // return o1.getVersion().compareTo(o2.getVersion());
125 viewer
.setInput(WorkbenchUiPlugin
.getDefault().getBundle()
126 .getBundleContext());
131 public void setFocus() {
133 viewer
.getControl().setFocus();
136 /** Content provider managing the array of bundles */
137 private static class BundleContentProvider
implements
138 IStructuredContentProvider
{
139 private static final long serialVersionUID
= -8533792785725875977L;
141 public Object
[] getElements(Object inputElement
) {
142 if (inputElement
instanceof BundleContext
) {
143 BundleContext bc
= (BundleContext
) inputElement
;
144 return bc
.getBundles();
149 public void dispose() {
152 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
157 /** Label provider for the state column */
158 private static class StateLabelProvider
extends ColumnLabelProvider
{
159 private static final long serialVersionUID
= -7885583135316000733L;
162 public Image
getImage(Object element
) {
163 Integer state
= ((Bundle
) element
).getState();
165 case Bundle
.UNINSTALLED
:
166 return OsgiExplorerImages
.INSTALLED
;
167 case Bundle
.INSTALLED
:
168 return OsgiExplorerImages
.INSTALLED
;
169 case Bundle
.RESOLVED
:
170 return OsgiExplorerImages
.RESOLVED
;
171 case Bundle
.STARTING
:
172 return OsgiExplorerImages
.STARTING
;
173 case Bundle
.STOPPING
:
174 return OsgiExplorerImages
.STARTING
;
176 return OsgiExplorerImages
.ACTIVE
;
183 public String
getText(Object element
) {
188 public String
getToolTipText(Object element
) {
189 Bundle bundle
= (Bundle
) element
;
190 Integer state
= bundle
.getState();
192 case Bundle
.UNINSTALLED
:
193 return "UNINSTALLED";
194 case Bundle
.INSTALLED
:
196 case Bundle
.RESOLVED
:
198 case Bundle
.STARTING
:
199 String activationPolicy
= bundle
.getHeaders()
200 .get("Bundle-ActivationPolicy").toString();
201 // FIXME constant triggers the compilation failure
202 // .get(Constants.BUNDLE_ACTIVATIONPOLICY).toString();
203 if (activationPolicy
!= null && activationPolicy
.equals("lazy"))
204 // FIXME constant triggers the compilation failure
205 // && activationPolicy.equals(Constants.ACTIVATION_LAZY))
208 case Bundle
.STOPPING
: