Source Code Cross Referenced for ScriptTablePanel.java in  » Database-Client » JSqlTool » org » jsqltool » gui » tableplugins » 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 » JSqlTool » org.jsqltool.gui.tableplugins 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.jsqltool.gui.tableplugins;
002:
003:        import javax.swing.*;
004:        import java.awt.*;
005:        import javax.swing.event.*;
006:        import javax.swing.table.*;
007:        import java.awt.event.*;
008:        import org.jsqltool.conn.DbConnectionUtil;
009:        import org.jsqltool.model.CustomTableModel;
010:        import java.sql.*;
011:        import java.util.*;
012:        import org.jsqltool.gui.*;
013:        import org.jsqltool.*;
014:        import org.jsqltool.gui.tablepanel.*;
015:        import org.jsqltool.gui.panel.*;
016:        import org.jsqltool.gui.graphics.SQLTextArea;
017:        import org.jsqltool.utils.Options;
018:
019:        /**
020:         * <p>Title: JSqlTool Project</p>
021:         * <p>Description: Panel that shows table SQL scripts.
022:         * </p>
023:         * <p>Copyright: Copyright (C) 2006 Mauro Carniel</p>
024:         *
025:         * <p> This file is part of JSqlTool project.
026:         * This library is free software; you can redistribute it and/or
027:         * modify it under the terms of the (LGPL) Lesser General Public
028:         * License as published by the Free Software Foundation;
029:         *
030:         *                GNU LESSER GENERAL PUBLIC LICENSE
031:         *                 Version 2.1, February 1999
032:         *
033:         * This library is distributed in the hope that it will be useful,
034:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
035:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
036:         * Library General Public License for more details.
037:         *
038:         * You should have received a copy of the GNU Library General Public
039:         * License along with this library; if not, write to the Free
040:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
041:         *
042:         *       The author may be contacted at:
043:         *           maurocarniel@tin.it</p>
044:         *
045:         * @author Mauro Carniel
046:         * @version 1.0
047:         */
048:        public class ScriptTablePanel extends JPanel implements  TablePlugin {
049:
050:            private String tableName = null;
051:            private SQLTextArea sql = new SQLTextArea();
052:            BorderLayout borderLayout1 = new BorderLayout();
053:            private DbConnectionUtil dbConnUtil = null;
054:            private JFrame parent = null;
055:            GridBagLayout gridBagLayout1 = new GridBagLayout();
056:
057:            public ScriptTablePanel() {
058:                try {
059:                    jbInit();
060:                } catch (Exception e) {
061:                    e.printStackTrace();
062:                }
063:            }
064:
065:            private void jbInit() throws Exception {
066:                this .setLayout(gridBagLayout1);
067:                this .add(sql, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
068:                        GridBagConstraints.WEST, GridBagConstraints.BOTH,
069:                        new Insets(5, 5, 0, 0), 0, 0));
070:                sql.setEditable(false);
071:            }
072:
073:            public final void resetPanel() {
074:                sql.setText("");
075:            }
076:
077:            /**
078:             * @return panel position inside the JTabbedPane related to the table detail
079:             */
080:            public int getTabbedPosition() {
081:                return 4;
082:            }
083:
084:            /**
085:             * @return folder name of the plugin panel, inside the JTabbedPane related to the table detail
086:             */
087:            public String getTabbedName() {
088:                return Options.getInstance().getResource("script");
089:            }
090:
091:            /**
092:             * This method is called from the table detail to inizialize the plugin panel
093:             */
094:            public void initPanel(MainFrame parent, DbConnectionUtil dbConnUtil) {
095:                this .parent = parent;
096:                this .dbConnUtil = dbConnUtil;
097:            }
098:
099:            /**
100:             * This method is called from the table detail to update the plugin panel content.
101:             * @param tableName table name (edventualy including catalog name) that table plugin have to show
102:             */
103:            public final void updateContent() {
104:                this .tableName = tableName;
105:                if (tableName == null || tableName.equals("")) {
106:                    sql.setText("");
107:                } else {
108:                    try {
109:                        TableModel cols = dbConnUtil.getTableColumns(tableName);
110:                        String t = tableName;
111:                        if (t.indexOf(".") != -1)
112:                            t = t.substring(t.indexOf(".") + 1);
113:                        String text = "CREATE TABLE " + t + "\n(\n";
114:                        int namelen = 0;
115:                        int len = 0;
116:                        Hashtable pk = new Hashtable();
117:                        for (int i = 0; i < cols.getRowCount(); i++) {
118:                            len = cols.getValueAt(i, 0).toString().length();
119:                            if (len > namelen) {
120:                                namelen = len;
121:                            }
122:                            if (cols.getValueAt(i, 2) != null) {
123:                                pk.put(cols.getValueAt(i, 2), cols.getValueAt(
124:                                        i, 0));
125:                            }
126:                        }
127:                        for (int i = 0; i < cols.getRowCount(); i++) {
128:                            text += "  "
129:                                    + rpad(cols.getValueAt(i, 0).toString(),
130:                                            namelen + 1)
131:                                    + cols.getValueAt(i, 1) + " ";
132:                            text += (cols.getValueAt(i, 4) != null ? "DEFAULT "
133:                                    + cols.getValueAt(i, 4) + " " : "");
134:                            text += (((Boolean) cols.getValueAt(i, 3))
135:                                    .booleanValue() ? "" : "NOT NULL");
136:                            text += ",\n";
137:                        }
138:                        if (pk.size() > 0) {
139:                            text += "  PRIMARY KEY(";
140:                            for (int i = 0; i < pk.size(); i++)
141:                                text += pk.get(new Integer(i + 1)) + ",";
142:                            text = text.substring(0, text.length() - 1);
143:                            text += ")\n";
144:                        } else
145:                            text = text.substring(0, text.length() - 2) + "\n";
146:                        text += ");\n\n";
147:
148:                        // indexes...
149:                        TableModel model = dbConnUtil
150:                                .getTableIndexes(tableName);
151:                        String indexName = null;
152:                        boolean unique = false;
153:                        for (int i = 0; i < model.getRowCount(); i++) {
154:                            if (model.getValueAt(i, 5) == null)
155:                                continue;
156:                            unique = false;
157:                            if (model.getValueAt(i, 3).getClass().equals(
158:                                    String.class))
159:                                unique = model.getValueAt(i, 3).toString()
160:                                        .equals("0");
161:                            else if (model.getValueAt(i, 3) instanceof  Number)
162:                                unique = ((Number) model.getValueAt(i, 3))
163:                                        .intValue() == 0;
164:
165:                            if (model.getValueAt(i, 5).equals(indexName)) {
166:                                text += model.getValueAt(i, 8) + ",";
167:                                continue;
168:                            } else {
169:                                if (indexName != null) {
170:                                    text = text.substring(0, text.length() - 1);
171:                                    text += ");\n\n";
172:                                }
173:                                indexName = model.getValueAt(i, 5).toString();
174:                            }
175:                            text += "CREATE ";
176:                            if (unique)
177:                                text += "UNIQUE ";
178:                            text += "INDEX " + model.getValueAt(i, 5) + " ON "
179:                                    + t + " (";
180:                            text += model.getValueAt(i, 8) + ",";
181:                        }
182:                        if (indexName != null) {
183:                            text = text.substring(0, text.length() - 1);
184:                            text += ");\n\n";
185:                        }
186:
187:                        // fk...
188:                        model = dbConnUtil.getCrossReference(tableName);
189:                        String fkName = null;
190:                        String pkList = "";
191:                        String pkTable = null;
192:                        for (int i = 0; i < model.getRowCount(); i++) {
193:                            if (model.getValueAt(i, 11) == null)
194:                                continue;
195:
196:                            if (model.getValueAt(i, 11).equals(fkName)) {
197:                                text += model.getValueAt(i, 7) + ",";
198:                                pkList += model.getValueAt(i, 3) + ",";
199:                                continue;
200:                            } else {
201:                                if (fkName != null) {
202:                                    text = text.substring(0, text.length() - 1);
203:                                    text += ")\n";
204:                                    text += "  REFERENCES " + pkTable + "\n  (";
205:                                    pkList = pkList.substring(0, pkList
206:                                            .length() - 1);
207:                                    text += pkList + ")\n);\n\n";
208:                                }
209:                                fkName = model.getValueAt(i, 11).toString();
210:                            }
211:                            text += "ALTER TABLE " + t + " ADD CONSTRAINT "
212:                                    + fkName + " FOREIGN KEY \n  (";
213:                            text += model.getValueAt(i, 7) + ",";
214:                            pkList = model.getValueAt(i, 3) + ",";
215:                            pkTable = model.getValueAt(i, 2).toString();
216:                        }
217:                        if (fkName != null) {
218:                            text = text.substring(0, text.length() - 1);
219:                            text += ")\n";
220:                            text += "  REFERENCES " + pkTable + "\n  (";
221:                            pkList = pkList.substring(0, pkList.length() - 1);
222:                            text += pkList + ")\n);\n\n";
223:                        }
224:
225:                        sql.setText(text);
226:                    } catch (Exception ex) {
227:                        ex.printStackTrace();
228:                    }
229:
230:                }
231:            }
232:
233:            /**
234:             * This method is called from the table detail to set entity name.
235:             * @param tableName table name (edventualy including catalog name) that table plugin have to show
236:             */
237:            public final void setTableName(String tableName) {
238:                this .tableName = tableName;
239:            }
240:
241:            /**
242:             * @return entity name
243:             */
244:            public String getTableName() {
245:                return tableName;
246:            }
247:
248:            private String rpad(String text, int len) {
249:                for (int i = text.length(); i < len; i++)
250:                    text += " ";
251:                return text;
252:            }
253:
254:            /**
255:             * @return infos about the author of the plugin panel; "" or null does not report any info about the plugin panel
256:             */
257:            public String getAuthor() {
258:                return "";
259:            }
260:
261:            /**
262:             * @return plugin panel version
263:             */
264:            public String getVersion() {
265:                return "1.0";
266:            }
267:
268:            /**
269:             * @return plugin panel name, reported into the about window
270:             */
271:            public String getName() {
272:                return Options.getInstance().getResource("script plugin");
273:            }
274:
275:            public boolean equals(Object o) {
276:                return (o instanceof  TablePlugin && ((TablePlugin) o).getName()
277:                        .equals(getName()));
278:            }
279:
280:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.