//
// TableModel.java
//
// The contents of this file are subject to the SNIA Public License Version 1.0
// (the "License"); you may not use this file except in compliance with the
// License. You may obtain a copy of the License at
//
//	http://www.snia.org/resources/openSource.html
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is TableModel.java
// 
// The Initial Developer of the Original Code is David Simons.
//
// Contributor(s):
//
//
// This source uses the Solaris WBEM APIs version 2.2. 
// Synchronization will be maintained with the Solaris WBEM APIS,
// which are being standardized through the Java Community Process.
//
//
// $Id: TableModel.java,v 1.1 2003/07/17 18:32:55 kumpf Exp $
//
// $Log: TableModel.java,v $
// Revision 1.1  2003/07/17 18:32:55  kumpf
// HP-BAPU: PEP-64 CIM Client and CIM Listener Java Interface
//
// Revision 1.1.1.1  2001/10/31 18:15:11  karl
// import of SNIA 0_7
//
// Revision 1.5  2000/08/16 05:59:55  shawn
// merge P_TOMCAT31 branch
//
// Revision 1.4.8.1  2000/08/10 00:03:31  shawn
// head merge
//
// Revision 1.4  2000/05/11 10:11:56  davidsi
// - Fixed tabs.
//
// Revision 1.3  2000/05/06 17:13:51  davidsi
// - Brought in line with SUN WBEM APIs 2.2
//
// Revision 1.2  2000/02/13 15:09:40  davidsi
// - Added text to cover re-use of Solaris WBEM APIs.
//
// Revision 1.1.1.1  2000/02/06 16:41:03  davidsi
// Initial version.
//
//
//

package org.snia.wbemcmd.browser;


import java.util.Vector;
import javax.swing.table.*;




//
// Table handler
//
public class TableModel extends AbstractTableModel {
    private class VectorColumn {
	Vector names=new Vector();
	
	VectorColumn() {
	}
	    
	int getSize() {
	    return(names.size());
	}
	    
	Object getValueAt(int row) {
	    if (row>=names.size())
		return("");
	    return((Object)(names.elementAt(row)));
	}
	
	void setValueAt(Object obj,int row) {
	    while (row>=names.size())
		names.addElement("");
	    names.setElementAt(obj,row);
	}
	
	void  addValue(String val) {
	    names.addElement(val);
	}
	    
	void clearValues() {
	    names=new Vector();
	}
    }	 
    
    
    
    
    Vector data=new Vector();	    // Vector of columns
    String []names;
    boolean []columnEdit;
    
    
    
    TableModel(String[] inames) {
	names=(String [])inames.clone();
	    
			  
	columnEdit=new boolean[names.length];
	for(int i=0;i<names.length;i++)
	    columnEdit[i]=false;
      
    }
	
    public boolean isCellEditable(int row, int col) {
	return columnEdit[col];
    }

    public void setColumnEditable(int col,boolean flag) {
	columnEdit[col]=flag;
    }
	
    public String getColumnName(int column) {
	return names[column];
    }
	
	
    public int getColumnCount() {
	if (names==null)
	    return(0);
	return names.length; }
	
    public TableModel() {
    }
	
    public int getRowCount() {
	int maxcount=0;
	    
	for(int i=0;i<data.size();i++){ 
	    int isize;
	    isize=((VectorColumn)data.elementAt(i)).getSize();
	    if (isize>maxcount)
		maxcount=isize;
	}
       return(maxcount);
  }

	
    public void addValue(int col,String val) {
	for(int i=data.size();i<=col;i++) {
	    data.addElement(new VectorColumn());
	}
	((VectorColumn)(data.elementAt(col))).addValue(val);
    }
	
    public Object getValueAt(int row,int col) {
	if (col>=data.size())
	    return("");
	return( ((VectorColumn)(data.elementAt(col))).getValueAt(row) );
    }
	
    public void setValueAt(Object value,int row,int col) {
	for(int i=data.size();i<=col;i++) {
	    data.addElement(new VectorColumn());
	}
	((VectorColumn)(data.elementAt(col))).setValueAt(value,row);
    }
    public void clearColumn(int col) {
	if (col<data.size())
	    data.setElementAt(new VectorColumn(),col);
	    
	data = new Vector();
    }
}    
