blob: 2e315f7c706c4f08821320f9efff73f279b4f0e3 [file] [log] [blame]
Stephane Frenot641ddbc2006-09-19 14:42:16 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
Stephane Frenot4eb2a3d2006-07-21 10:19:58 +000018 */
19package org.apache.felix.mosgi.managedelements.osgiprobes.tab;
20
21import java.awt.Component;
22import java.beans.PropertyChangeEvent;
23import java.util.ArrayList;
24import java.util.Vector;
25import javax.management.MBeanAttributeInfo;
26import javax.management.MBeanServerConnection;
27import javax.management.ObjectName;
28import javax.swing.JPanel;
29import javax.swing.JScrollPane;
30import javax.swing.JTable;
31import javax.swing.table.DefaultTableModel;
32import org.osgi.framework.BundleActivator;
33import org.osgi.framework.BundleContext;
34import org.osgi.framework.ServiceRegistration;
35import org.apache.felix.mosgi.console.ifc.Plugin;
36
37public class OsgiProbesTabUI extends JPanel implements Plugin, BundleActivator {
38
39 private String [] headers = {"Name", "Value"};
40 private JTable innerTable;
41
42 private BundleContext m_context = null;
43 private ServiceRegistration sreg = null;
44
45 public OsgiProbesTabUI(){
46 this.innerTable=new JTable();
47 this.innerTable.setPreferredScrollableViewportSize(new java.awt.Dimension(500,150));
48 JScrollPane table = new JScrollPane(this.innerTable);
49 this.add(table);
50 }
51
52
53 ///////////////////////////////////////////
54 // BundleActivator //
55 ///////////////////////////////////////////
56 public void start(BundleContext context) {
57 m_context = context;
58 this.registerServicePlugin();
59 }
60
61 public void stop(BundleContext context) {
62 }
63
64
65
66 ///////////////////////////////////////////
67 // Plugin //
68 //////////////////////////////////////////
69 public void registerServicePlugin(){
70 sreg = m_context.registerService(Plugin.class.getName(), this, null);
Stephane Frenot1ce47fd2006-10-02 13:51:53 +000071
Stephane Frenot4eb2a3d2006-07-21 10:19:58 +000072 }
73
74 public void unregisterServicePlugin(){
Stephane Frenot1ce47fd2006-10-02 13:51:53 +000075 if (sreg!=null){
76 sreg.unregister();
77 sreg=null;
78 }
Stephane Frenot4eb2a3d2006-07-21 10:19:58 +000079 }
80
81 public String pluginLocation(){
82 return m_context.getBundle().getLocation();
83 }
84
85 public String getName(){return "OSGi Platform";}
86
87 public Component getGUI(){return this;}
88
89 public void propertyChange(PropertyChangeEvent e){
90 /*
91 * This a static tab, each new visit will provide the same
92 * information. A dynamic tab update is provided in LinuxTab
93 *
94 */
95 if (e.getPropertyName().equals(Plugin.NEW_NODE_READY)){
96 this.getProperties((MBeanServerConnection)e.getNewValue());
97 }else if(e.getPropertyName().equals(Plugin.EMPTY_NODE)){
98 this.innerTable.setModel(new DefaultTableModel());
99 this.invalidate();
100 this.validate();
101 }
102 }
103
104 private void getProperties(MBeanServerConnection mbsc){
105 try{
106 ObjectName on=new ObjectName("TabUI:name=OsgiProbes");
107 MBeanAttributeInfo attrInfo[] = mbsc.getMBeanInfo(on).getAttributes();
108 Object content [][]=new String[attrInfo.length][2];
109 for (int k=0;k<attrInfo.length;k++) {
110 content [k][0]=attrInfo[k].getName();
111 content [k][1]=mbsc.getAttribute(on, attrInfo[k].getName());
112 }
113 DefaultTableModel dtm=new DefaultTableModel(content, this.headers);
114 this.innerTable.setModel(dtm);
115 this.invalidate();
116 this.validate();
117 }catch (Exception e){
118 e.printStackTrace();
119 }
120 }
121}