1 18 19 package org.apache.jmeter.visualizers; 20 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 25 import javax.swing.event.TableModelListener ; 26 import javax.swing.table.TableModel ; 27 28 import org.apache.jmeter.samplers.SampleResult; 29 import org.apache.jmeter.util.JMeterUtils; 30 import org.apache.jorphan.logging.LoggingManager; 31 import org.apache.jorphan.util.JOrphanUtils; 32 import org.apache.log.Logger; 33 34 35 43 public class TableDataModel extends GraphModel implements TableModel 44 { 45 transient private static Logger log = LoggingManager.getLoggerForClass(); 46 47 List urlList = new ArrayList (); 48 49 52 public TableDataModel() 53 { 54 super(); 55 } 56 57 62 public Class getGuiClass() 63 { 64 return TableVisualizer.class; 65 } 66 67 public void clear() 68 { 69 super.clear(); 70 urlList.clear(); 71 } 72 73 78 public String getClassLabel() 79 { 80 return JMeterUtils.getResString("view_results_in_table"); 81 } 82 83 public Sample addNewSample( 84 long time, 85 long timeStamp, 86 boolean success, 87 String url) 88 { 89 Sample s = super.addNewSample(time, timeStamp, success); 90 91 urlList.add(url); 92 return s; 93 } 94 95 public Sample addSample(SampleResult e) 96 { 97 Sample s = addNewSample(e.getTime(), e.getTimeStamp(), e.isSuccessful(), 98 (String ) e.getSampleLabel()); 99 100 fireDataChanged(); 101 102 return s; 103 } 104 105 public int getRowCount() 107 { 108 return getSampleCount(); 109 } 110 111 public int getColumnCount() 112 { 113 return 4; 115 } 116 117 public String getColumnName(int columnIndex) 118 { 119 switch (columnIndex) 120 { 121 case 0: 122 return "SampleNo"; 123 124 case 1: 125 return JMeterUtils.getResString("url"); 126 127 case 2: 128 return "Sample - ms"; 129 130 case 3: 131 return JMeterUtils.getResString("Success?"); 132 133 default: 134 return null; 135 } 136 } 137 138 public Class getColumnClass(int columnIndex) 139 { 140 if (columnIndex == 0) 141 { 142 return Integer .class; 143 } 144 else if (columnIndex == 1) 145 { 146 return String .class; 147 } 148 else if (columnIndex == 2) 149 { 150 return Long .class; 151 } 152 else if (columnIndex == 3) 153 { 154 return Boolean .class; 155 } 156 else 157 { 158 return null; 159 } 160 } 161 162 public boolean isCellEditable(int rowIndex, int columnIndex) 163 { 164 return false; 165 } 166 167 public Object getValueAt(int rowIndex, int columnIndex) 168 { 169 if (columnIndex == 0) 170 { 171 if ((rowIndex >= 0) && (rowIndex < getSampleCount())) 172 { 173 return new Integer (rowIndex + 1); 174 } 175 } 176 else if (columnIndex == 1) 177 { 178 log.debug("rowIndex = " + rowIndex); 179 if ((rowIndex >= 0) && (rowIndex < urlList.size())) 180 { 181 log.debug(" url = " + urlList.get(rowIndex)); 182 return urlList.get(rowIndex); 183 } 184 } 185 else if (columnIndex == 2) 186 { 187 if ((rowIndex >= 0) && (rowIndex < getSampleCount())) 188 { 189 return new Long (((Sample) getSamples().get(rowIndex)).data); 190 } 191 } 192 else if (columnIndex == 3) 193 { 194 if ((rowIndex >= 0) && (rowIndex < urlList.size())) 195 { 196 return JOrphanUtils.valueOf( 197 !((Sample) getSamples().get(rowIndex)).error); 198 } 199 } 200 return null; 201 } 202 203 206 public void setValueAt(Object aValue, int rowIndex, int columnIndex) 207 {} 208 209 212 public void addTableModelListener(TableModelListener l) 213 {} 214 215 218 public void removeTableModelListener(TableModelListener l) 219 {} 220 } 221 222 | Popular Tags |