2 * Copyright (C) 2007-2012 Argeo GmbH
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
.cms
.e4
.monitoring
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 import javax
.annotation
.PostConstruct
;
23 import org
.argeo
.eclipse
.ui
.TreeParent
;
24 import org
.eclipse
.e4
.ui
.di
.Focus
;
25 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
26 import org
.eclipse
.jface
.viewers
.TreeViewer
;
27 import org
.eclipse
.jface
.viewers
.Viewer
;
28 import org
.eclipse
.swt
.SWT
;
29 import org
.eclipse
.swt
.widgets
.Composite
;
30 import org
.osgi
.framework
.Bundle
;
31 import org
.osgi
.framework
.BundleContext
;
32 import org
.osgi
.framework
.FrameworkUtil
;
34 /** The OSGi runtime from a module perspective. */
35 public class ModulesView
{
36 private final static BundleContext bc
= FrameworkUtil
.getBundle(ModulesView
.class).getBundleContext();
37 private TreeViewer viewer
;
40 public void createPartControl(Composite parent
) {
41 viewer
= new TreeViewer(parent
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
42 viewer
.setContentProvider(new ModulesContentProvider());
43 viewer
.setLabelProvider(new ModulesLabelProvider());
48 public void setFocus() {
49 viewer
.getTree().setFocus();
52 private class ModulesContentProvider
implements ITreeContentProvider
{
53 private static final long serialVersionUID
= 3819934804640641721L;
55 public Object
[] getElements(Object inputElement
) {
56 return getChildren(inputElement
);
59 public Object
[] getChildren(Object parentElement
) {
60 if (parentElement
instanceof BundleContext
) {
61 BundleContext bundleContext
= (BundleContext
) parentElement
;
62 Bundle
[] bundles
= bundleContext
.getBundles();
64 List
<BundleNode
> modules
= new ArrayList
<BundleNode
>();
65 for (Bundle bundle
: bundles
) {
66 if (bundle
.getState() == Bundle
.ACTIVE
)
67 modules
.add(new BundleNode(bundle
, true));
69 return modules
.toArray();
70 } else if (parentElement
instanceof TreeParent
) {
71 return ((TreeParent
) parentElement
).getChildren();
77 public Object
getParent(Object element
) {
78 // TODO Auto-generated method stub
82 public boolean hasChildren(Object element
) {
83 if (element
instanceof TreeParent
) {
84 return ((TreeParent
) element
).hasChildren();
89 public void dispose() {
92 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
96 private class ModulesLabelProvider
extends StateLabelProvider
{
97 private static final long serialVersionUID
= 5290046145534824722L;
100 public String
getText(Object element
) {
101 if (element
instanceof BundleNode
)
102 return element
.toString() + " [" + ((BundleNode
) element
).getBundle().getBundleId() + "]";
103 return element
.toString();