001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1999-2004 Gerald Brose
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: *
020: */
021: package org.jacorb.imr.util;
022:
023: import javax.swing.table.*;
024: import org.jacorb.imr.*;
025: import javax.swing.event.*;
026:
027: /**
028: * This class is the model for the server table.
029: * On user changes, it writes back its edited cells
030: * via the IMRModel class.
031: *
032: * @author Nicolas Noffke
033: *
034: * $Id: ImRServerTableModel.java,v 1.9 2006/06/16 12:36:28 alphonse.bendt Exp $
035: */
036:
037: public class ImRServerTableModel extends AbstractTableModel {
038: private ImRModel m_model;
039: private static final String[] m_columns = new String[] { "Name",
040: "Host", "Command", "active", "holding" };
041:
042: private ServerInfo[] m_servers;
043:
044: /**
045: * The constructor.
046: *
047: * @param model the ImRModel to write changes via.
048: */
049: public ImRServerTableModel(ImRModel model) {
050: m_model = model;
051: }
052:
053: /**
054: * Pass in the servers the table should display.
055: * Notify the JTable of that.
056: *
057: * @param servers an array containing the ServerInfo structs of the
058: * servers to display.
059: */
060: public void setServers(ServerInfo[] servers) {
061: m_servers = servers;
062: fireTableChanged(new TableModelEvent(this ));
063: }
064:
065: /**
066: * Notify the JTable that a server has been updated.
067: *
068: * @param index the servers index in the table.
069: */
070: public void serverRefreshed(int index) {
071: fireTableRowsUpdated(index, index);
072: }
073:
074: /**
075: * Get the number of rows of this table.
076: *
077: * @return the number of rows.
078: */
079: public int getRowCount() {
080: return m_servers.length;
081: }
082:
083: /**
084: * Get the number of columns of this table.
085: *
086: * @return the number of columns.
087: */
088: public int getColumnCount() {
089: return m_columns.length;
090: }
091:
092: /**
093: * Get the name of a specific column.
094: *
095: * @param column the columns index.
096: * @return String the columns name.
097: */
098: public String getColumnName(int column) {
099: return m_columns[column];
100: }
101:
102: /**
103: * Get the class of a specific column.
104: *
105: * @param index the columns index.
106: * @return the columns Class object.
107: */
108: public Class getColumnClass(int index) {
109: if (index == 0 || index == 1 || index == 2)
110: return String.class;
111:
112: else if (index == 3 || index == 4)
113: return Boolean.class;
114:
115: else
116: return Object.class;
117: }
118:
119: /**
120: * Get the value of a specific cell.
121: *
122: * @param row the cells row.
123: * @param column the cells column.
124: * @return the cells value.
125: */
126: public Object getValueAt(int row, int column) {
127: if (column == 0)
128: return m_servers[row].name;
129:
130: else if (column == 1)
131: return m_servers[row].host;
132:
133: else if (column == 2)
134: return m_servers[row].command;
135:
136: else if (column == 3)
137: return Boolean.valueOf(m_servers[row].active);
138:
139: else if (column == 4)
140: return Boolean.valueOf(m_servers[row].holding);
141:
142: return new Object();
143: }
144:
145: /**
146: * Test, wheter a cell is editable.
147: *
148: * @param row the cells row.
149: * @param column the cells column.
150: *
151: * @return true, if the cell is editable.
152: */
153: public boolean isCellEditable(int row, int column) {
154: if (column >= 1) {
155: return true;
156: }
157: return false;
158: }
159:
160: /**
161: * Set the value of a specific cell, i.e. the user has edited a cell.
162: *
163: * @param value the new value.
164: * @param row the cells row.
165: * @param column the cells column.
166: */
167: public void setValueAt(Object value, int row, int column) {
168: m_model.updateServer(row, m_columns[column], value);
169: }
170: } // ImRServerTableModel
|