]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/osgi/BundlesView.java
remove empty packages
[lgpl/argeo-commons.git] / org.argeo.cms.ui.workbench / src / org / argeo / cms / ui / workbench / osgi / BundlesView.java
1 //package org.argeo.eclipse.ui.workbench.osgi;
2 //public class BundlesView {}
3
4 /*
5 * Copyright (C) 2007-2012 Argeo GmbH
6 *
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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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.
18 */
19 package org.argeo.cms.ui.workbench.osgi;
20
21 import java.util.Comparator;
22
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;
36
37 /**
38 * Overview of the bundles as a table. Equivalent to Equinox 'ss' console
39 * command.
40 */
41 public class BundlesView extends ViewPart {
42 private TableViewer viewer;
43
44 @Override
45 public void createPartControl(Composite parent) {
46 viewer = new TableViewer(parent);
47 viewer.setContentProvider(new BundleContentProvider());
48 viewer.getTable().setHeaderVisible(true);
49
50 EclipseUiSpecificUtils.enableToolTipSupport(viewer);
51
52 // ID
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;
59
60 public String getText(Object element) {
61 return Long.toString(((Bundle) element).getBundleId());
62 }
63 });
64 new ColumnViewerComparator<Bundle>(column, new Comparator<Bundle>() {
65 public int compare(Bundle o1, Bundle o2) {
66 return (int) (o1.getBundleId() - o2.getBundleId());
67 }
68 });
69
70 // State
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();
78 }
79 });
80
81 // Symbolic name
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;
87
88 public String getText(Object element) {
89 return ((Bundle) element).getSymbolicName();
90 }
91 });
92 new ColumnViewerComparator<Bundle>(column, new Comparator<Bundle>() {
93 public int compare(Bundle o1, Bundle o2) {
94 return o1.getSymbolicName().compareTo(o2.getSymbolicName());
95 }
96 });
97
98 // Version
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;
104
105 public String getText(Object element) {
106 Bundle bundle = (org.osgi.framework.Bundle) element;
107 return bundle.getVersion().toString();
108 }
109 });
110 new ColumnViewerComparator<Bundle>(column, new Comparator<Bundle>() {
111 public int compare(Bundle o1, Bundle o2) {
112 return o1.getVersion().compareTo(o2.getVersion());
113 }
114 });
115
116 viewer.setInput(WorkbenchUiPlugin.getDefault().getBundle()
117 .getBundleContext());
118
119 }
120
121 @Override
122 public void setFocus() {
123 if (viewer != null)
124 viewer.getControl().setFocus();
125 }
126
127 /** Content provider managing the array of bundles */
128 private static class BundleContentProvider implements
129 IStructuredContentProvider {
130 private static final long serialVersionUID = -8533792785725875977L;
131
132 public Object[] getElements(Object inputElement) {
133 if (inputElement instanceof BundleContext) {
134 BundleContext bc = (BundleContext) inputElement;
135 return bc.getBundles();
136 }
137 return null;
138 }
139
140 public void dispose() {
141 }
142
143 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
144 }
145 }
146 }