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