Source Code Cross Referenced for PowerTableModel.java in  » Testing » jakarta-jmeter » org » apache » jmeter » gui » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jakarta jmeter » org.apache.jmeter.gui.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *   http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         * 
017:         */
018:
019:        package org.apache.jmeter.gui.util;
020:
021:        import java.lang.reflect.Constructor;
022:        import java.lang.reflect.InvocationTargetException;
023:        import java.util.List;
024:
025:        import javax.swing.table.DefaultTableModel;
026:
027:        import org.apache.jorphan.collections.Data;
028:        import org.apache.jorphan.logging.LoggingManager;
029:        import org.apache.log.Logger;
030:
031:        /**
032:         * @author mstover
033:         */
034:        public class PowerTableModel extends DefaultTableModel {
035:            private static final Logger log = LoggingManager
036:                    .getLoggerForClass();
037:
038:            Data model = new Data();
039:
040:            Class[] columnClasses;
041:
042:            public PowerTableModel(String[] headers, Class[] cc) {
043:                if (headers.length != cc.length) {
044:                    throw new IllegalArgumentException(
045:                            "Header and column array sizes differ");
046:                }
047:                model.setHeaders(headers);
048:                columnClasses = cc;
049:            }
050:
051:            public PowerTableModel() {
052:            }
053:
054:            public void setRowValues(int row, Object[] values) {
055:                if (values.length != model.getHeaderCount()) {
056:                    throw new IllegalArgumentException(
057:                            "Incorrect number of data items");
058:                }
059:                model.setCurrentPos(row);
060:                for (int i = 0; i < values.length; i++) {
061:                    model.addColumnValue(model.getHeaders()[i], values[i]);
062:                }
063:            }
064:
065:            public Data getData() {
066:                return model;
067:            }
068:
069:            public void addNewColumn(String colName, Class colClass) {
070:                model.addHeader(colName);
071:                Class[] newClasses = new Class[columnClasses.length + 1];
072:                System.arraycopy(columnClasses, 0, newClasses, 0,
073:                        columnClasses.length);
074:                newClasses[newClasses.length - 1] = colClass;
075:                columnClasses = newClasses;
076:                Object defaultValue = createDefaultValue(columnClasses.length - 1);
077:                model.setColumnData(colName, defaultValue);
078:                this .fireTableStructureChanged();
079:            }
080:
081:            public void removeRow(int row) {
082:                log.debug("remove row: " + row);
083:                if (model.size() > row) {
084:                    log.debug("Calling remove row on Data");
085:                    model.removeRow(row);
086:                }
087:            }
088:
089:            public void removeColumn(int col) {
090:                model.removeColumn(col);
091:                this .fireTableStructureChanged();
092:            }
093:
094:            public void setColumnData(int col, List data) {
095:                model.setColumnData(col, data);
096:            }
097:
098:            public List getColumnData(String colName) {
099:                return model.getColumnAsObjectArray(colName);
100:            }
101:
102:            public void clearData() {
103:                String[] headers = model.getHeaders();
104:                model = new Data();
105:                model.setHeaders(headers);
106:                this .fireTableDataChanged();
107:            }
108:
109:            public void addRow(Object data[]) {
110:                if (data.length != model.getHeaderCount()) {
111:                    throw new IllegalArgumentException(
112:                            "Incorrect number of data items");
113:                }
114:                model.setCurrentPos(model.size());
115:                for (int i = 0; i < data.length; i++) {
116:                    model.addColumnValue(model.getHeaders()[i], data[i]);
117:                }
118:            }
119:
120:            public void addNewRow() {
121:                addRow(createDefaultRow());
122:            }
123:
124:            private Object[] createDefaultRow() {
125:                Object[] rowData = new Object[getColumnCount()];
126:                for (int i = 0; i < rowData.length; i++) {
127:                    rowData[i] = createDefaultValue(i);
128:                }
129:                return rowData;
130:            }
131:
132:            public Object[] getRowData(int row) {
133:                Object[] rowData = new Object[getColumnCount()];
134:                for (int i = 0; i < rowData.length; i++) {
135:                    rowData[i] = model.getColumnValue(i, row);
136:                }
137:                return rowData;
138:            }
139:
140:            private Object createDefaultValue(int i) {
141:                Class colClass = getColumnClass(i);
142:                try {
143:                    return colClass.newInstance();
144:                } catch (Exception e) {
145:                    try {
146:                        Constructor constr = colClass
147:                                .getConstructor(new Class[] { String.class });
148:                        return constr.newInstance(new Object[] { "" });
149:                    } catch (NoSuchMethodException err) {
150:                    } catch (InstantiationException err) {
151:                    } catch (IllegalAccessException err) {
152:                    } catch (InvocationTargetException err) {
153:                    }
154:                    try {
155:                        Constructor constr = colClass
156:                                .getConstructor(new Class[] { Integer.TYPE });
157:                        return constr
158:                                .newInstance(new Object[] { new Integer(0) });
159:                    } catch (NoSuchMethodException err) {
160:                    } catch (InstantiationException err) {
161:                    } catch (IllegalAccessException err) {
162:                    } catch (InvocationTargetException err) {
163:                    }
164:                    try {
165:                        Constructor constr = colClass
166:                                .getConstructor(new Class[] { Long.TYPE });
167:                        return constr
168:                                .newInstance(new Object[] { new Long(0L) });
169:                    } catch (NoSuchMethodException err) {
170:                    } catch (InstantiationException err) {
171:                    } catch (IllegalAccessException err) {
172:                    } catch (InvocationTargetException err) {
173:                    }
174:                    try {
175:                        Constructor constr = colClass
176:                                .getConstructor(new Class[] { Boolean.TYPE });
177:                        return constr
178:                                .newInstance(new Object[] { Boolean.FALSE });
179:                    } catch (NoSuchMethodException err) {
180:                    } catch (InstantiationException err) {
181:                    } catch (IllegalAccessException err) {
182:                    } catch (InvocationTargetException err) {
183:                    }
184:                    try {
185:                        Constructor constr = colClass
186:                                .getConstructor(new Class[] { Float.TYPE });
187:                        return constr
188:                                .newInstance(new Object[] { new Float(0F) });
189:                    } catch (NoSuchMethodException err) {
190:                    } catch (InstantiationException err) {
191:                    } catch (IllegalAccessException err) {
192:                    } catch (InvocationTargetException err) {
193:                    }
194:                    try {
195:                        Constructor constr = colClass
196:                                .getConstructor(new Class[] { Double.TYPE });
197:                        return constr
198:                                .newInstance(new Object[] { new Double(0D) });
199:                    } catch (NoSuchMethodException err) {
200:                    } catch (InstantiationException err) {
201:                    } catch (IllegalAccessException err) {
202:                    } catch (InvocationTargetException err) {
203:                    }
204:                    try {
205:                        Constructor constr = colClass
206:                                .getConstructor(new Class[] { Character.TYPE });
207:                        return constr.newInstance(new Object[] { new Character(
208:                                ' ') });
209:                    } catch (NoSuchMethodException err) {
210:                    } catch (InstantiationException err) {
211:                    } catch (IllegalAccessException err) {
212:                    } catch (InvocationTargetException err) {
213:                    }
214:                    try {
215:                        Constructor constr = colClass
216:                                .getConstructor(new Class[] { Byte.TYPE });
217:                        return constr.newInstance(new Object[] { new Byte(
218:                                Byte.MIN_VALUE) });
219:                    } catch (NoSuchMethodException err) {
220:                    } catch (InstantiationException err) {
221:                    } catch (IllegalAccessException err) {
222:                    } catch (InvocationTargetException err) {
223:                    }
224:                    try {
225:                        Constructor constr = colClass
226:                                .getConstructor(new Class[] { Short.TYPE });
227:                        return constr.newInstance(new Object[] { new Short(
228:                                Short.MIN_VALUE) });
229:                    } catch (NoSuchMethodException err) {
230:                    } catch (InstantiationException err) {
231:                    } catch (IllegalAccessException err) {
232:                    } catch (InvocationTargetException err) {
233:                    }
234:                }
235:                return "";
236:            }
237:
238:            /**
239:             * Required by table model interface.
240:             * 
241:             * @return the RowCount value
242:             */
243:            public int getRowCount() {
244:                if (model == null) {
245:                    return 0;
246:                }
247:                return model.size();
248:            }
249:
250:            /**
251:             * Required by table model interface.
252:             * 
253:             * @return the ColumnCount value
254:             */
255:            public int getColumnCount() {
256:                return model.getHeaders().length;
257:            }
258:
259:            /**
260:             * Required by table model interface.
261:             * 
262:             * @return the ColumnName value
263:             */
264:            public String getColumnName(int column) {
265:                return model.getHeaders()[column];
266:            }
267:
268:            public boolean isCellEditable(int row, int column) {
269:                // all table cells are editable
270:                return true;
271:            }
272:
273:            public Class getColumnClass(int column) {
274:                return columnClasses[column];
275:            }
276:
277:            /**
278:             * Required by table model interface. return the ValueAt value
279:             */
280:            public Object getValueAt(int row, int column) {
281:                return model.getColumnValue(column, row);
282:            }
283:
284:            /**
285:             * Sets the ValueAt attribute of the Arguments object.
286:             * 
287:             * @param value
288:             *            the new ValueAt value
289:             */
290:            public void setValueAt(Object value, int row, int column) {
291:                if (row < model.size()) {
292:                    model.setCurrentPos(row);
293:                    model.addColumnValue(model.getHeaders()[column], value);
294:                }
295:            }
296:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.