KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > visualizers > TableDataModel


1 // $Header: /home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/visualizers/Attic/TableDataModel.java,v 1.13 2004/02/13 01:48:46 sebb Exp $
2
/*
3  * Copyright 2002-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.visualizers;
20
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24
25 import javax.swing.event.TableModelListener JavaDoc;
26 import javax.swing.table.TableModel JavaDoc;
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 /**
36  * This class implements the TableModel for the information kept by the
37  * GraphModel.
38  *
39  * @author <a HREF="mailto:alf@i100.no">Alf Hogemark</a>Hogemark
40  * Created March 10, 2002
41  * @version $Revision: 1.13 $ Last updated: $Date: 2004/02/13 01:48:46 $
42  */

43 public class TableDataModel extends GraphModel implements TableModel JavaDoc
44 {
45     transient private static Logger log = LoggingManager.getLoggerForClass();
46
47     List JavaDoc urlList = new ArrayList JavaDoc();
48
49     /**
50      * Constructor for the TableDataModel object.
51      */

52     public TableDataModel()
53     {
54         super();
55     }
56
57     /**
58      * Gets the GuiClass attribute of the TableModel object.
59      *
60      * @return the GuiClass value
61      */

62     public Class JavaDoc getGuiClass()
63     {
64         return TableVisualizer.class;
65     }
66
67     public void clear()
68     {
69         super.clear();
70         urlList.clear();
71     }
72
73     /**
74      * Gets the ClassLabel attribute of the GraphModel object.
75      *
76      * @return the ClassLabel value
77      */

78     public String JavaDoc 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 JavaDoc 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 JavaDoc) e.getSampleLabel());
99
100         fireDataChanged();
101
102         return s;
103     }
104
105     // Implmentation of the TableModel interface
106
public int getRowCount()
107     {
108         return getSampleCount();
109     }
110
111     public int getColumnCount()
112     {
113         // We have two columns : sampleNo and sampleValue
114
return 4;
115     }
116
117     public String JavaDoc 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 JavaDoc getColumnClass(int columnIndex)
139     {
140         if (columnIndex == 0)
141         {
142             return Integer JavaDoc.class;
143         }
144         else if (columnIndex == 1)
145         {
146             return String JavaDoc.class;
147         }
148         else if (columnIndex == 2)
149         {
150             return Long JavaDoc.class;
151         }
152         else if (columnIndex == 3)
153         {
154             return Boolean JavaDoc.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 JavaDoc getValueAt(int rowIndex, int columnIndex)
168     {
169         if (columnIndex == 0)
170         {
171             if ((rowIndex >= 0) && (rowIndex < getSampleCount()))
172             {
173                 return new Integer JavaDoc(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 JavaDoc(((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     /**
204      * Dummy implementation.
205      */

206     public void setValueAt(Object JavaDoc aValue, int rowIndex, int columnIndex)
207     {}
208
209     /**
210      * Dummy implementation.
211      */

212     public void addTableModelListener(TableModelListener JavaDoc l)
213     {}
214
215     /**
216      * Dummy implementation.
217      */

218     public void removeTableModelListener(TableModelListener JavaDoc l)
219     {}
220 }
221
222
Popular Tags