Source Code Cross Referenced for DefaultTableModel.java in  » Scripting » groovy-1.0 » groovy » model » 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 » Scripting » groovy 1.0 » groovy.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         $Id: DefaultTableModel.java 259 2003-11-04 12:00:48Z jstrachan $
003:
004:         Copyright 2003 (C) James Strachan and Bob Mcwhirter. All Rights Reserved.
005:
006:         Redistribution and use of this software and associated documentation
007:         ("Software"), with or without modification, are permitted provided
008:         that the following conditions are met:
009:
010:         1. Redistributions of source code must retain copyright
011:            statements and notices.  Redistributions must also contain a
012:            copy of this document.
013:
014:         2. Redistributions in binary form must reproduce the
015:            above copyright notice, this list of conditions and the
016:            following disclaimer in the documentation and/or other
017:            materials provided with the distribution.
018:
019:         3. The name "groovy" must not be used to endorse or promote
020:            products derived from this Software without prior written
021:            permission of The Codehaus.  For written permission,
022:            please contact info@codehaus.org.
023:
024:         4. Products derived from this Software may not be called "groovy"
025:            nor may "groovy" appear in their names without prior written
026:            permission of The Codehaus. "groovy" is a registered
027:            trademark of The Codehaus.
028:
029:         5. Due credit should be given to The Codehaus -
030:            http://groovy.codehaus.org/
031:
032:         THIS SOFTWARE IS PROVIDED BY THE CODEHAUS AND CONTRIBUTORS
033:         ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
034:         NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
035:         FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
036:         THE CODEHAUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
037:         INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
038:         (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
039:         SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
040:         HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
041:         STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
042:         ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
043:         OF THE POSSIBILITY OF SUCH DAMAGE.
044:
045:         */
046:        package groovy.model;
047:
048:        import groovy.lang.Closure;
049:
050:        import java.util.Collections;
051:        import java.util.List;
052:
053:        import javax.swing.table.AbstractTableModel;
054:        import javax.swing.table.DefaultTableColumnModel;
055:        import javax.swing.table.TableColumnModel;
056:
057:        import org.codehaus.groovy.runtime.InvokerHelper;
058:
059:        /**
060:         * A default table model made up of PropertyModels on a Value model.
061:         * 
062:         * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
063:         * @version $Revision: 259 $
064:         */
065:        public class DefaultTableModel extends AbstractTableModel {
066:
067:            private ValueModel rowModel;
068:            private ValueModel rowsModel;
069:            private MyTableColumnModel columnModel = new MyTableColumnModel();
070:
071:            public DefaultTableModel(ValueModel rowsModel) {
072:                this (rowsModel, new ValueHolder());
073:            }
074:
075:            public DefaultTableModel(ValueModel rowsModel, ValueModel rowModel) {
076:                this .rowModel = rowModel;
077:                this .rowsModel = rowsModel;
078:            }
079:
080:            /**
081:             * @return the column definitions.
082:             */
083:            public List getColumnList() {
084:                return columnModel.getColumnList();
085:            }
086:
087:            public TableColumnModel getColumnModel() {
088:                return columnModel;
089:            }
090:
091:            /**
092:             * Adds a property model column to the table
093:             */
094:            public DefaultTableColumn addPropertyColumn(Object headerValue,
095:                    String property, Class type) {
096:                return addColumn(headerValue, new PropertyModel(rowModel,
097:                        property, type));
098:            }
099:
100:            /**
101:             * Adds a closure based column to the table
102:             */
103:            public DefaultTableColumn addClosureColumn(Object headerValue,
104:                    Closure readClosure, Closure writeClosure, Class type) {
105:                return addColumn(headerValue, new ClosureModel(rowModel,
106:                        readClosure, writeClosure, type));
107:            }
108:
109:            public DefaultTableColumn addColumn(Object headerValue,
110:                    ValueModel columnValueModel) {
111:                DefaultTableColumn answer = new DefaultTableColumn(headerValue,
112:                        columnValueModel);
113:                addColumn(answer);
114:                return answer;
115:            }
116:
117:            /**
118:             * Adds a new column definition to the table
119:             */
120:            public void addColumn(DefaultTableColumn column) {
121:                columnModel.addColumn(column);
122:            }
123:
124:            /**
125:             * Removes a column definition from the table
126:             */
127:            public void removeColumn(DefaultTableColumn column) {
128:                columnModel.removeColumn(column);
129:            }
130:
131:            public int getRowCount() {
132:                return getRows().size();
133:            }
134:
135:            public int getColumnCount() {
136:                return columnModel.getColumnCount();
137:            }
138:
139:            public String getColumnName(int columnIndex) {
140:                String answer = null;
141:                if (columnIndex < 0
142:                        || columnIndex >= columnModel.getColumnCount()) {
143:                    return answer;
144:                }
145:                Object value = columnModel.getColumn(columnIndex)
146:                        .getHeaderValue();
147:                if (value != null) {
148:                    return value.toString();
149:                }
150:                return answer;
151:            }
152:
153:            public Class getColumnClass(int columnIndex) {
154:                return getColumnModel(columnIndex).getType();
155:            }
156:
157:            public boolean isCellEditable(int rowIndex, int columnIndex) {
158:                return getColumnModel(columnIndex).isEditable();
159:            }
160:
161:            public Object getValueAt(int rowIndex, int columnIndex) {
162:                List rows = getRows();
163:                Object answer = null;
164:                if (rowIndex < 0 || rowIndex >= rows.size()) {
165:                    return answer;
166:                }
167:                if (columnIndex < 0
168:                        || columnIndex >= columnModel.getColumnCount()) {
169:                    return answer;
170:                }
171:                Object row = getRows().get(rowIndex);
172:                rowModel.setValue(row);
173:                DefaultTableColumn column = (DefaultTableColumn) columnModel
174:                        .getColumn(columnIndex);
175:                if (row == null || column == null) {
176:                    return answer;
177:                }
178:                return column.getValue(row, rowIndex, columnIndex);
179:            }
180:
181:            public void setValueAt(Object value, int rowIndex, int columnIndex) {
182:                List rows = getRows();
183:                if (rowIndex < 0 || rowIndex >= rows.size()) {
184:                    return;
185:                }
186:                if (columnIndex < 0
187:                        || columnIndex >= columnModel.getColumnCount()) {
188:                    return;
189:                }
190:                Object row = getRows().get(rowIndex);
191:                rowModel.setValue(row);
192:                DefaultTableColumn column = (DefaultTableColumn) columnModel
193:                        .getColumn(columnIndex);
194:                if (row == null || column == null) {
195:                    return;
196:                }
197:                column.setValue(row, value, rowIndex, columnIndex);
198:            }
199:
200:            protected ValueModel getColumnModel(int columnIndex) {
201:                DefaultTableColumn column = (DefaultTableColumn) columnModel
202:                        .getColumn(columnIndex);
203:                return column.getValueModel();
204:            }
205:
206:            protected List getRows() {
207:                Object value = rowsModel.getValue();
208:                if (value == null) {
209:                    return Collections.EMPTY_LIST;
210:                }
211:                return InvokerHelper.asList(value);
212:            }
213:
214:            protected static class MyTableColumnModel extends
215:                    DefaultTableColumnModel {
216:                public List getColumnList() {
217:                    return tableColumns;
218:                }
219:            }
220:
221:            public ValueModel getRowModel() {
222:                return rowModel;
223:            }
224:
225:            public ValueModel getRowsModel() {
226:                return rowsModel;
227:            }
228:
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.