Coverage report

  %line %branch
org.apache.commons.jelly.tags.swing.model.ExpressionTableModel
0% 
0% 

 1  
 /*
 2  
  * Copyright 2002,2004 The Apache Software Foundation.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.apache.commons.jelly.tags.swing.model;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import javax.swing.table.AbstractTableModel;
 22  
 import javax.swing.table.DefaultTableColumnModel;
 23  
 import javax.swing.table.TableColumnModel;
 24  
 
 25  
 import org.apache.commons.jelly.JellyContext;
 26  
 
 27  
 /**
 28  
  * A Swing TableModel that uses a List of rows with pluggable Expressions
 29  
  * to evaluate the value of the cells
 30  
  *
 31  
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 32  
  * @version $Revision: 155420 $
 33  
  */
 34  
 public class ExpressionTableModel extends AbstractTableModel {
 35  
 
 36  
     private JellyContext context;
 37  0
     private List rows = new ArrayList();
 38  0
     private MyTableColumnModel columnModel = new MyTableColumnModel();
 39  
 
 40  0
     public ExpressionTableModel() {
 41  0
     }
 42  
 
 43  
     /**
 44  
      * Returns the column definitions.
 45  
      * @return List
 46  
      */
 47  
     public List getColumnList() {
 48  0
         return columnModel.getColumnList();
 49  
     }
 50  
 
 51  
     /**
 52  
      * @return the TableColumnModel
 53  
      */
 54  
     public TableColumnModel getColumnModel() {
 55  0
         return columnModel;
 56  
     }
 57  
 
 58  
     /**
 59  
      * Adds a new column definition to the table
 60  
      */
 61  
     public void addColumn(ExpressionTableColumn column) {
 62  0
         columnModel.addColumn(column);
 63  0
     }
 64  
 
 65  
     /**
 66  
      * Removes a column definition from the table
 67  
      */
 68  
     public void removeColumn(ExpressionTableColumn column) {
 69  0
         columnModel.removeColumn(column);
 70  0
     }
 71  
 
 72  
 
 73  
     // TableModel interface
 74  
     //-------------------------------------------------------------------------
 75  
     public int getRowCount() {
 76  0
         return rows.size();
 77  
     }
 78  
 
 79  
     public int getColumnCount() {
 80  0
         return columnModel.getColumnCount();
 81  
     }
 82  
 
 83  
     public String getColumnName(int columnIndex) {
 84  0
         String answer = null;
 85  0
         if (columnIndex < 0 || columnIndex >= columnModel.getColumnCount()) {
 86  0
             return answer;
 87  
         }
 88  0
         Object value = columnModel.getColumn(columnIndex).getHeaderValue();
 89  0
         if (value != null) {
 90  0
             return value.toString();
 91  
         }
 92  0
         return answer;
 93  
     }
 94  
 
 95  
     public Object getValueAt(int rowIndex, class="keyword">int columnIndex) {
 96  0
         Object answer = null;
 97  0
         if (rowIndex < 0 || rowIndex >= rows.size()) {
 98  0
             return answer;
 99  
         }
 100  0
         if (columnIndex < 0 || columnIndex >= columnModel.getColumnCount()) {
 101  0
             return answer;
 102  
         }
 103  0
         Object row = rows.get(rowIndex);;
 104  0
         ExpressionTableColumn column = (ExpressionTableColumn) columnModel.getColumn(columnIndex);
 105  0
         if (row == null || column == class="keyword">null) {
 106  0
             return answer;
 107  
         }
 108  0
         return column.evaluateValue(this, row, rowIndex, columnIndex);
 109  
     }
 110  
 
 111  
 
 112  
     // Properties
 113  
     //-------------------------------------------------------------------------
 114  
 
 115  
 
 116  
     /**
 117  
      * Returns the list of rows.
 118  
      * @return List
 119  
      */
 120  
     public List getRows() {
 121  0
         return rows;
 122  
     }
 123  
 
 124  
     /**
 125  
      * Sets the list of rows.
 126  
      * @param rows The rows to set
 127  
      */
 128  
     public void setRows(List rows) {
 129  0
         this.rows = rows;
 130  0
     }
 131  
 
 132  
     /**
 133  
      * Returns the context.
 134  
      * @return JellyContext
 135  
      */
 136  
     public JellyContext getContext() {
 137  0
         return context;
 138  
     }
 139  
 
 140  
     /**
 141  
      * Sets the context.
 142  
      * @param context The context to set
 143  
      */
 144  
     public void setContext(JellyContext context) {
 145  0
         this.context = context;
 146  0
     }
 147  
 
 148  
     // Implementation methods
 149  
     //-------------------------------------------------------------------------
 150  
     protected static class MyTableColumnModel extends DefaultTableColumnModel {
 151  
         public List getColumnList() {
 152  
             return tableColumns;
 153  
         }
 154  
     };
 155  
 
 156  
 
 157  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.