001/*
002 * $Id: TreeTableModel.java 2476 2007-11-25 15:52:59Z kschaefe $
003 *
004 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005 * Santa Clara, California 95054, U.S.A. All rights reserved.
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 * 
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015 * Lesser General Public License for more details.
016 * 
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this library; if not, write to the Free Software
019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
020 */
021package org.jdesktop.swingx.treetable;
022
023
024import javax.swing.tree.TreeModel;
025
026/**
027 * The model used by {@code JXTreeTable}.
028 * <p>
029 * This model is a combination of {@link TreeModel} and
030 * {@link javax.swing.table.TableModel} for use with the tree table. It does not
031 * actually extends {@code TableModel}, but instead copies method signature as 
032 * appropriate and alters other to work with the underlying {@code TreeModel}.
033 * <p>
034 * 
035 * @see TreeModel
036 * @see javax.swing.table.TableModel
037 */
038public interface TreeTableModel extends TreeModel {
039    /**
040     * Returns the most specific superclass for all the cell values in the
041     * column. This is used by the {@code JXTreeTable} to set up a default
042     * renderer and editor for the column.
043     * 
044     * @param columnIndex
045     *            the index of the column
046     * @return the common ancestor class of the object values in the model.
047     * @see javax.swing.table.TableModel#getColumnClass(int)
048     */
049    public Class<?> getColumnClass(int columnIndex);
050
051    /**
052     * Returns the number of columns in the model. A {@code JXTreeTable} uses
053     * this method to determine how many columns it should create and display by
054     * default.
055     * 
056     * @return the number of columns in the model
057     * @see javax.swing.table.TableModel#getColumnCount()
058     */
059    public int getColumnCount();
060
061    /**
062     * Returns the name of the column at {@code columnIndex}. This is used to
063     * initialize the table's column header name. Note: this name does not need
064     * to be unique; two columns in a table can have the same name.
065     * 
066     * @param column
067     *            the index of the column
068     * @return the name of the column
069     * @see javax.swing.table.TableModel#getColumnName(int)
070     */
071    public String getColumnName(int column);
072
073    /**
074     * Returns the column that is the "tree" column. While it is not required,
075     * most implementations will default the first column to be the hierarchical
076     * one.
077     * 
078     * @return the index of the hierarchical column or -1 if no column is the
079     *         hierarchical column.
080     */
081    public int getHierarchicalColumn();
082    
083    /**
084     * Returns the value for the {@code node} at {@code columnIndex}. The
085     * {@code node} must be managed by this model. Unamanaged nodes should throw
086     * an {@code IllegalArgumentException}.
087     * 
088     * @param node
089     *            the node whose value is to be queried
090     * @param column
091     *            the column whose value is to be queried
092     * @return the value Object at the specified cell
093     * @throws IllegalArgumentException
094     *             if {@code node} is not managed by this model.
095     * @see #setValueAt
096     * @see javax.swing.table.TableModel#getValueAt(int, int)
097     */
098    public Object getValueAt(Object node, int column);
099
100    /**
101     * Returns true if the cell for the {@code node} at {@code columnIndex} is
102     * editable. Otherwise, {@code setValueAt} on the cell will not change the
103     * value of that cell. The {@code node} must be managed by this model.
104     * Unamanaged nodes should throw an {@code IllegalArgumentException}.
105     * 
106     * @param node
107     *            the node whose value to be queried
108     * @param column
109     *            the column whose value to be queried
110     * @return true if the cell is editable
111     * @throws IllegalArgumentException
112     *             if {@code node} is not managed by this model.
113     * @see #setValueAt
114     * @see javax.swing.table.TableModel#isCellEditable(int, int)
115     */
116    public boolean isCellEditable(Object node, int column);
117
118    /**
119     * Sets the value for the {@code node} at {@code columnIndex} to
120     * {@code value}. The {@code node} must be managed by this model.
121     * Unamanaged nodes should throw an {@code IllegalArgumentException}.
122     * 
123     * 
124     * @param value
125     *            the new value
126     * @param node
127     *            the node whose value is to be changed
128     * @param column
129     *            the column whose value is to be changed
130     * @throws IllegalArgumentException
131     *             if {@code node} is not managed by this model.
132     * @see #getValueAt
133     * @see #isCellEditable
134     * @see javax.swing.table.TableModel#setValueAt(Object, int, int)
135     */
136    public void setValueAt(Object value, Object node, int column);
137}