Source Code Cross Referenced for JETATableModel.java in  » Swing-Library » abeille-forms-designer » com » jeta » swingbuilder » gui » components » 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 » Swing Library » abeille forms designer » com.jeta.swingbuilder.gui.components 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2005 Jeff Tassin
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:
019:        package com.jeta.swingbuilder.gui.components;
020:
021:        import java.util.ArrayList;
022:        import java.util.Collection;
023:
024:        import javax.swing.table.AbstractTableModel;
025:
026:        import com.jeta.open.support.EmptyCollection;
027:
028:        /**
029:         * This class is the table model for the common tables.
030:         * 
031:         * @author Jeff Tassin
032:         */
033:        public class JETATableModel extends AbstractTableModel {
034:            /** an array of Trigger object */
035:            private ArrayList m_data;
036:
037:            /** an array of column names for the table */
038:            private String[] m_colnames;
039:
040:            /** an array of column types for the table */
041:            private Class[] m_coltypes;
042:
043:            /**
044:             * ctor.
045:             * 
046:             * @param connection
047:             *            the underlying database connection
048:             * @param tableId
049:             *            the id of the table we are displaying the indices for
050:             */
051:            public JETATableModel() {
052:
053:            }
054:
055:            /**
056:             * Adds the given trigger object to the table
057:             */
058:            public void addRow(Object obj) {
059:                if (m_data == null)
060:                    m_data = new ArrayList();
061:
062:                m_data.add(obj);
063:                fireTableRowsInserted(m_data.size() - 1, m_data.size() - 1);
064:            }
065:
066:            /**
067:             * @return true if the model contains the given object
068:             */
069:            public boolean contains(Object obj) {
070:                if (m_data == null)
071:                    return false;
072:                else
073:                    return m_data.contains(obj);
074:            }
075:
076:            /**
077:             * @return the number of columns in this model
078:             */
079:            public int getColumnCount() {
080:                return m_colnames.length;
081:            }
082:
083:            /**
084:             * @return the collection of objects in this model
085:             */
086:            public Collection getData() {
087:                if (m_data == null)
088:                    return EmptyCollection.getInstance();
089:                else
090:                    return m_data;
091:            }
092:
093:            /**
094:             * @return the number of rows objects in this model
095:             */
096:            public int getRowCount() {
097:                if (m_data == null)
098:                    return 0;
099:                else
100:                    return m_data.size();
101:            }
102:
103:            /**
104:             * @return the name of a column at a given index
105:             */
106:            public String getColumnName(int column) {
107:                return m_colnames[column];
108:            }
109:
110:            /**
111:             * @return the type of column at a given index
112:             */
113:            public Class getColumnClass(int column) {
114:                return m_coltypes[column];
115:            }
116:
117:            /**
118:             * @return the object at the given row in the model
119:             */
120:            public Object getRow(int row) {
121:                if (m_data == null)
122:                    return null;
123:                else {
124:                    if (row >= 0 && row < m_data.size())
125:                        return m_data.get(row);
126:                    else
127:                        return null;
128:                }
129:            }
130:
131:            /**
132:             * @return the Object at the given row column. Note: you generally override
133:             *         this method
134:             */
135:            public Object getValueAt(int row, int col) {
136:                Object obj = getRow(row);
137:                if (obj instanceof  Object[]) {
138:                    Object[] array = (Object[]) obj;
139:                    return array[col];
140:                } else {
141:                    return obj;
142:                }
143:            }
144:
145:            /**
146:             * @return the index of the given object if it is contained in this model.
147:             *         -1 is returned if this model does not contain the object.
148:             */
149:            public int indexOf(Object obj) {
150:                return m_data.indexOf(obj);
151:            }
152:
153:            /**
154:             * Inserts the object at the given row in the model.
155:             */
156:            public void insertRow(Object obj, int row) {
157:                if (row < 0)
158:                    row = 0;
159:
160:                if (row >= m_data.size())
161:                    m_data.add(obj);
162:                else
163:                    m_data.add(row, obj);
164:            }
165:
166:            private static int gcd(int i, int j) {
167:                return (j == 0) ? i : gcd(j, i % j);
168:            }
169:
170:            public void moveRow(int start, int end, int to)
171:                    throws IndexOutOfBoundsException {
172:                int shift = to - start;
173:                int first, last;
174:                if (shift < 0) {
175:                    first = to;
176:                    last = end;
177:                } else {
178:                    first = start;
179:                    last = to + end - start;
180:                }
181:
182:                int a = first;
183:                int b = last + 1;
184:
185:                int size = b - a;
186:                int r = size - shift;
187:                int g = gcd(size, r);
188:                for (int i = 0; i < g; i++) {
189:                    to = i;
190:                    Object tmp = m_data.get(a + to);
191:                    for (int from = (to + r) % size; from != i; from = (to + r)
192:                            % size) {
193:                        m_data.set(a + to, m_data.get(a + from));
194:                        to = from;
195:                    }
196:                    m_data.set(a + to, tmp);
197:                }
198:                fireTableRowsUpdated(first, last);
199:            }
200:
201:            /**
202:             * Remove all data items from this model
203:             */
204:            public void removeAll() {
205:                if (m_data != null) {
206:                    m_data.clear();
207:                    fireTableDataChanged();
208:                }
209:            }
210:
211:            /**
212:             * Removes the object at the given row
213:             */
214:            public Object removeRow(int row) {
215:                Object obj = getRow(row);
216:                m_data.remove(obj);
217:                return obj;
218:            }
219:
220:            /**
221:             * Removes the object at the given row
222:             */
223:            public boolean remove(Object obj) {
224:                int index = m_data.indexOf(obj);
225:                if (index >= 0) {
226:                    m_data.remove(index);
227:                    fireTableRowsDeleted(index, index);
228:                    return true;
229:                } else {
230:                    return false;
231:                }
232:            }
233:
234:            public Object set(int index, Object element)
235:                    throws IndexOutOfBoundsException {
236:                Object result = m_data.set(index, element);
237:                fireTableRowsUpdated(index, index);
238:                return result;
239:            }
240:
241:            /**
242:             * Sets the names for the columns in this model
243:             */
244:            public void setColumnNames(String[] names) {
245:                m_colnames = names;
246:            }
247:
248:            /**
249:             * Sets the types for the columns in this model
250:             */
251:            public void setColumnTypes(Class[] types) {
252:                m_coltypes = types;
253:            }
254:
255:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.