View Javadoc
1 /*** 2 * LevelTableModel.java 3 * 4 * Project: Dependency Tool 5 * 6 * WHEN WHO WHAT 7 * 06.06.2003 pko initial public release 8 * 11.06.2002 ctr creation 9 * 10 * Copyright 2003 ELCA Informatique SA 11 * Av. de la Harpe 22-24, 1000 Lausanne 13, Switzerland 12 * www.elca.ch 13 * 14 * This library is free software; you can redistribute it and/or 15 * modify it under the terms of the GNU Lesser General Public License 16 * as published by the Free Software Foundation; either version 2.1 of 17 * the License, or (at your option) any later version. 18 * 19 * This library is distributed in the hope that it will be useful, but 20 * WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 * Lesser General Public License for more details. 23 * 24 * You should have received a copy of the GNU Lesser General Public 25 * License along with this library; if not, write to the Free Software 26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 27 * USA 28 */ 29 30 package ch.elca.dependency.gui; 31 32 import java.util.ArrayList; 33 import javax.swing.table.AbstractTableModel; 34 35 /*** 36 * This class is the data model for the level table in the 37 * <code>LevelDialog</code>. It is responsible for managing the table 38 * entries. 39 * 40 * @author Christoph Trutmann 41 * @version 1.0-beta 42 */ 43 public class LevelTableModel extends AbstractTableModel { 44 45 /*** 46 * Column names appearing in the table header. 47 */ 48 private static final String[] COLUMN_NAMES = {"Name", "Match packages"}; 49 50 /*** 51 * Determines the type of the column. 52 */ 53 private static final Class[] COLUMN_CLASSES = {String.class, String.class}; 54 55 /*** 56 * Determines which cells are editable. 57 */ 58 private static final boolean[] CELL_IS_EDITABLE = {false, false}; 59 60 /*** 61 * Collection with all the rows of the table stored in an object array. 62 */ 63 private ArrayList m_rows; 64 65 66 /*** 67 * Constructor 68 */ 69 public LevelTableModel(){ 70 m_rows = new ArrayList(); 71 } 72 73 74 /*** 75 * Returns the number of columns in this data table. 76 * 77 * @return the number of columns in the model 78 */ 79 public int getColumnCount(){ 80 return COLUMN_NAMES.length; 81 } 82 83 84 /*** 85 * Returns the number of rows in this data table. 86 * 87 * @return the number of rows in the model 88 */ 89 public int getRowCount(){ 90 return m_rows.size(); 91 } 92 93 94 /*** 95 * Returns an attribute value for the cell at <code>row</code> 96 * and <code>column</code>. 97 * 98 * @param row the row whose value is to be queried 99 * @param column the column whose value is to be queried 100 * @return the value Object at the specified cell 101 * @exception ArrayIndexOutOfBoundsException if an invalid row or 102 * column was given 103 */ 104 public Object getValueAt(int row, int col){ 105 Object[] filter = (Object[])m_rows.get(row); 106 return filter[col]; 107 } 108 109 110 /*** 111 * Returns the column name. 112 * 113 * @return A name for this column using the string value of the 114 * appropriate member. 115 * If the value is <code>null</code> or does not have an entry for 116 * this index, returns the default name provided by the superclass. 117 */ 118 public String getColumnName(int col) { 119 120 if ( COLUMN_NAMES.length <= col ) { 121 return super.getColumnName(col); 122 } 123 124 if ( COLUMN_NAMES[col] == null || COLUMN_NAMES[col].equals("") ) { 125 if ( col == 0 ){ 126 return ""; // because here has to be no label 127 } 128 else { 129 return super.getColumnName(col); 130 } 131 } 132 else { 133 return COLUMN_NAMES[col]; 134 } 135 } 136 137 138 /*** 139 * Returns the most specific superclass for all the cell values 140 * in the column. This is used by the <code>JTable</code> to set up a 141 * default renderer and editor for the column. 142 * 143 * @param columnIndex the index of the column 144 * @return the common ancestor class of the object values in the model. 145 */ 146 public Class getColumnClass(int columnIndex){ 147 return COLUMN_CLASSES[columnIndex]; 148 } 149 150 151 /*** 152 * Sets the value in the cell at <code>columnIndex</code> and 153 * <code>rowIndex</code> to <code>aValue</code>. 154 * 155 * @param aValue the new value 156 * @param rowIndex the row whose value is to be changed 157 * @param columnIndex the column whose value is to be changed 158 * @see #getValueAt 159 * @see #isCellEditable 160 */ 161 public void setValueAt(Object aValue, int rowIndex, int columnIndex){ 162 Object[] level = (Object[])m_rows.get(rowIndex); 163 level[columnIndex] = aValue; 164 m_rows.set(rowIndex, level); 165 fireTableRowsUpdated(rowIndex, rowIndex); 166 } 167 168 169 /*** 170 * Adds the Level to the table. 171 * The new entry is not marked as selected. 172 * 173 * @param name Name of the added filter. 174 * @param value Value of the added filter. It is a string representation of 175 * a regular expression. 176 */ 177 public void addLevelEntry(String name, String value){ 178 Object[] newEntry = new Object[2]; 179 newEntry[0] = name; 180 newEntry[1] = value; 181 m_rows.add(newEntry); 182 int lastElem = m_rows.size()-1; 183 fireTableRowsInserted(lastElem, lastElem); 184 } 185 186 187 /*** 188 * Removes the Level from the list. 189 * 190 * @param index Index of the row to remove. 191 * @return Object array with the filter which is now removed. 192 */ 193 public Object[] removeLevelEntry(int index){ 194 Object[] tmp = null; 195 try { 196 tmp = (Object[])m_rows.remove(index); 197 // if no row exists it's not possible to delete something 198 } catch ( IndexOutOfBoundsException e ) { } 199 fireTableRowsDeleted(index, index); 200 return tmp; 201 } 202 203 204 /*** 205 * Returns false for all cells except the first which is the check box for 206 * marking a filter entry. 207 * 208 * @param rowIndex the row being queried 209 * @param columnIndex the column being queried 210 * @return false for all the cells except the first one. 211 */ 212 public boolean isCellEditable(int rowIndex, int columnIndex) { 213 return CELL_IS_EDITABLE[columnIndex]; 214 } 215 216 217 /*** 218 * Clears the whole table model that means all the rows are deleted. 219 */ 220 public void clear(){ 221 m_rows.clear(); 222 } 223 }

This page was automatically generated by Maven