2 * Copyright (C) 2007-2012 Mathieu Baudier
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.osgi
.ui
.explorer
.views
;
18 import java
.util
.Comparator
;
20 import org
.argeo
.eclipse
.ui
.ColumnViewerComparator
;
21 import org
.argeo
.eclipse
.ui
.specific
.EclipseUiSpecificUtils
;
22 import org
.argeo
.osgi
.ui
.explorer
.OsgiExplorerImages
;
23 import org
.argeo
.osgi
.ui
.explorer
.OsgiExplorerPlugin
;
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
.graphics
.Image
;
31 import org
.eclipse
.swt
.widgets
.Composite
;
32 import org
.eclipse
.ui
.part
.ViewPart
;
33 import org
.osgi
.framework
.Bundle
;
34 import org
.osgi
.framework
.BundleContext
;
35 import org
.osgi
.framework
.Constants
;
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 public String
getText(Object element
) {
59 return Long
.toString(((Bundle
) element
).getBundleId());
62 new ColumnViewerComparator
<Bundle
>(column
, new Comparator
<Bundle
>() {
63 public int compare(Bundle o1
, Bundle o2
) {
64 return (int) (o1
.getBundleId() - o2
.getBundleId());
69 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
70 column
.getColumn().setWidth(18);
71 column
.getColumn().setText("State");
72 column
.setLabelProvider(new StateLabelProvider());
73 new ColumnViewerComparator
<Bundle
>(column
, new Comparator
<Bundle
>() {
74 public int compare(Bundle o1
, Bundle o2
) {
75 return o1
.getState() - o2
.getState();
80 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
81 column
.getColumn().setWidth(300);
82 column
.getColumn().setText("Symbolic Name");
83 column
.setLabelProvider(new ColumnLabelProvider() {
84 public String
getText(Object element
) {
85 return ((Bundle
) element
).getSymbolicName();
88 new ColumnViewerComparator
<Bundle
>(column
, new Comparator
<Bundle
>() {
89 public int compare(Bundle o1
, Bundle o2
) {
90 return o1
.getSymbolicName().compareTo(o2
.getSymbolicName());
95 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
96 column
.getColumn().setWidth(150);
97 column
.getColumn().setText("Version");
98 column
.setLabelProvider(new ColumnLabelProvider() {
99 public String
getText(Object element
) {
100 return ((Bundle
) element
).getVersion().toString();
103 new ColumnViewerComparator
<Bundle
>(column
, new Comparator
<Bundle
>() {
104 public int compare(Bundle o1
, Bundle o2
) {
105 return o1
.getVersion().compareTo(o2
.getVersion());
109 viewer
.setInput(OsgiExplorerPlugin
.getDefault().getBundle()
110 .getBundleContext());
115 public void setFocus() {
117 viewer
.getControl().setFocus();
120 /** Content provider managing the array of bundles */
121 private static class BundleContentProvider
implements
122 IStructuredContentProvider
{
123 public Object
[] getElements(Object inputElement
) {
124 if (inputElement
instanceof BundleContext
) {
125 BundleContext bc
= (BundleContext
) inputElement
;
126 return bc
.getBundles();
131 public void dispose() {
134 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
139 /** Label provider for the state column */
140 private static class StateLabelProvider
extends ColumnLabelProvider
{
142 public Image
getImage(Object element
) {
143 Integer state
= ((Bundle
) element
).getState();
145 case Bundle
.UNINSTALLED
:
146 return OsgiExplorerImages
.INSTALLED
;
147 case Bundle
.INSTALLED
:
148 return OsgiExplorerImages
.INSTALLED
;
149 case Bundle
.RESOLVED
:
150 return OsgiExplorerImages
.RESOLVED
;
151 case Bundle
.STARTING
:
152 return OsgiExplorerImages
.STARTING
;
153 case Bundle
.STOPPING
:
154 return OsgiExplorerImages
.STARTING
;
156 return OsgiExplorerImages
.ACTIVE
;
163 public String
getText(Object element
) {
168 public String
getToolTipText(Object element
) {
169 Bundle bundle
= (Bundle
) element
;
170 Integer state
= bundle
.getState();
172 case Bundle
.UNINSTALLED
:
173 return "UNINSTALLED";
174 case Bundle
.INSTALLED
:
176 case Bundle
.RESOLVED
:
178 case Bundle
.STARTING
:
179 String activationPolicy
= bundle
.getHeaders()
180 .get(Constants
.BUNDLE_ACTIVATIONPOLICY
).toString();
181 if (activationPolicy
!= null
182 && activationPolicy
.equals(Constants
.ACTIVATION_LAZY
))
185 case Bundle
.STOPPING
: