Source Code Cross Referenced for PackageBrowse.java in  » Database-Client » PKLite-SQL-Client » com » pk » 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 » PKLite SQL Client » com.pk 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.pk;
002:
003:        import javax.swing.*;
004:        import javax.swing.event.*;
005:        import java.awt.*;
006:        import java.awt.event.*;
007:        import javax.swing.border.*;
008:        import javax.swing.tree.*;
009:        import javax.swing.table.*;
010:        import java.sql.*;
011:
012:        class PackageBrowse extends JFrame implements  ActionListener,
013:                TreeSelectionListener {
014:
015:            /**
016:             * 
017:             */
018:            private static final long serialVersionUID = 2959819232816106291L;
019:
020:            public PackageBrowse(MyInternalFrame mif, Connection connection,
021:                    String userID) {
022:                super ("Package Browser");
023:
024:                this .mif = mif;
025:                this .connection = connection;
026:                this .userID = userID;
027:
028:                setBounds(0, 0, 400, 400);
029:                setDefaultCloseOperation(DISPOSE_ON_CLOSE);
030:                addWindowListener(new WindowHandler());
031:
032:                status.setBorder(BorderFactory
033:                        .createBevelBorder(BevelBorder.LOWERED));
034:                getContentPane().add(status, BorderLayout.SOUTH);
035:
036:                // Create tree to go in left split pane
037:                dbNode = new DefaultMutableTreeNode("No database");
038:                dbTreeModel = new DefaultTreeModel(dbNode);
039:                dbTree = new JTree(dbTreeModel);
040:                treePane = new JScrollPane(dbTree);
041:                treePane.setBorder(BorderFactory
042:                        .createLineBorder(Color.darkGray));
043:
044:                table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
045:                table.setShowGrid(false);
046:                table.setFont(new Font("Default", Font.BOLD, 12));
047:                table
048:                        .setPreferredScrollableViewportSize(new Dimension(500,
049:                                70));
050:                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
051:                tablePane = new JScrollPane(table);
052:                tablePane.setBorder(BorderFactory
053:                        .createLineBorder(Color.darkGray));
054:
055:                JSplitPane splitpane = new JSplitPane(
056:                        JSplitPane.HORIZONTAL_SPLIT, true, // Continuous relayout
057:                        treePane, // Left pane content
058:                        tablePane); // Right pane content
059:                getContentPane().add(splitpane, BorderLayout.CENTER);
060:                splitpane.setDividerLocation(150); // Left pane 150 pixels wide
061:
062:                dbTree.addTreeSelectionListener(this );
063:
064:                pack();
065:
066:                setVisible(true); // Set window visible
067:                show(); // Display the window
068:
069:            }
070:
071:            private String userID = null;
072:
073:            private String url = null;
074:
075:            MyInternalFrame mif;
076:            Connection connection;
077:            Statement statement;
078:
079:            //	private String[] drivers = { // Oracle driver
080:            //		"sun.jdbc.odbc.JdbcOdbcDriver", // ODBC bridge
081:            //		"com.imaginary.sql.msql.MsqlDriver" // mSQL driver
082:            //	};
083:
084:            public void actionPerformed(ActionEvent e) {
085:                //		Object source = e.getSource(); // Get source of the event
086:            }
087:
088:            public void openConnection() {
089:                try {
090:                    status.setText("Database connection established");
091:
092:                    statement = connection.createStatement(); // Create statement for query
093:
094:                    dbNode = new DefaultMutableTreeNode(url); // Root node is URL
095:                    dbTreeModel.setRoot(dbNode); // Set root in model
096:                    setupTree(connection.getMetaData()); // Set up tree with metadata
097:
098:                    treePane.setBorder(BorderFactory.createTitledBorder(
099:                            BorderFactory.createLineBorder(Color.darkGray),
100:                            //url,
101:                            userID.toUpperCase(), TitledBorder.CENTER,
102:                            TitledBorder.DEFAULT_POSITION));
103:                    dbTree.setRootVisible(true); // Now show the root node
104:                    dbTreeModel.reload(); // Get the tree redisplayed
105:
106:                } catch (SQLException sqle) {
107:                    status.setText(sqle.getMessage()); // Display first message
108:                    do // loop through exceptions
109:                    {
110:                        System.err.println("Exception occurred:\nMessage: "
111:                                + sqle.getMessage());
112:                        System.err.println("SQL state: " + sqle.getSQLState());
113:                        System.err.println("Vendor code: "
114:                                + sqle.getErrorCode() + "\n----------------");
115:                    } while ((sqle = sqle.getNextException()) != null);
116:                }
117:            }
118:
119:            private void setupTree(DatabaseMetaData metadata)
120:                    throws SQLException {
121:                String[] tableTypes = { "PACKAGE" }; // We want only tables
122:
123:                String catalog = connection.getCatalog();
124:                ResultSet tables = metadata.getTables(// Get the tables info
125:                        catalog, userID.toUpperCase(), null, tableTypes);
126:
127:                String tableName; // Stores a table name
128:                DefaultMutableTreeNode tableNode; // Stores a tree node for a table
129:                while (tables.next()) // For each table
130:                {
131:                    //tableName = tables.getString("TABLE_NAME");     // get the table name
132:                    tableName = tables.getString(3); // get the table name
133:                    tableNode = new DefaultMutableTreeNode(tableName);
134:                    dbNode.add(tableNode); // Add the node to the tree
135:
136:                    // Get all the columns for the current table
137:                    //ResultSet columnNames = metadata.getColumns(null, null, tableName, null);
138:                    ResultSet columnNames = statement
139:                            .executeQuery("SELECT OBJECT_NAME FROM USER_OBJECTS "
140:                                    + "WHERE OBJECT_NAME = '"
141:                                    + tableName
142:                                    + "' "
143:                                    + "AND  OBJECT_TYPE = 'PACKAGE BODY'");
144:
145:                    //System.out.println("User ID is "+userID+"\n");
146:
147:                    // Add nodes for the columns as children of the table node
148:                    while (columnNames.next())
149:                        tableNode.add(new DefaultMutableTreeNode(columnNames
150:                                .getString("OBJECT_NAME")));
151:
152:                }
153:            }
154:
155:            public void valueChanged(TreeSelectionEvent e) {
156:                TreePath[] paths = dbTree.getSelectionPaths();
157:                if (paths == null)
158:                    return;
159:
160:                boolean tableSelected = false; // Set true if a table is selected
161:                String column; // Stores a column name from a path
162:                String tableName; // Stores a table name from a path
163:                String columnsParam = null; // Column names in SQL SELECT
164:                String tableParam = null; // Table name in SQL SELECT
165:                String message = null; // Message for status area
166:                for (int j = 0; j < paths.length; j++) {
167:                    switch (paths[j].getPathCount()) {
168:                    case 2: // We have a table selected
169:                        tableParam = (String) (((DefaultMutableTreeNode) (paths[j]
170:                                .getPathComponent(1))).getUserObject());
171:                        columnsParam = "*"; // Select all columns
172:                        tableSelected = true; // Set flag for a table selected
173:                        message = "Complete " + tableParam
174:                                + " package displayed";
175:                        break;
176:
177:                    case 3: // Column selected
178:                        tableName = (String) (((DefaultMutableTreeNode) (paths[j]
179:                                .getPathComponent(1))).getUserObject());
180:                        if (tableParam == null)
181:                            tableParam = tableName;
182:
183:                        else if (tableParam != tableName)
184:                            break;
185:                        column = (String) (((DefaultMutableTreeNode) (paths[j]
186:                                .getPathComponent(2))).getUserObject());
187:                        if (columnsParam == null) // If no previous columns
188:                            columnsParam = column; // add the column
189:                        else
190:                            // otherwise
191:                            columnsParam += "," + column; // we need a comma too
192:                        message = columnsParam + " displayed from "
193:                                + tableParam + " package.";
194:                        break;
195:                    }
196:                    if (tableSelected) // If a table was selected
197:                        break; // we are done
198:                }
199:                try {
200:                    // Display the columns and change the scroll pane border
201:                    if (tableSelected) {
202:
203:                        tableModel.setResultSet(statement.executeQuery(mif
204:                                .getConnectionInformation()
205:                                .getDatabaseDialect().getPackageInfoSQLString(
206:                                        tableParam,
207:                                        mif.getConnectionInformation())));
208:                        DefaultTableColumnModel tcm = (DefaultTableColumnModel) table
209:                                .getColumnModel();
210:                        TableColumn tc = tcm.getColumn(0);
211:                        tc.setWidth(400);
212:                        tc.setResizable(true);
213:                    } else {
214:                        tableModel
215:                                .setResultSet(statement
216:                                        .executeQuery("SELECT DECODE(UPPER(TRIM(TEXT)),'END;',TEXT,SUBSTR(TEXT,1,LENGTH(TEXT)-1)) AS \"PACKAGE BODY SOURCE\" FROM USER_SOURCE "
217:                                                + "WHERE TYPE='PACKAGE BODY' "
218:                                                + "AND   NAME='"
219:                                                + tableParam
220:                                                + "'" + "ORDER BY LINE"));
221:                        DefaultTableColumnModel tcm = (DefaultTableColumnModel) table
222:                                .getColumnModel();
223:                        TableColumn tc = tcm.getColumn(0);
224:                        tc.setWidth(400);
225:                        tc.setResizable(true);
226:                    }
227:
228:                    tablePane.setBorder(BorderFactory.createTitledBorder(
229:                            BorderFactory.createLineBorder(Color.darkGray),
230:                            tableParam, TitledBorder.CENTER,
231:                            TitledBorder.DEFAULT_POSITION));
232:                } catch (SQLException sqle) {
233:                    message = "Selection event Error\n" + sqle.getMessage();
234:                    System.err.println(message);
235:                }
236:                if (message != null)
237:                    status.setText(message);
238:            }
239:
240:            // Inner class defining handler for window events
241:            class WindowHandler extends WindowAdapter {
242:                public void windowOpened(WindowEvent e) {
243:                    openConnection();
244:                }
245:
246:                // Handler for window closing event
247:                public void windowClosing(WindowEvent e) {
248:                    mif.packageBrowseFlag = 0;
249:                }
250:            }
251:
252:            JTextArea status = new JTextArea(3, 30);
253:
254:            DefaultMutableTreeNode dbNode; // Root node for the database tree
255:            DefaultTreeModel dbTreeModel; // Model for the database metadata
256:            JTree dbTree; // Tree to display the metadata
257:            JScrollPane treePane; // Scroll pane holding the tree
258:
259:            JScrollPane tablePane; // Scroll pane holding the table
260:            ResultsModel tableModel = new ResultsModel();
261:            JTable table = new JTable(tableModel);
262:
263:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.