KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > gui > model > AttributeModel


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.console.gui.model;
26
27 import javax.management.MBeanAttributeInfo JavaDoc;
28 import javax.management.ObjectName JavaDoc;
29 import javax.swing.table.AbstractTableModel JavaDoc;
30
31 import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
32 import org.objectweb.cjdbc.console.jmx.RmiJmxClient;
33
34 /**
35  * This class defines a AttributeModel
36  *
37  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
38  * @version 1.0
39  */

40 public class AttributeModel extends AbstractTableModel JavaDoc
41 {
42   private MBeanAttributeInfo JavaDoc[] info;
43   private RmiJmxClient client;
44   private ObjectName JavaDoc mbean;
45
46   /**
47    *
48    * Creates a new <code>AttributeModel</code> object
49    *
50    * @param info MBean attribute info
51    * @param client JMX client
52    * @param mbean MBean object
53    */

54   public AttributeModel(MBeanAttributeInfo JavaDoc[] info, RmiJmxClient client,
55       ObjectName JavaDoc mbean)
56   {
57     this.info = info;
58     this.client = client;
59     this.mbean = mbean;
60   }
61
62
63   /**
64    * @see javax.swing.table.TableModel#getColumnCount()
65    */

66   public int getColumnCount()
67   {
68     return 3;
69   }
70
71   /**
72    * @see javax.swing.table.TableModel#getRowCount()
73    */

74   public int getRowCount()
75   {
76     return info.length;
77   }
78
79   /**
80    * Returns the info value.
81    *
82    * @return Returns the info.
83    */

84   public MBeanAttributeInfo JavaDoc[] getInfo()
85   {
86     return info;
87   }
88
89   /**
90    * @see javax.swing.table.TableModel#getValueAt(int, int)
91    */

92   public Object JavaDoc getValueAt(int rowIndex, int columnIndex)
93   {
94     if ((rowIndex >= 0 && rowIndex < info.length) == false)
95       return null;
96     switch (columnIndex)
97     {
98       case 0 :
99         return info[rowIndex].getName();
100       case 1 :
101         return GuiConstants.getParameterType(info[rowIndex].getType());
102       case 2 :
103         try
104         {
105           return client.getAttributeValue(mbean, info[rowIndex].getName());
106         }
107         catch (Exception JavaDoc e)
108         {
109           return "-----";
110         }
111       default :
112         return null;
113     }
114   }
115
116   /**
117    * @see javax.swing.table.TableModel#isCellEditable(int, int)
118    */

119   public boolean isCellEditable(int rowIndex, int columnIndex)
120   {
121     if ((rowIndex >= 0 && rowIndex < info.length) == false)
122       return false;
123     if (rowIndex != 2)
124       return false;
125     else
126       return info[rowIndex].isWritable();
127   }
128
129   /**
130    * @see javax.swing.table.TableModel#getColumnName(int)
131    */

132   public String JavaDoc getColumnName(int column)
133   {
134     switch (column)
135     {
136       case 0 :
137         return "Name";
138       case 1 :
139         return "Type";
140       case 2 :
141         return "Value";
142       default :
143         return null;
144     }
145   }
146 }
Popular Tags