Source Code Cross Referenced for DBTable.java in  » ERP-CRM-Financial » Personal-Finance-Manager » br » com » gfpshare » beans » 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 » ERP CRM Financial » Personal Finance Manager » br.com.gfpshare.beans.table 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 16/07/2004
003:         * 
004:         * Swing Components - visit http://sf.net/projects/gfd
005:         * 
006:         * Copyright (C) 2004  Igor Regis da Silva Simões
007:         * 
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or (at your option) any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         * 
022:         */
023:        package br.com.gfpshare.beans.table;
024:
025:        import java.sql.SQLException;
026:        import java.util.Date;
027:        import java.util.Map;
028:
029:        import javax.swing.JTable;
030:        import javax.swing.table.JTableHeader;
031:        import javax.swing.table.TableColumn;
032:        import javax.swing.table.TableColumnModel;
033:        import javax.swing.table.TableModel;
034:
035:        import br.com.gfpshare.db.DAOCreationException;
036:        import br.com.gfpshare.db.PersistentObject;
037:
038:        /**
039:         * Componente de Tabela capaz de realizar conexão com um banco de dados para reter os dados que irão
040:         * preenche-lo. <BR>
041:         * Pra usá-lo basta instanciá-lo passando o tipo de dado que desevrá ser carregado do banco. O tipo passado
042:         * deverá ser um derivado de PersistentObject e a conexão com o banco de dados deverá estar devidamente
043:         * configurada através do DataBaseManager.
044:         * 
045:         * @see br.com.gfpshare.db.PersistentObject br.com.igor.db.DataBaseManager
046:         * @author Igor Regis da Silva Simoes
047:         */
048:        public class DBTable<T extends PersistentObject> extends JTable {
049:            /**
050:             * Cria uma nova instância de DBTable
051:             */
052:            public DBTable() {
053:                //Não fazemos nada
054:            }
055:
056:            /**
057:             * Cria uma nova instância de DBTable
058:             * 
059:             * @param dataType tipo de dados que deverão ser carregados pelo componente.
060:             */
061:            public DBTable(T dataType) {
062:                getDBModel().setDataType(dataType);
063:                try {
064:                    getDBModel().filter();
065:                } catch (DAOCreationException e) {
066:                    // TODO Auto-generated catch block
067:                    e.printStackTrace();
068:                } catch (SQLException e) {
069:                    // TODO Auto-generated catch block
070:                    e.printStackTrace();
071:                }
072:                createDefaultColumnsFromModel();
073:            }
074:
075:            /**
076:             * Cria uma nova instância de DBTable
077:             * 
078:             * @param dataType tipo de dados que deverão ser carregados pelo componente.
079:             * @param tableHeaderRenderer Rendere para o Header da tabela
080:             */
081:            public DBTable(T dataType,
082:                    SortableTabelHeaderRenderer tableHeaderRenderer) {
083:                getDBModel().setDataType(dataType);
084:                try {
085:                    getDBModel().filter();
086:                } catch (DAOCreationException e) {
087:                    // TODO Auto-generated catch block
088:                    e.printStackTrace();
089:                } catch (SQLException e) {
090:                    // TODO Auto-generated catch block
091:                    e.printStackTrace();
092:                }
093:                createDefaultColumnsFromModel();
094:                tableHeader.setDefaultRenderer(tableHeaderRenderer);
095:            }
096:
097:            /**
098:             * Retona o modelo de dados que representa o conteúdo deste componente.
099:             * 
100:             * @return modelo de dados que representa o conteúdo deste componente, do tipo DBTableModel.
101:             * @see br.com.gfpshare.beans.DBComboBoxModel
102:             */
103:            public DBTableModel getDBModel() {
104:                return (DBTableModel) dataModel;
105:            }
106:
107:            /**
108:             * @see javax.swing.JTable#createDefaultDataModel()
109:             */
110:            @Override
111:            protected TableModel createDefaultDataModel() {
112:                return new DBTableModel(null);
113:            }
114:
115:            /**
116:             * @see javax.swing.JTable#createDefaultTableHeader()
117:             */
118:            @Override
119:            protected JTableHeader createDefaultTableHeader() {
120:                JTableHeader tableHeader = new JTableHeader(columnModel);
121:                tableHeader
122:                        .setDefaultRenderer(new SortableTabelHeaderRenderer());
123:                return tableHeader;
124:            }
125:
126:            /**
127:             * @see javax.swing.JTable#createDefaultColumnsFromModel()
128:             */
129:            @Override
130:            public void createDefaultColumnsFromModel() {
131:                TableModel m = getModel();
132:                if (m != null) {
133:                    // Remove todas as colunas atuais
134:                    TableColumnModel cm = getColumnModel();
135:                    while (cm.getColumnCount() > 0) {
136:                        cm.removeColumn(cm.getColumn(0));
137:                    }
138:
139:                    // Cria novas colunas a partir do DataBaseTableModel
140:                    for (int i = 0; i < m.getColumnCount(); i++) {
141:                        TableColumn newColumn = new TableColumn(i);
142:
143:                        if (m.getColumnClass(i).getName().equals(
144:                                Date.class.getName())) {
145:                            newColumn
146:                                    .setCellRenderer(new ConfiguravelTableCellRenderer(
147:                                            ConfiguravelTableCellRenderer.DATA,
148:                                            -1));
149:                        } else if (m.getColumnClass(i).getName().equals(
150:                                Double.class.getName())) {
151:                            newColumn
152:                                    .setCellRenderer(new ConfiguravelTableCellRenderer(
153:                                            ConfiguravelTableCellRenderer.DINHEIRO,
154:                                            -1));
155:                        } else if (m.getColumnClass(i).getName().equals(
156:                                Boolean.class.getName())) {
157:                            newColumn
158:                                    .setCellRenderer(new ConfiguravelTableCellRenderer(
159:                                            ConfiguravelTableCellRenderer.BOOLEANO,
160:                                            -1));
161:                        } else
162:                            newColumn
163:                                    .setCellRenderer(new ConfiguravelTableCellRenderer(
164:                                            -1, -1));
165:                        addColumn(newColumn);
166:                    }
167:                }
168:            }
169:
170:            /**
171:             * Retorna o nome deste componente
172:             * 
173:             * @return Nome do componente
174:             */
175:            @Override
176:            public String getName() {
177:                return "DBTable";
178:            }
179:
180:            /**
181:             * Retrona os dados em uma determinada posição na lista da tabela
182:             * 
183:             * @param index Posição onde estão os dados que se deseja recuperar
184:             * @return Map contendo os dados
185:             * @throws SQLException
186:             */
187:            public Map<String, Object> getDataAt(int index) throws SQLException {
188:                return getDBModel().getDataAt(index);
189:            }
190:
191:            /**
192:             * Retorna um PersistentObject representando os dados de uma determinada posição da coleção.
193:             * 
194:             * @param index Posição da qual se deseja pegar os dados.
195:             * @return PersistentObject representando os dados/
196:             * @throws SQLException Caso ocorra um erro sql.
197:             */
198:            public T getPersistentObject(int index) throws SQLException {
199:                return (T) getDBModel().getPersistentObject(index);
200:            }
201:
202:            /**
203:             * Determina o tipo de dados contidos nesta coleção assim como o filtro para o que será retido.
204:             * 
205:             * @param dataType tipo de dados contidos nesta coleção assim como o filtro para o que será retido
206:             */
207:            public void setDataType(T dataType) {
208:                getDBModel().setDataType(dataType);
209:            }
210:
211:            /**
212:             * Carrega os dados da colação a partir do banco de dados usando um critério para filtrar os dados
213:             * carregados.
214:             * 
215:             * @throws DAOCreationException Quando houver qualquer problema referente a conexão com o banco de
216:             *             dados.
217:             * @throws SQLException Quando houver problema na execução da query que retem os dados do banco.
218:             */
219:            public void filter() throws DAOCreationException, SQLException {
220:                getDBModel().filter();
221:            }
222:
223:            /**
224:             * Carrega os dados da coleção a partir do banco de dados.
225:             * 
226:             * @throws DAOCreationException Quando houver qualquer problema referente a conexão com o banco de
227:             *             dados.
228:             * @throws SQLException Quando houver problema na execução da query que retem os dados do banco.
229:             */
230:            public void loadDados() throws DAOCreationException, SQLException {
231:                try {
232:                    setDataType((T) getDBModel().getDataType().getClass()
233:                            .newInstance());
234:                } catch (Exception e) {
235:                    // TODO Auto-generated catch block
236:                    e.printStackTrace();
237:                }
238:                getDBModel().loadDados();
239:            }
240:
241:            /**
242:             * Oculta uma coluna da tebela
243:             * 
244:             * @param columnName Nome da coluna a ser ocultada
245:             */
246:            public void hideColumn(String columnName) {
247:                getColumn(columnName).setWidth(0);
248:                getColumn(columnName).setMinWidth(0);
249:                getColumn(columnName).setMaxWidth(0);
250:            }
251:
252:            /**
253:             * Exibe uma coluna da tabla, caso esteja oculta
254:             * 
255:             * @param columnName Nome da coluna a ser exibida
256:             */
257:            public void showColumn(String columnName) {
258:                showColumn(columnName, 80);
259:            }
260:
261:            /**
262:             * Exibe uma coluna da tabla, caso esteja oculta
263:             * 
264:             * @param columnName Nome da coluna a ser exibida
265:             * @param width Largura da coluna
266:             */
267:            public void showColumn(String columnName, int width) {
268:                getColumn(columnName).setMinWidth(30);
269:                getColumn(columnName).setMaxWidth(150);
270:                getColumn(columnName).setWidth(width);
271:                getColumn(columnName).setPreferredWidth(width);
272:            }
273:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.