Xoetrope
HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
package net.xoetrope.test.table;

import java.awt.Component;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
import net.xoetrope.optional.data.XModelHelper;

import net.xoetrope.xui.XProjectManager;
import net.xoetrope.xui.data.XBaseModel;
import net.xoetrope.xui.data.XModel;


public class XModelTableModel implements TableModel
{

protected XModel model, rootMdl;

protected Component component;

protected String headerValues[];

public XModelTableModel( XModel newModel )
{
rootMdl = XProjectManager.getModel();
model = newModel;
}

public void setHeaders( String headers[] )
{
headerValues = headers;
}

public XModel getModel()
{
return model;
}


/
* Returns the number of rows in the model. A
* <code>JTable</code> uses this method to determine how many rows it
* should display. This method should be quick, as it
* is called frequently during rendering.
*
* @return the number of rows in the model
* @see #getColumnCount
*/
public int getRowCount()
{
return model.getNumChildren();
}

/

* Returns the number of columns in the model. A
* <code>JTable</code> uses this method to determine how many columns it
* should create and display by default.
*
* @return the number of columns in the model
* @see #getRowCount
*/
public int getColumnCount()
{
return headerValues.length;
}

/
* Returns the name of the column at <code>columnIndex</code>. This is used
* to initialize the table's column header name. Note: this name does
* not need to be unique; two columns in a table can have the same name.
*
* @param columnIndex the index of the column
* @return the name of the column
*/
public String getColumnName(int columnIndex)
{
System.out.println( "header: " headerValues[ columnIndex ] );
return headerValues[ columnIndex ];
}

/

* Returns the most specific superclass for all the cell values
* in the column. This is used by the <code>JTable</code> to set up a
* default renderer and editor for the column.
*
* @param columnIndex the index of the column
* @return the common ancestor class of the object values in the model.
*/
public Class getColumnClass(int columnIndex)
{
return String.class;
}

/
* Returns true if the cell at <code>rowIndex</code> and
* <code>columnIndex</code>
* is editable. Otherwise, <code>setValueAt</code> on the cell will not
* change the value of that cell.
*
* @param rowIndex the row whose value to be queried
* @param columnIndex the column whose value to be queried
* @return true if the cell is editable
* @see #setValueAt
*/
public boolean isCellEditable( int rowIndex, int columnIndex )
{
return true;
}

/

* Returns the value for the cell at <code>columnIndex</code> and
* <code>rowIndex</code>.
*
* @param rowIndex the row whose value is to be queried
* @param columnIndex the column whose value is to be queried
* @return the value Object at the specified cell
*/
public Object getValueAt( int rowIndex, int columnIndex )
{
return model.get( rowIndex ).get(columnIndex).get();
}

public Object getModelAt( int rowIndex, int columnIndex )
{
try {
return model.get( rowIndex ).get( columnIndex );
}
catch ( Exception e )
{
return null;
}
}

public Object getModelAt( int rowIndex )
{
return model.get( rowIndex );
}

/
* Sets the value in the cell at <code>columnIndex</code> and
* <code>rowIndex</code> to <code>aValue</code>.
*
* @param aValue the new value
* @param rowIndex the row whose value is to be changed
* @param columnIndex the column whose value is to be changed
* @see #getValueAt
* @see #isCellEditable
*/
public void setValueAt(Object aValue, int rowIndex, int columnIndex)
{
model.get( rowIndex ).get( columnIndex ).set( aValue );
}


public void setComponent( Component comp )
{
component = comp;
}

public Component getComponent()
{
return component;
}

/

* Adds a listener to the list that is notified each time a change
* to the data model occurs.
*
* @param l the TableModelListener
*/
public void addTableModelListener(TableModelListener l)
{

}

/
* Removes a listener from the list that is notified each time a
* change to the data model occurs.
*
* @param l the TableModelListener
*/
public void removeTableModelListener(TableModelListener l)
{

}
}

There are no comments on this page. [Add comment]

Page was generated in 0.1263 seconds