KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > panoptes > view > swing > configurator > AttributeTableModel


1 /*
2  * Created on Feb 14, 2004
3  *
4  */

5 package net.sf.panoptes.view.swing.configurator;
6
7 import javax.management.MBeanAttributeInfo JavaDoc;
8 import javax.swing.table.AbstractTableModel JavaDoc;
9
10 import net.sf.panoptes.component.jmx.model.MBeanWrapper;
11
12 /**
13  *
14  *
15  * @author Dag Liodden
16  * @version 0.1
17  */

18 public class AttributeTableModel extends AbstractTableModel JavaDoc {
19     
20     private MBeanWrapper mbean;
21
22     public AttributeTableModel(MBeanWrapper wrapper) {
23         this.mbean = wrapper;
24     }
25     
26     public void setMBean(MBeanWrapper mbean) {
27         this.mbean = mbean;
28     }
29     
30     public int getColumnCount() {
31         return 3;
32     }
33
34     public int getRowCount() {
35         if (mbean == null)
36             return 0;
37         else
38             return mbean.getAttributes().length;
39     }
40
41     public String JavaDoc getColumnName(int columnIndex) {
42         switch (columnIndex) {
43         case 0 :
44             return "Name";
45         case 1 :
46             return "Value";
47         case 2 :
48             return "Type";
49         default :
50             return "Uknown column";
51         }
52
53     }
54
55     public Object JavaDoc getValueAt(int rowIndex, int columnIndex) {
56         MBeanAttributeInfo JavaDoc i = mbean.getAttributes()[rowIndex];
57         switch (columnIndex) {
58         case 0 :
59             return i.getName();
60         case 1 :
61             Object JavaDoc val = mbean.getAttributeValue(i.getName());
62             return val == null ? "null" : val.toString();
63         case 2 :
64             return i.getType();
65         default :
66             return "Unknown column";
67         }
68     }
69
70 }
71
Popular Tags