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