001 /* JAPI - (Yet another (hopefully) useful) Java API
002 *
003 * Copyright (C) 2004-2006 Christian Hujer
004 *
005 * This program is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU General Public License as
007 * published by the Free Software Foundation; either version 2 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful, but
011 * WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013 * General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License
016 * along with this program; if not, write to the Free Software
017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
018 * 02111-1307, USA.
019 */
020
021 package net.sf.japi.swing.treetable;
022
023 import javax.swing.table.TableModel;
024 import javax.swing.tree.TreeModel;
025
026 /** The <code>TreeTableModel</code> interface specifies the methods the JTreeTable will use to interrogate a tabular tree data model.
027 * <p />
028 * The <code>JTreeTable</code> can be set up to display any data model which implements the <code>TreeTableModel</code> interface with a couple of lines of code:
029 * <pre>
030 * TreeTableModel myData = new MyTreeTableModel();
031 * JTreeTable treeTable = new JTreeTable(myData);
032 * </pre>
033 * @author <a href="mailto:chris@riedquat.de">Christian Hujer</a>
034 */
035 public interface TreeTableModel<R, T> {
036
037 /** Returns a child with a certain index.
038 * @param parent Node to return child for
039 * @param index Index of child
040 * @return child node with index from parent or <code>null</code> if no child was found
041 * @see TreeModel#getChild(Object, int)
042 */
043 T getChild(T parent, int index);
044
045 /** Returns the number of available children.
046 * @return number of available children
047 * @see TreeModel#getChildCount(Object)
048 */
049 int getChildCount(T node);
050
051 /** Returns the type for column number <code>column</code>.
052 * @param column Column to get type for
053 * @return type of <var>column</var>
054 * @see TableModel#getColumnClass(int)
055 */
056 Class<?> getColumnClass(int column);
057
058 /** Returns the number of availible columns.
059 * @return number of available columns
060 * @see TableModel#getColumnCount()
061 */
062 int getColumnCount();
063
064 /** Returns the name for column number <code>column</code>.
065 * @param column Column to get name for
066 * @return name of <var>column</var>
067 * @see TableModel#getColumnName(int)
068 */
069 String getColumnName(int column);
070
071 /** Returns the root of the treetable.
072 * @return root of the treetable
073 */
074 R getRoot();
075
076 /** Returns the value to be displayed for node <code>node</code> at column number <code>column</code>.
077 * @param node Node to get value of
078 * @param column Column to get value of
079 * @return object
080 * @see TableModel#getValueAt(int, int)
081 */
082 Object getValueAt(T node, int column);
083
084 /** Indicates whether the the value for node <code>node</code> at column number <code>column</code> is editable.
085 * @param node Node to check
086 * @param column Column to check
087 * @return <code>true</code> if the cell is editable, otherwise <code>false</code>
088 * @see TableModel#isCellEditable(int, int)
089 */
090 boolean isCellEditable(T node, int column);
091
092 /** Returns <code<true</code> if node is a leaf.
093 * @param node Node
094 * @return <code>true</code> if node is a leaf, otherwise <code>false</code>
095 */
096 boolean isLeaf(T node);
097
098 /** Sets the value for node <code>node</code> at column number <code>column</code>.
099 * @param value Value to be set
100 * @param node Node to set value at
101 * @param column Column of value in the node
102 * @see TableModel#setValueAt(Object, int, int)
103 */
104 void setValueAt(Object value, T node, int column);
105
106 } // interface TreeTableModel