Source Code Cross Referenced for DBTreeTable.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 24/10/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.awt.Color;
026:        import java.awt.Component;
027:        import java.sql.ResultSet;
028:        import java.sql.SQLException;
029:        import java.util.Date;
030:        import java.util.Map;
031:
032:        import javax.swing.JTree;
033:        import javax.swing.table.TableColumn;
034:        import javax.swing.table.TableColumnModel;
035:        import javax.swing.table.TableModel;
036:        import javax.swing.tree.DefaultMutableTreeNode;
037:        import javax.swing.tree.DefaultTreeCellRenderer;
038:
039:        import br.com.gfpshare.db.DAOCreationException;
040:        import br.com.gfpshare.db.PersistentObject;
041:
042:        /**
043:         * @author Igor Regis da Silva Simoes
044:         */
045:        public class DBTreeTable extends JTreeTable {
046:
047:            /**
048:             * Cria uma nova instância de DBTable
049:             */
050:            public DBTreeTable() {
051:                super (null);
052:            }
053:
054:            public DBTreeTable(DBTreeTableModel model) {
055:                super (model);
056:                createDefaultColumnsFromModel();
057:
058:                //This is the default state, but user can change it
059:                tree.setRootVisible(false);
060:                tree.setCellRenderer(new DefaultTreeCellRenderer() {
061:                    @Override
062:                    public Component getTreeCellRendererComponent(JTree tree,
063:                            Object value, boolean sel, boolean expanded,
064:                            boolean leaf, int row, boolean hasFocus) {
065:                        super .getTreeCellRendererComponent(tree, value, sel,
066:                                expanded, leaf, row, hasFocus);
067:                        if (value instanceof  DefaultMutableTreeNode) {
068:                            if (((DefaultMutableTreeNode) value)
069:                                    .getUserObject() instanceof  PersistentObject) {
070:                                setText(((PersistentObject) ((DefaultMutableTreeNode) value)
071:                                        .getUserObject())
072:                                        .getAsString(PersistentObject.CURTO));
073:                            } else if (((DefaultMutableTreeNode) value)
074:                                    .getUserObject() instanceof  ResultSet) {
075:                                try {
076:                                    setText(((ResultSet) ((DefaultMutableTreeNode) value)
077:                                            .getUserObject()).getMetaData()
078:                                            .getTableName(1));
079:                                } catch (SQLException e) {
080:                                    setText("|");
081:                                }
082:                            }
083:                        }
084:                        if (sel)
085:                            setForeground(Color.BLUE);
086:                        else
087:                            setForeground(Color.BLACK);
088:                        return this ;
089:                    }
090:                }
091:
092:                );
093:
094:                getColumn(getColumnName(1)).setCellRenderer(tree);
095:                getColumn(getColumnName(1)).setCellEditor(
096:                        new TreeTableCellEditor());
097:            }
098:
099:            /**
100:             * Cria uma nova instância de DBTable <br>
101:             * By default the DBTreeTable will hide the root element, if you need that this element
102:             * be visible, call the setRootVisible(boolean) method with a "true" argument
103:             * 
104:             * @param dataType tipo de dados que deverão ser carregados pelo componente.
105:             * @param fieldParentName
106:             */
107:            public DBTreeTable(PersistentObject dataType, String fieldParentName) {
108:                this (new DBTreeTableModel(dataType, fieldParentName));
109:            }
110:
111:            /**
112:             * Cria uma nova instância de DBTable
113:             * 
114:             * @param dataType tipo de dados que deverão ser carregados pelo componente.
115:             * @param fieldParentName
116:             * @param tableHeaderRenderer
117:             */
118:            public DBTreeTable(PersistentObject dataType,
119:                    String fieldParentName,
120:                    SortableTabelHeaderRenderer tableHeaderRenderer) {
121:                this (dataType, fieldParentName);
122:                tableHeader.setDefaultRenderer(tableHeaderRenderer);
123:            }
124:
125:            /**
126:             * Retona o modelo de dados que representa o conteúdo deste componente.
127:             * 
128:             * @return modelo de dados que representa o conteúdo deste componente, do tipo DBTableModel.
129:             * @see br.com.gfpshare.beans.DBComboBoxModel
130:             */
131:            public DBTreeTableModel getDBModel() {
132:                return ((TreeTableModelAdapter) dataModel)
133:                        .getDBTreeTableModel();
134:            }
135:
136:            /**
137:             * Retorna o ModelAdapter usado internamente
138:             * @return TreeTableModelAdapter
139:             */
140:            private TreeTableModelAdapter getModelAdapater() {
141:                return ((TreeTableModelAdapter) dataModel);
142:            }
143:
144:            /**
145:             * @see javax.swing.JTable#createDefaultDataModel()
146:             */
147:            @Override
148:            protected TableModel createDefaultDataModel() {
149:                return new DBTableModel(null);
150:            }
151:
152:            /**
153:             * @see javax.swing.JTable#createDefaultColumnsFromModel()
154:             */
155:            @Override
156:            public void createDefaultColumnsFromModel() {
157:                TableModel m = getModel();
158:                if (m != null) {
159:                    // Remove todas as colunas atuais
160:                    TableColumnModel cm = getColumnModel();
161:                    while (cm.getColumnCount() > 0) {
162:                        cm.removeColumn(cm.getColumn(0));
163:                    }
164:
165:                    // Cria novas colunas a partir do DataBaseTableModel
166:                    for (int i = 0; i < m.getColumnCount(); i++) {
167:                        TableColumn newColumn = new TableColumn(i);
168:
169:                        if (m.getColumnClass(i).getName().equals(
170:                                Date.class.getName())) {
171:                            newColumn
172:                                    .setCellRenderer(new ConfiguravelTableCellRenderer(
173:                                            ConfiguravelTableCellRenderer.DATA,
174:                                            -1));
175:                        } else if (m.getColumnClass(i).getName().equals(
176:                                Double.class.getName())) {
177:                            newColumn
178:                                    .setCellRenderer(new ConfiguravelTableCellRenderer(
179:                                            ConfiguravelTableCellRenderer.DINHEIRO,
180:                                            -1));
181:                        } else if (m.getColumnClass(i).getName().equals(
182:                                Boolean.class.getName())) {
183:                            newColumn
184:                                    .setCellRenderer(new ConfiguravelTableCellRenderer(
185:                                            ConfiguravelTableCellRenderer.BOOLEANO,
186:                                            -1));
187:                        } else
188:                            newColumn
189:                                    .setCellRenderer(new ConfiguravelTableCellRenderer(
190:                                            -1, -1));
191:                        addColumn(newColumn);
192:                    }
193:                }
194:            }
195:
196:            /**
197:             * Retorna o nome deste componente
198:             * 
199:             * @return Nome do componente
200:             */
201:            @Override
202:            public String getName() {
203:                return "DBTreeTable";
204:            }
205:
206:            /**
207:             * Retrona os dados em uma determinada posição na lista da tabela
208:             * 
209:             * @param index Posição onde estão os dados que se deseja recuperar
210:             * @return Map contendo os dados
211:             * @throws SQLException
212:             */
213:            public Map getDataAt(int index) throws SQLException {
214:                return getDBModel().getDataAt(index);
215:            }
216:
217:            /**
218:             * Retorna um PersistentObject representando os dados de uma determinada posição da coleção.
219:             * 
220:             * @param index Posição da qual se deseja pegar os dados.
221:             * @return PersistentObject representando os dados/
222:             */
223:            public PersistentObject getPersistentObject(int index) {
224:                Object node = null;
225:                if (index != -1
226:                        && (node = getModelAdapater().nodeForRow(index)) instanceof  DefaultMutableTreeNode
227:                        && ((DefaultMutableTreeNode) getModelAdapater()
228:                                .nodeForRow(index)).getUserObject() instanceof  PersistentObject)
229:                    return (PersistentObject) ((DefaultMutableTreeNode) getModelAdapater()
230:                            .nodeForRow(index)).getUserObject();
231:                else
232:                    return null;
233:            }
234:
235:            /**
236:             * Determina o tipo de dados contidos nesta coleção assim como o filtro para o que será retido.
237:             * 
238:             * @param dataType tipo de dados contidos nesta coleção assim como o filtro para o que será retido
239:             */
240:            public void setDataType(PersistentObject dataType) {
241:                getDBModel().setDataType(dataType);
242:            }
243:
244:            /**
245:             * Carrega os dados da colação a partir do banco de dados usando um critério para filtrar os dados
246:             * carregados.
247:             * 
248:             * @throws DAOCreationException Quando houver qualquer problema referente a conexão com o banco de
249:             *             dados.
250:             * @throws SQLException Quando houver problema na execução da query que retem os dados do banco.
251:             */
252:            public void filter() throws DAOCreationException, SQLException {
253:                getDBModel().filter();
254:            }
255:
256:            /**
257:             * Carrega os dados da coleção a partir do banco de dados.
258:             * 
259:             * @throws DAOCreationException Quando houver qualquer problema referente a conexão com o banco de
260:             *             dados.
261:             * @throws SQLException Quando houver problema na execução da query que retem os dados do banco.
262:             */
263:            public void loadDados() throws DAOCreationException, SQLException {
264:                getDBModel().loadDados();
265:            }
266:
267:            /**
268:             * Oculta uma coluna da tebela
269:             * 
270:             * @param columnName Nome da coluna a ser ocultada
271:             */
272:            public void hideColumn(String columnName) {
273:                getColumn(columnName).setWidth(0);
274:                getColumn(columnName).setMinWidth(0);
275:                getColumn(columnName).setMaxWidth(0);
276:            }
277:
278:            /**
279:             * Exibe uma coluna da tabla, caso esteja oculta
280:             * 
281:             * @param columnName Nome da coluna a ser exibida
282:             */
283:            public void showColumn(String columnName) {
284:                showColumn(columnName, 80);
285:            }
286:
287:            /**
288:             * Exibe uma coluna da tabla, caso esteja oculta
289:             * 
290:             * @param columnName Nome da coluna a ser exibida
291:             * @param width Largura da coluna
292:             */
293:            public void showColumn(String columnName, int width) {
294:                getColumn(columnName).setMinWidth(30);
295:                getColumn(columnName).setMaxWidth(150);
296:                getColumn(columnName).setWidth(width);
297:                getColumn(columnName).setPreferredWidth(width);
298:            }
299:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.