KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > imr > util > ImRServerTableModel


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.imr.util;
22
23 import javax.swing.table.*;
24 import org.jacorb.imr.*;
25 import javax.swing.event.*;
26 /**
27  * This class is the model for the server table.
28  * On user changes, it writes back its edited cells
29  * via the IMRModel class.
30  *
31  * @author Nicolas Noffke
32  *
33  * $Id: ImRServerTableModel.java,v 1.7 2004/05/06 12:39:59 nicolas Exp $
34  */

35
36 public class ImRServerTableModel extends AbstractTableModel {
37     private ImRModel m_model;
38     private static final String JavaDoc[] m_columns = new String JavaDoc[] {"Name", "Host", "Command", "active", "holding"};
39
40     private ServerInfo[] m_servers;
41
42     /**
43      * The constructor.
44      *
45      * @param model the ImRModel to write changes via.
46      */

47     public ImRServerTableModel(ImRModel model){
48     m_model = model;
49     }
50
51     /**
52      * Pass in the servers the table should display.
53      * Notify the JTable of that.
54      *
55      * @param servers an array containing the ServerInfo structs of the
56      * servers to display.
57      */

58     public void setServers(ServerInfo[] servers){
59     m_servers = servers;
60     fireTableChanged(new TableModelEvent(this));
61     }
62
63     /**
64      * Notify the JTable that a server has been updated.
65      *
66      * @param index the servers index in the table.
67      */

68     public void serverRefreshed(int index){
69     fireTableRowsUpdated(index, index);
70     }
71
72     /**
73      * Get the number of rows of this table.
74      *
75      * @return the number of rows.
76      */

77     public int getRowCount(){
78     return m_servers.length;
79     }
80
81     /**
82      * Get the number of columns of this table.
83      *
84      * @return the number of columns.
85      */

86     public int getColumnCount(){
87     return m_columns.length;
88     }
89
90     /**
91      * Get the name of a specific column.
92      *
93      * @param index the columns index.
94      * @return String the columns name.
95      */

96     public String JavaDoc getColumnName(int column){
97     return m_columns[column];
98     }
99
100     /**
101      * Get the class of a specific column.
102      *
103      * @param index the columns index.
104      * @return the columns Class object.
105      */

106     public Class JavaDoc getColumnClass(int index){
107     if (index == 0 || index == 1 || index == 2)
108         return String JavaDoc.class;
109
110     else if (index == 3 || index == 4)
111         return Boolean JavaDoc.class;
112
113     else
114         return Object JavaDoc.class;
115     }
116
117     /**
118      * Get the value of a specific cell.
119      *
120      * @param row the cells row.
121      * @param column the cells column.
122      * @return the cells value.
123      */

124     public Object JavaDoc getValueAt(int row, int column){
125     if (column == 0)
126         return m_servers[row].name;
127
128     else if (column == 1)
129         return m_servers[row].host;
130
131     else if (column == 2)
132         return m_servers[row].command;
133
134     else if (column == 3)
135         return new Boolean JavaDoc(m_servers[row].active);
136     
137     else if (column == 4)
138         return new Boolean JavaDoc(m_servers[row].holding);
139     
140     return new Object JavaDoc();
141     }
142
143     /**
144      * Test, wheter a cell is editable.
145      *
146      * @param row the cells row.
147      * @param column the cells column.
148      *
149      * @return true, if the cell is editable.
150      */

151     public boolean isCellEditable(int row, int column){
152     if (column >= 1)
153         return true;
154     else
155         return false;
156     }
157
158     /**
159      * Set the value of a specific cell, i.e. the user has edited a cell.
160      *
161      * @param value the new value.
162      * @param row the cells row.
163      * @param column the cells column.
164      */

165     public void setValueAt(Object JavaDoc value, int row, int column){
166     m_model.updateServer(row, m_columns[column], value);
167     }
168 } // ImRServerTableModel
169

170
171
172
173
174
175
176
177
178
179
180
181
182
183
Popular Tags