001    /*
002     * Copyright (c) 2005 Jens Schou, Staffan Gustafsson, Björn Lanneskog, 
003     * Einar Pehrson and Sebastian Kekkonen
004     *
005     * This file is part of
006     * CleanSheets Extension for Test Cases
007     *
008     * CleanSheets Extension for Test Cases is free software; you can
009     * redistribute it and/or modify it under the terms of the GNU General Public
010     * License as published by the Free Software Foundation; either version 2 of
011     * the License, or (at your option) any later version.
012     *
013     * CleanSheets Extension for Test Cases is distributed in the hope that
014     * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
015     * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016     * See the GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with CleanSheets Extension for Test Cases; if not, write to the
020     * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
021     * Boston, MA  02111-1307  USA
022     */
023    package csheets.ext.test.ui;
024    
025    import javax.swing.DefaultCellEditor;
026    import javax.swing.JComboBox;
027    import javax.swing.table.TableModel;
028    
029    import csheets.core.Value;
030    import csheets.ext.test.TestCase;
031    
032    /**
033     * The table used to display test cases, and to provide editing of validation
034     * states.
035     * @author Einar Pehrson
036     */
037    @SuppressWarnings("serial")
038    public class TestCaseTable extends TestTable {
039    
040            /**
041             * Creates a new test case table.
042             * @param tableModel the table model
043             */
044            public TestCaseTable(TableModel tableModel) {
045                    super(tableModel);
046    
047                    // Configures value renderer
048                    setDefaultRenderer(Value.class, new TestCaseResultRenderer());
049    
050                    // Configures validation state editor and renderer
051                    setDefaultRenderer(TestCase.ValidationState.class, new ValidationStateRenderer());
052                    setDefaultEditor(TestCase.ValidationState.class, new DefaultCellEditor(
053                            new JComboBox(TestCase.ValidationState.values())));
054            }
055    
056            /**
057             * Overridden to only allow editing of validation states.
058             * @param row the row whose value is to be queried
059             * @param column the column whose value is to be queried                 
060             * @return true if the cell at the given row and column is editable
061             */
062            public boolean isCellEditable(int row, int column) {
063                    return getColumnClass(column) == TestCase.ValidationState.class;
064            }
065    
066    
067            /**
068             * Returns the class of the column in the table.
069             * @param column the column whose class is to be queried
070             * @return class the class to be returned
071             */
072            public Class<?> getColumnClass(int column) {
073                    switch (column) {
074                    //      case 0: return TestCase.class;
075                            case 1: return Value.class;
076                            case 2: return TestCase.ValidationState.class;
077                            default: return Object.class;
078                    }
079            }
080    }