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
;
37 import org
.osgi
.framework
.Constants
;
40 * Overview of the bundles as a table. Equivalent to Equinox 'ss' console
44 // public class BundlesView {}
46 public class BundlesView
extends ViewPart
{
47 private TableViewer viewer
;
50 public void createPartControl(Composite parent
) {
51 viewer
= new TableViewer(parent
);
52 viewer
.setContentProvider(new BundleContentProvider());
53 viewer
.getTable().setHeaderVisible(true);
55 EclipseUiSpecificUtils
.enableToolTipSupport(viewer
);
58 TableViewerColumn column
= new TableViewerColumn(viewer
, SWT
.NONE
);
59 column
.getColumn().setWidth(30);
60 column
.getColumn().setText("ID");
61 column
.getColumn().setAlignment(SWT
.RIGHT
);
62 column
.setLabelProvider(new ColumnLabelProvider() {
63 private static final long serialVersionUID
= -3122136344359358605L;
65 public String
getText(Object element
) {
66 return Long
.toString(((Bundle
) element
).getBundleId());
69 new ColumnViewerComparator
<Bundle
>(column
, new Comparator
<Bundle
>() {
70 public int compare(Bundle o1
, Bundle o2
) {
71 return (int) (o1
.getBundleId() - o2
.getBundleId());
76 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
77 column
.getColumn().setWidth(18);
78 column
.getColumn().setText("State");
79 column
.setLabelProvider(new StateLabelProvider());
80 new ColumnViewerComparator
<Bundle
>(column
, new Comparator
<Bundle
>() {
81 public int compare(Bundle o1
, Bundle o2
) {
82 return o1
.getState() - o2
.getState();
87 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
88 column
.getColumn().setWidth(300);
89 column
.getColumn().setText("Symbolic Name");
90 column
.setLabelProvider(new ColumnLabelProvider() {
91 private static final long serialVersionUID
= -4280840684440451080L;
93 public String
getText(Object element
) {
94 return ((Bundle
) element
).getSymbolicName();
97 new ColumnViewerComparator
<Bundle
>(column
, new Comparator
<Bundle
>() {
98 public int compare(Bundle o1
, Bundle o2
) {
99 return o1
.getSymbolicName().compareTo(o2
.getSymbolicName());
104 column
= new TableViewerColumn(viewer
, SWT
.NONE
);
105 column
.getColumn().setWidth(150);
106 column
.getColumn().setText("Version");
107 column
.setLabelProvider(new ColumnLabelProvider() {
108 private static final long serialVersionUID
= 6871926308708629989L;
110 public String
getText(Object element
) {
111 Bundle bundle
= (org
.osgi
.framework
.Bundle
) element
;
112 return bundle
.getVersion().toString();
115 new ColumnViewerComparator
<Bundle
>(column
, new Comparator
<Bundle
>() {
116 public int compare(Bundle o1
, Bundle o2
) {
117 return o1
.getVersion().compareTo(o2
.getVersion());
121 viewer
.setInput(WorkbenchUiPlugin
.getDefault().getBundle()
122 .getBundleContext());
127 public void setFocus() {
129 viewer
.getControl().setFocus();
132 /** Content provider managing the array of bundles */
133 private static class BundleContentProvider
implements
134 IStructuredContentProvider
{
135 private static final long serialVersionUID
= -8533792785725875977L;
137 public Object
[] getElements(Object inputElement
) {
138 if (inputElement
instanceof BundleContext
) {
139 BundleContext bc
= (BundleContext
) inputElement
;
140 return bc
.getBundles();
145 public void dispose() {
148 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
153 /** Label provider for the state column */
154 private static class StateLabelProvider
extends ColumnLabelProvider
{
155 private static final long serialVersionUID
= -7885583135316000733L;
158 public Image
getImage(Object element
) {
159 Integer state
= ((Bundle
) element
).getState();
161 case Bundle
.UNINSTALLED
:
162 return OsgiExplorerImages
.INSTALLED
;
163 case Bundle
.INSTALLED
:
164 return OsgiExplorerImages
.INSTALLED
;
165 case Bundle
.RESOLVED
:
166 return OsgiExplorerImages
.RESOLVED
;
167 case Bundle
.STARTING
:
168 return OsgiExplorerImages
.STARTING
;
169 case Bundle
.STOPPING
:
170 return OsgiExplorerImages
.STARTING
;
172 return OsgiExplorerImages
.ACTIVE
;
179 public String
getText(Object element
) {
184 public String
getToolTipText(Object element
) {
185 Bundle bundle
= (Bundle
) element
;
186 Integer state
= bundle
.getState();
188 case Bundle
.UNINSTALLED
:
189 return "UNINSTALLED";
190 case Bundle
.INSTALLED
:
192 case Bundle
.RESOLVED
:
194 case Bundle
.STARTING
:
195 String activationPolicy
= bundle
.getHeaders()
196 .get(Constants
.BUNDLE_ACTIVATIONPOLICY
).toString();
198 // .get("Bundle-ActivationPolicy").toString();
199 // FIXME constant triggers the compilation failure
200 if (activationPolicy
!= null
201 && activationPolicy
.equals(Constants
.ACTIVATION_LAZY
))
202 // && activationPolicy.equals("lazy"))
203 // FIXME constant triggers the compilation failure
204 // && activationPolicy.equals(Constants.ACTIVATION_LAZY))
207 case Bundle
.STOPPING
: