Source Code Cross Referenced for TableModel.java in  » Database-Client » dbmjui » fr » aliacom » common » ui » table » 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 » Database Client » dbmjui » fr.aliacom.common.ui.table 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package fr.aliacom.common.ui.table;
002:
003:        import java.beans.PropertyChangeEvent;
004:        import java.beans.PropertyChangeListener;
005:        import java.util.ArrayList;
006:
007:        import org.apache.log4j.Logger;
008:
009:        import fr.aliacom.bean.BeanUtils;
010:        import fr.aliacom.form.common.ToolkitManager;
011:
012:        /**
013:         * TableModel class used by all ITable implementations.
014:         * 
015:         * The model stores its data in an <code>ArrayList</code> of
016:         * java beans.
017:         * 
018:         * Each "column" in the model is a property of the JavaBean.
019:         * The mapping between properties and columns in done by the
020:         * {@link fr.aliacom.common.ui.table.BeanPropertiesMapping}.
021:         * 
022:         * @author tom
023:         *
024:         * (c) 2001, 2003 Thomas Cataldo
025:         */
026:        public final class TableModel implements  PropertyChangeListener {
027:
028:            private ArrayList data;
029:            private BeanPropertiesMapping columnsModel;
030:            private ArrayList listeners;
031:
032:            private static final Logger log = Logger
033:                    .getLogger(TableModel.class);
034:
035:            /**
036:             * Creates a tableModel.
037:             * The column model will be initialized by the form parsing process.
038:             */
039:            public TableModel() {
040:                data = new ArrayList();
041:                columnsModel = new BeanPropertiesMapping();
042:                listeners = new ArrayList();
043:            }
044:
045:            public BeanPropertiesMapping getColumnModel() {
046:                return columnsModel;
047:            }
048:
049:            public int getRowCount() {
050:                return data.size();
051:            }
052:
053:            public int getColumnCount() {
054:                return columnsModel.getPropertiesCount();
055:            }
056:
057:            public void setValueAt(Object value, int row, int column) {
058:                BeanUtils.setValue(data.get(row), columnsModel
059:                        .getProperty(column - 1), value);
060:                fireTableCellUpdated(row, column);
061:            }
062:
063:            public Object getValueAt(int row, int column) {
064:                Object bean = data.get(row);
065:                if (column == 0) {
066:                    return bean;
067:                } else {
068:                    return BeanUtils.getValue(bean, columnsModel
069:                            .getProperty(column - 1));
070:                }
071:            }
072:
073:            public void addRow(Object rowData) {
074:                addRowFast(rowData);
075:                fireTableRowsInserted(getRowCount() - 1, getRowCount());
076:            }
077:
078:            public void addTableModelListener(ITableModelListener aml) {
079:                listeners.add(aml);
080:            }
081:
082:            public void removeTableModelListener(ITableModelListener aml) {
083:                listeners.remove(aml);
084:            }
085:
086:            private void addRowFast(Object rowData) {
087:                data.add(rowData);
088:                BeanUtils.addPropertyChangeListener(rowData, this );
089:            }
090:
091:            public void addRows(ArrayList rowsData) {
092:                for (int i = 0; i < rowsData.size(); i++) {
093:                    addRowFast(rowsData.get(i));
094:                }
095:
096:                fireTableRowsInserted(getRowCount() - rowsData.size(),
097:                        getRowCount());
098:            }
099:
100:            private final class RowsSetter implements  Runnable {
101:                private ArrayList rows;
102:
103:                public void setRows(ArrayList rowsData) {
104:                    rows = rowsData;
105:                }
106:
107:                public void run() {
108:                    removeAll();
109:                    addRows(rows);
110:                }
111:            }
112:
113:            public void setRows(ArrayList rowsData) {
114:                log.debug("setRows(arrayList rowsData (size=" + rowsData.size()
115:                        + "))");
116:                final RowsSetter setter = new RowsSetter();
117:                setter.setRows(rowsData);
118:                ToolkitManager.getToolkit().asyncExec(setter);
119:            }
120:
121:            public ArrayList getRows() {
122:                return data;
123:            }
124:
125:            public void removeAll() {
126:                int max = data.size();
127:                for (int i = 0; i < max; i++) {
128:                    BeanUtils.removePropertyChangeListener(data.get(i), this );
129:                }
130:                data.clear();
131:
132:                if (max != 0) {
133:                    fireTableRowsDeleted(0, max - 1);
134:                }
135:            }
136:
137:            public Object removeRow(Object row) {
138:                int index = data.indexOf(row);
139:                if (index != -1) {
140:                    return removeRow(index);
141:                } else {
142:                    return null;
143:                }
144:            }
145:
146:            private Object removeRowFast(int row) {
147:                Object o = data.get(row);
148:                BeanUtils.removePropertyChangeListener(o, this );
149:                data.remove(row);
150:                return o;
151:            }
152:
153:            public Object removeRow(int row) {
154:                Object o = removeRowFast(row);
155:                fireTableRowsDeleted(row, row);
156:                return o;
157:            }
158:
159:            /**
160:             * Returns the JavaBean displayed at a given row.
161:             * 
162:             * @param rowIndex
163:             * @return Object the javaBean presented at <code>rowIndex</code>
164:             */
165:            public Object getRow(int rowIndex) {
166:                return data.get(rowIndex);
167:            }
168:
169:            /**
170:             * Method fireTableCellUpdated.
171:             * @param i
172:             * @param i1
173:             */
174:            private void fireTableCellUpdated(int i, int i1) {
175:                ITableModelListener aml;
176:                for (int a = 0, n = listeners.size(); a < n; a++) {
177:                    aml = (ITableModelListener) listeners.get(a);
178:                    aml.tableCellUpdated(i, i1);
179:                }
180:            }
181:
182:            /**
183:             * Method fireTableRowsDeleted.
184:             * @param i
185:             * @param max
186:             */
187:            private void fireTableRowsDeleted(int i, int max) {
188:                ITableModelListener aml;
189:                for (int a = 0, n = listeners.size(); a < n; a++) {
190:                    aml = (ITableModelListener) listeners.get(a);
191:                    aml.tableRowsDeleted(i, max);
192:                }
193:            }
194:
195:            /**
196:             * Method fireTableRowsInserted.
197:             * @param i
198:             * @param i1
199:             */
200:            private void fireTableRowsInserted(int i, int i1) {
201:                ITableModelListener aml;
202:                for (int a = 0, n = listeners.size(); a < n; a++) {
203:                    aml = (ITableModelListener) listeners.get(a);
204:                    aml.tableRowsInserted(i, i1);
205:                }
206:            }
207:
208:            public void propertyChange(PropertyChangeEvent evt) {
209:                log.debug("PropertyChangeEvent from " + evt.getSource());
210:                int row = data.indexOf(evt.getSource());
211:                int column = columnsModel.getIndex(evt.getPropertyName());
212:                log.debug("property '" + evt.getPropertyName() + "' (column="
213:                        + column + ") change at row " + row);
214:                if (column > 0) {
215:                    fireTableCellUpdated(row, columnsModel.getIndex(evt
216:                            .getPropertyName()));
217:                }
218:            }
219:
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.