Source Code Cross Referenced for TableInfoPanel.java in  » Database-Client » QueryForm » org » glasser » qform » 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 » QueryForm » org.glasser.qform 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:         * Copyright (c) 1998 - 2004 David F. Glasser.  All rights
003:         * reserved.
004:         *
005:         * This file is part of the QueryForm Database Tool.
006:         *
007:         * The QueryForm Database Tool is free software; you can redistribute it
008:         * and/or modify it under the terms of the GNU General Public License as
009:         * published by the Free Software Foundation; either version 2 of the
010:         * License, or (at your option) any later version.
011:         *
012:         * The QueryForm Database Tool is distributed in the hope that it will
013:         * be useful, but WITHOUT ANY WARRANTY; without even the implied
014:         * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
015:         * See the GNU General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU General Public License
018:         * along with the QueryForm Database Tool; if not, write to:
019:         *
020:         *      The Free Software Foundation, Inc.,
021:         *      59 Temple Place, Suite 330
022:         *      Boston, MA  02111-1307  USA
023:         *
024:         * or visit http://www.gnu.org.
025:         *
026:         * ====================================================================
027:         *
028:         * This product includes software developed by the
029:         * Apache Software Foundation (http://www.apache.org/).
030:         *
031:         * ==================================================================== 
032:         *
033:         * $Source: /cvsroot/qform/qform/src/org/glasser/qform/TableInfoPanel.java,v $
034:         * $Revision: 1.7 $
035:         * $Author: dglasser $
036:         * $Date: 2004/09/28 02:05:45 $
037:         * 
038:         * --------------------------------------------------------------------
039:         */
040:        package org.glasser.qform;
041:
042:        import javax.swing.*;
043:        import javax.swing.border.*;
044:        import java.awt.*;
045:        import java.awt.event.*;
046:        import javax.swing.table.*;
047:        import java.util.*;
048:        import org.glasser.util.*;
049:        import org.glasser.util.comparators.MethodComparator;
050:        import org.glasser.sql.*;
051:        import org.glasser.swing.*;
052:        import org.glasser.swing.table.*;
053:        import org.glasser.sql.*;
054:        import javax.swing.event.*;
055:
056:        public class TableInfoPanel extends JPanel {
057:
058:            private TableInfo tableInfo = null;
059:
060:            JTabbedPane tabbedPane = new JTabbedPane();
061:
062:            protected final String[] columnNames = { "Ordinal", "PK",
063:                    "Column Name", "Data Type", "SQL Type", "Nullable", "Size",
064:                    "Decimal Digits", "Default" };
065:
066:            protected final String[] getters = { "getOrdinal",
067:                    "getPkComponent", "getColumnName", "getTypeName",
068:                    "getDataType", "getNullable", "getColumnSize",
069:                    "getDecimalDigits", "getColumnDefaultValue" };
070:
071:            ListTableModel columnTableModel = null;
072:
073:            JTable columnTable = null;
074:
075:            ListTableModel fkeyModel = null;
076:            JPanel fkeyPanel = new JPanel();
077:            JTable fkeysTable = null;
078:
079:            ListTableModel fcolModel = new ListTableModel(
080:                    new ForeignKeyColumnManager(), null);
081:            JTable fcolTable = new JTable(fcolModel);
082:
083:            ListTableModel exkeyModel = null;
084:            JPanel exkeyPanel = new JPanel();
085:            JTable exkeysTable = null;
086:
087:            ListTableModel excolModel = new ListTableModel(
088:                    new ExportedKeyColumnManager(), null);
089:
090:            JTable excolTable = new JTable(excolModel);
091:
092:            JTextField txtDsName = new JTextField();
093:            JTextField txtTableName = new JTextField();
094:            JTextField txtTableSchem = new JTextField();
095:            JTextField txtTableType = new JTextField();
096:
097:            Object[][] fields1 = { { txtDsName, "Data Source" },
098:                    { txtTableType, "Table Type" }
099:
100:            };
101:
102:            Object[][] fields2 = { { txtTableSchem, "Table Schema" },
103:                    { txtTableName, "Table Name" }
104:
105:            };
106:
107:            Object[][] fields = { fields1[0], fields1[1], fields2[0],
108:                    fields2[1] };
109:
110:            /**
111:             * This comparator is used to sort the ForeignKey objects displayed on
112:             * the Foreign Keys tab.
113:             */
114:            private final static MethodComparator FOREIGN_KEY_COMPARATOR = new MethodComparator(
115:                    ForeignKey.class,
116:                    "getForeignTableName",
117:                    false,
118:                    false,
119:                    new MethodComparator(ForeignKey.class, "getForeignKeyName"),
120:                    false);
121:
122:            /**
123:             * This comparator is used to sort the ForeignKey objects displayed
124:             * on the Exported Keys tab.
125:             */
126:            private final static MethodComparator EXPORTED_KEY_COMPARATOR = new MethodComparator(
127:                    ForeignKey.class,
128:                    "getLocalTableName",
129:                    false,
130:                    false,
131:                    new MethodComparator(ForeignKey.class, "getForeignKeyName"),
132:                    false);
133:
134:            public TableInfoPanel(TableInfo tableInfo, String dataSourceName)
135:                    throws NoSuchMethodException {
136:
137:                this .tableInfo = tableInfo;
138:
139:                setLayout(new BorderLayout());
140:
141:                JPanel headerPanel = new JPanel();
142:                JPanel leftHeader = new JPanel();
143:                JPanel rightHeader = new JPanel();
144:                Font font = new Font("SansSerif", Font.PLAIN, 9);
145:                GUIHelper.buildFormPanel(leftHeader, fields1, -1, 5, font,
146:                        Color.black, false, -2);
147:                GUIHelper.buildFormPanel(rightHeader, fields2, -1, 5, font,
148:                        Color.black, false, -2);
149:
150:                headerPanel.setLayout(new GridBagLayout());
151:                GridBagConstraints gc = new GridBagConstraints();
152:                gc.gridx = 0;
153:                gc.gridy = 0;
154:                gc.weightx = .5;
155:                gc.weighty = 0;
156:                gc.fill = gc.BOTH;
157:                gc.anchor = gc.CENTER;
158:                gc.insets = new Insets(0, 0, 0, 5);
159:                headerPanel.add(leftHeader, gc);
160:
161:                gc.gridx = 1;
162:                gc.insets = new Insets(0, 5, 0, 0);
163:                headerPanel.add(rightHeader, gc);
164:
165:                for (int j = 0; j < fields.length; j++) {
166:                    JTextField field = (JTextField) fields[j][0];
167:                    field.setFont(font);
168:                    field.setEditable(false);
169:                    field.setEnabled(false);
170:                    field.setDisabledTextColor(Color.black);
171:                }
172:
173:                txtDsName.setText(dataSourceName);
174:                txtTableSchem.setText(tableInfo.getTableSchem());
175:                txtTableName.setText(tableInfo.getTableName());
176:                txtTableType.setText(tableInfo.getTableType());
177:
178:                headerPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
179:                add(headerPanel, BorderLayout.NORTH);
180:
181:                add(tabbedPane, BorderLayout.CENTER);
182:
183:                ColumnManager cm = new ReflectionColumnManager(columnNames,
184:                        Column.class, getters, null);
185:
186:                Column[] columns = (Column[]) tableInfo.getColumns();
187:                if (columns != null)
188:                    columns = (Column[]) columns.clone();
189:
190:                columnTableModel = new ListTableModel(cm, Arrays
191:                        .asList(columns));
192:
193:                columnTable = new JTable(columnTableModel);
194:
195:                // make the table sortable
196:                PushButtonTableHeader columnTableHeader = new PushButtonTableHeader();
197:                columnTable.setTableHeader(columnTableHeader);
198:                columnTableHeader.addMouseListener(new ListTableModelSorter());
199:
200:                JPanel p = new JPanel();
201:                p.setLayout(new BorderLayout());
202:                p.add(new JScrollPane(columnTable), BorderLayout.CENTER);
203:
204:                tabbedPane.addTab("Columns", p);
205:
206:                // assemble the Foreign Keys tab.
207:
208:                ForeignKey[] fkeys = tableInfo.getForeignKeys();
209:                if (fkeys != null) {
210:
211:                    fkeys = (ForeignKey[]) fkeys.clone();
212:                    Arrays.sort(fkeys, FOREIGN_KEY_COMPARATOR);
213:
214:                    tabbedPane.addTab("Foreign Keys", fkeyPanel);
215:                    fkeyModel = new ListTableModel(
216:                            new ReflectionColumnManager(new String[] {
217:                                    "Foreign Table", "Foreign Key Name" },
218:                                    ForeignKey.class, new String[] {
219:                                            "getForeignTableName",
220:                                            "getForeignKeyName" }, null),
221:                            Arrays.asList(fkeys));
222:
223:                    fkeyPanel.setLayout(new BoxLayout(fkeyPanel,
224:                            BoxLayout.Y_AXIS));
225:
226:                    fkeysTable = new JTable(fkeyModel);
227:
228:                    // add a listener to the foreignTableList table that will cause each
229:                    // foreign table's key columns to be displayed in the fcolTable
230:                    // when the table selection changes.
231:                    fkeysTable.getSelectionModel().addListSelectionListener(
232:                            new ListSelectionListener() {
233:                                public void valueChanged(ListSelectionEvent e) {
234:                                    int row = fkeysTable.getSelectedRow();
235:                                    if (row > -1) {
236:                                        ForeignKey f = (ForeignKey) fkeyModel
237:                                                .getObjectAtRow(row);
238:                                        if (f != null) {
239:                                            fcolModel.setDataList(f
240:                                                    .getForeignKeyColumns());
241:                                        } else {
242:                                            System.out
243:                                                    .println("FOREIGN KEY OBJECT IS NULL AT ROW "
244:                                                            + row);
245:                                        }
246:                                    }
247:                                }
248:                            });
249:
250:                    if (fkeyModel.getRowCount() > 0)
251:                        fkeysTable.getSelectionModel().setSelectionInterval(0,
252:                                0);
253:
254:                    fkeysTable.getSelectionModel().setSelectionMode(
255:                            ListSelectionModel.SINGLE_SELECTION);
256:
257:                    // now assemble the visual components of the Foreign Key Fields
258:                    // tab.
259:                    JLabel lbl1 = new JLabel("Foreign Keys");
260:                    lbl1.setHorizontalAlignment(JLabel.LEFT);
261:                    lbl1.setBorder(new EmptyBorder(4, 5, 4, 0));
262:
263:                    JLabel lbl2 = new JLabel("Foreign Key Columns");
264:                    lbl2.setHorizontalAlignment(JLabel.LEFT);
265:                    lbl2.setBorder(new EmptyBorder(4, 5, 4, 0));
266:
267:                    fkeyPanel.setLayout(new GridBagLayout());
268:                    gc = new GridBagConstraints();
269:
270:                    gc.weightx = 1.0;
271:                    gc.gridx = 0;
272:                    gc.gridy = gc.RELATIVE;
273:                    gc.fill = gc.BOTH;
274:
275:                    gc.weighty = 0;
276:                    fkeyPanel.add(lbl1, gc);
277:
278:                    gc.weighty = .6;
279:                    fkeyPanel.add(new JScrollPane(fkeysTable), gc);
280:
281:                    gc.weighty = 0;
282:                    fkeyPanel.add(lbl2, gc);
283:
284:                    gc.weighty = .4;
285:                    fkeyPanel.add(new JScrollPane(fcolTable), gc);
286:                }
287:
288:                // assemble the Exported Keys tab.
289:
290:                ForeignKey[] exkeys = tableInfo.getExportedKeys();
291:                if (exkeys != null) {
292:
293:                    exkeys = (ForeignKey[]) exkeys.clone();
294:                    Arrays.sort(exkeys, EXPORTED_KEY_COMPARATOR);
295:
296:                    tabbedPane.addTab("Exported Keys", exkeyPanel);
297:                    exkeyModel = new ListTableModel(
298:                            new ReflectionColumnManager(new String[] {
299:                                    "Foreign Table", "Exported Key Name" },
300:                                    ForeignKey.class, new String[] {
301:                                            "getLocalTableName",
302:                                            "getForeignKeyName" }, null),
303:                            Arrays.asList(exkeys));
304:
305:                    exkeyPanel.setLayout(new BoxLayout(exkeyPanel,
306:                            BoxLayout.Y_AXIS));
307:
308:                    exkeysTable = new JTable(exkeyModel);
309:
310:                    // add a listener to the foreignTableList table that will cause each
311:                    // foreign table's key columns to be displayed in the excolTable
312:                    // when the table selection changes.
313:                    exkeysTable.getSelectionModel().addListSelectionListener(
314:                            new ListSelectionListener() {
315:                                public void valueChanged(ListSelectionEvent e) {
316:                                    int row = exkeysTable.getSelectedRow();
317:                                    if (row > -1) {
318:                                        ForeignKey f = (ForeignKey) exkeyModel
319:                                                .getObjectAtRow(row);
320:                                        if (f != null) {
321:                                            excolModel.setDataList(f
322:                                                    .getForeignKeyColumns());
323:                                        } else {
324:                                            System.out
325:                                                    .println("FOREIGN KEY OBJECT IS NULL AT ROW "
326:                                                            + row);
327:                                        }
328:                                    }
329:                                }
330:                            });
331:
332:                    if (exkeyModel.getRowCount() > 0)
333:                        exkeysTable.getSelectionModel().setSelectionInterval(0,
334:                                0);
335:
336:                    exkeysTable.getSelectionModel().setSelectionMode(
337:                            ListSelectionModel.SINGLE_SELECTION);
338:
339:                    // now assemble the visual components of the Foreign Key Fields
340:                    // tab.
341:                    JLabel lbl1 = new JLabel("Exported Keys");
342:                    lbl1.setHorizontalAlignment(JLabel.LEFT);
343:                    lbl1.setBorder(new EmptyBorder(4, 5, 4, 0));
344:
345:                    JLabel lbl2 = new JLabel("Exported Key Columns");
346:                    lbl2.setHorizontalAlignment(JLabel.LEFT);
347:                    lbl2.setBorder(new EmptyBorder(4, 5, 4, 0));
348:
349:                    exkeyPanel.setLayout(new GridBagLayout());
350:                    gc = new GridBagConstraints();
351:
352:                    gc.weightx = 1.0;
353:                    gc.gridx = 0;
354:                    gc.gridy = gc.RELATIVE;
355:                    gc.fill = gc.BOTH;
356:
357:                    gc.weighty = 0;
358:                    exkeyPanel.add(lbl1, gc);
359:
360:                    gc.weighty = .6;
361:                    exkeyPanel.add(new JScrollPane(exkeysTable), gc);
362:
363:                    gc.weighty = 0;
364:                    exkeyPanel.add(lbl2, gc);
365:
366:                    gc.weighty = .4;
367:                    exkeyPanel.add(new JScrollPane(excolTable), gc);
368:                }
369:
370:                tabbedPane.addTab("DDL", new DDLPanel(tableInfo));
371:
372:            }
373:
374:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.