Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

AttributeModel.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk.
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.console.gui.model;
00026 
00027 import javax.management.MBeanAttributeInfo;
00028 import javax.management.ObjectName;
00029 import javax.swing.table.AbstractTableModel;
00030 
00031 import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
00032 import org.objectweb.cjdbc.console.jmx.RmiJmxClient;
00033 
00034 public class AttributeModel extends AbstractTableModel
00035 {
00036   private MBeanAttributeInfo[] info;
00037   private RmiJmxClient         client;
00038   private ObjectName           mbean;
00039 
00040   /**
00041    * @see javax.swing.table.TableModel#getColumnCount()
00042    */
00043   public int getColumnCount()
00044   {
00045     return 3;
00046   }
00047 
00048   /**
00049    * @see javax.swing.table.TableModel#getRowCount()
00050    */
00051   public int getRowCount()
00052   {
00053     return info.length;
00054   }
00055 
00056   /**
00057    * Returns the info value.
00058    * 
00059    * @return Returns the info.
00060    */
00061   public MBeanAttributeInfo[] getInfo()
00062   {
00063     return info;
00064   }
00065 
00066   /**
00067    * @see javax.swing.table.TableModel#getValueAt(int, int)
00068    */
00069   public Object getValueAt(int rowIndex, int columnIndex)
00070   {
00071     if ((rowIndex >= 0 && rowIndex < info.length) == false)
00072       return null;
00073     switch (columnIndex)
00074     {
00075       case 0 :
00076         return info[rowIndex].getName();
00077       case 1 :
00078         return GuiConstants.getParameterType(info[rowIndex].getType());
00079       case 2 :
00080         try
00081         {
00082           return client.getAttributeValue(mbean, info[rowIndex].getName());
00083         }
00084         catch (Exception e)
00085         {
00086           return "-----";
00087         }
00088       default :
00089         return null;
00090     }
00091   }
00092 
00093   /**
00094    * @see javax.swing.table.TableModel#isCellEditable(int, int)
00095    */
00096   public boolean isCellEditable(int rowIndex, int columnIndex)
00097   {
00098     if ((rowIndex >= 0 && rowIndex < info.length) == false)
00099       return false;
00100     if (rowIndex != 2)
00101       return false;
00102     else
00103       return info[rowIndex].isWritable();
00104   }
00105 
00106   public AttributeModel(MBeanAttributeInfo[] info, RmiJmxClient client,
00107       ObjectName mbean)
00108   {
00109     this.info = info;
00110     this.client = client;
00111     this.mbean = mbean;
00112   }
00113 
00114   /**
00115    * @see javax.swing.table.TableModel#getColumnName(int)
00116    */
00117   public String getColumnName(int column)
00118   {
00119     switch (column)
00120     {
00121       case 0 :
00122         return "Name";
00123       case 1 :
00124         return "Type";
00125       case 2 :
00126         return "Value";
00127       default :
00128         return null;
00129     }
00130   }
00131 }

Generated on Mon Apr 11 22:01:29 2005 for C-JDBC by  doxygen 1.3.9.1