Source Code Cross Referenced for PrettyKid.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) 


0001:        package com.pk;
0002:
0003:        import java.awt.*;
0004:        import java.awt.event.*; // For event classes
0005:        import java.beans.PropertyVetoException;
0006:
0007:        import javax.swing.*; // For Swing components
0008:        //import javax.swing.table.*;              // For the table classes
0009:        import javax.swing.text.*;
0010:
0011:        import com.pk.script.ui.ScriptPanel;
0012:
0013:        //import javax.swing.JInternalFrame;
0014:        import java.sql.*; // For JDBC classes
0015:        import java.util.HashSet;
0016:        import java.util.Hashtable;
0017:        import java.util.Properties;
0018:        import java.util.Vector;
0019:        import java.io.*;
0020:
0021:        public class PrettyKid extends JFrame implements  ActionListener,
0022:                Constants {
0023:            /**
0024:             * 
0025:             */
0026:            private static final long serialVersionUID = 1L;
0027:            private JDialog preferencesJDialog = null;
0028:            private Config config = null;
0029:            private ScriptPanel scriptPanel = null;
0030:            JDesktopPane desktop;
0031:            Vector myInternalFrameList = null;
0032:            Hashtable connectionList = null;
0033:            Preferences propertiyFrame = null;
0034:
0035:            MyInternalFrame frame;
0036:            MyInternalFrame ji;
0037:
0038:            String user;
0039:            String password;
0040:            String url;
0041:            String driver;
0042:
0043:            JMenu windowMenu = null;
0044:            JMenuBar menuBar = null; // The menu bar
0045:            JMenuItem nextWindowItem = null;
0046:            JMenuItem newConItem = null;
0047:            JMenuItem newWinItem = null;
0048:            JMenuItem saveItem = null;
0049:            JMenuItem exortXMLItem = null;
0050:            JMenuItem exortHTMLItem = null;
0051:            JMenuItem saveSQLItem = null;
0052:            JMenuItem loadSQLItem = null;
0053:            JMenuItem printItem = null;
0054:            JMenuItem clearQueryItem = null;// Clear SQL item
0055:            JMenuItem executeItem = null;
0056:            JMenuItem historyItem = null;
0057:            JMenuItem exitItem = null;// Exit item
0058:            JMenuItem cutItem = null;// Cut item
0059:            JMenuItem copyItem = null;// Copy item
0060:            JMenuItem pasteItem = null;// Paste item
0061:            JMenuItem previousSQLItem = null;// Previous SQL statements item
0062:            JMenuItem commitItem = null;
0063:            JMenuItem rollBackItem = null;
0064:            JMenuItem objectTableItem = null; // Object Table item
0065:            JMenuItem objectIndexItem = null; // Object Index item
0066:            JMenuItem objectProcedureItem = null;
0067:            JMenuItem objectPackageItem = null;
0068:            JMenuItem planItem = null;
0069:            JMenuItem aboutpklItem = null; // About item
0070:            JMenuItem preferencesItem = null;
0071:            JMenuItem scriptRunnerItem = null;
0072:            JMenuItem undoItem = null;
0073:            JMenuItem redoItem = null;
0074:
0075:            Properties pkLiteProperties = null;
0076:
0077:            int isSgaFrameOpened = 0;
0078:
0079:            public PrettyKid() {
0080:
0081:                super ("PKLite SQL Client"); // Call base constructor
0082:
0083:                HashSet tmpHashSet = new HashSet();
0084:                tmpHashSet.add(AWTKeyStroke.getAWTKeyStroke("TAB"));
0085:                KeyboardFocusManager.getCurrentKeyboardFocusManager()
0086:                        .setDefaultFocusTraversalKeys(
0087:                                KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
0088:                                tmpHashSet);
0089:                //this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,tmpHashSet);
0090:
0091:                myInternalFrameList = new Vector();
0092:                connectionList = new Hashtable();
0093:                try {
0094:
0095:                    //This code will load and create the new config object from a xml file
0096:                    ConfigDigester tmpConfigDigester = new ConfigDigester();
0097:                    tmpConfigDigester.setFileName("config.xml");
0098:                    config = tmpConfigDigester.createConfig();
0099:                    UIManager.setLookAndFeel(config.getSelectedLookAndFeel());
0100:                    SwingUtilities.updateComponentTreeUI(this );
0101:                    getpropertiyFrame().setConfig(config);
0102:                    getpropertiyFrame().initialize();
0103:
0104:                    java.util.List tmp = config.getConnections();
0105:                    String driveName = null;
0106:                    int size = tmp.size();
0107:                    for (int x = 0; x < size; x++) {
0108:                        driveName = ((ConnectionConfig) tmp.get(x)).getDriver();
0109:                        try {
0110:                            Class.forName(driveName);
0111:                        } catch (ClassNotFoundException e) {
0112:                            JOptionPane.showMessageDialog(this ,
0113:                                    "Could not find class for driver: "
0114:                                            + driveName);
0115:                        }
0116:                    }
0117:
0118:                } catch (Exception e) {
0119:                    e.printStackTrace();
0120:                    try {
0121:                        UIManager.setLookAndFeel(UIManager
0122:                                .getSystemLookAndFeelClassName());
0123:                    } catch (Exception e1) {
0124:                    }
0125:                }
0126:                setBounds(50, 0, 100, 100); // Set window bounds
0127:                menuBar = new JMenuBar(); // The menu bar
0128:                newConItem = new JMenuItem("New Connection");
0129:                newWinItem = new JMenuItem("New Window");
0130:                saveItem = new JMenuItem("as Delimited File...");
0131:                exortXMLItem = new JMenuItem("as XML...");
0132:                exortHTMLItem = new JMenuItem("as HTML...");
0133:                saveSQLItem = new JMenuItem("Save SQL...");
0134:                loadSQLItem = new JMenuItem("Load SQL...");
0135:                printItem = new JMenuItem("Print...");
0136:                clearQueryItem = new JMenuItem("Clear query"); // Clear SQL item
0137:                executeItem = new JMenuItem("Execute");
0138:                historyItem = new JMenuItem("History");
0139:                exitItem = new JMenuItem("Exit"); // Exit item
0140:                cutItem = new JMenuItem("Cut"); // Cut item
0141:                copyItem = new JMenuItem("Copy"); // Copy item
0142:                pasteItem = new JMenuItem("Paste"); // Paste item
0143:                previousSQLItem = new JMenuItem("Previous SQL"); // Previous SQL statements item
0144:                commitItem = new JMenuItem("Commit");
0145:                rollBackItem = new JMenuItem("RollBack");
0146:                objectTableItem = new JMenuItem("Table"); // Object Table item
0147:                objectIndexItem = new JMenuItem("Index"); // Object Index item
0148:                objectProcedureItem = new JMenuItem("Procedure");
0149:                objectPackageItem = new JMenuItem("Package");
0150:                preferencesItem = new JMenuItem("Preferences");
0151:                scriptRunnerItem = new JMenuItem("Run Script");
0152:                undoItem = new JMenuItem("Undo");
0153:                redoItem = new JMenuItem("Redo");
0154:
0155:                planItem = new JMenuItem("Explain plan");
0156:                aboutpklItem = new JMenuItem("About PKLite"); // About item
0157:
0158:                planItem = new JMenuItem("Explain plan");
0159:                nextWindowItem = new JMenuItem("Next Window");
0160:                int inset = 50;
0161:                Dimension screenSize = Toolkit.getDefaultToolkit()
0162:                        .getScreenSize();
0163:                setBounds(inset, inset, screenSize.width - inset * 2,
0164:                        screenSize.height - inset * 2);
0165:
0166:                addWindowListener(new WindowHandler()); // Listener for window close
0167:
0168:                JPanel overAllPanel = new JPanel();
0169:                overAllPanel.setLayout(new BorderLayout());
0170:                overAllPanel.setPreferredSize(new java.awt.Dimension(
0171:                        screenSize.width - inset * 4, screenSize.height - inset
0172:                                * 4));
0173:                setContentPane(overAllPanel);
0174:                desktop = new JDesktopPane(); //a specialized layered pane
0175:                overAllPanel.add(desktop, BorderLayout.CENTER);
0176:                setJMenuBar(createMenuBar());
0177:
0178:                JToolBar toolBar = new JToolBar();
0179:
0180:                addButtons(toolBar);
0181:                overAllPanel.add(toolBar, BorderLayout.NORTH);
0182:
0183:                desktop.putClientProperty("JDesktopPane.dragMode", "outline");
0184:
0185:                pack();
0186:
0187:                setVisible(true);
0188:
0189:                createFrame(); //Create first window
0190:
0191:            }
0192:
0193:            protected JMenuBar createMenuBar() {
0194:                // Create the menubar from the menu items
0195:
0196:                JMenu fileMenu = new JMenu("File"); // Create File menu
0197:                fileMenu.setMnemonic('F'); // Create shortcut
0198:                JMenu editMenu = new JMenu("Edit"); // Create Edit menu
0199:                editMenu.setMnemonic('E'); // Create shortcut
0200:                JMenu objectMenu = new JMenu("Schema"); // Create Monitor menu
0201:                objectMenu.setMnemonic('S'); // Create shortcut
0202:
0203:                JMenu windowMenu = new JMenu("Window");
0204:                windowMenu.setMnemonic('W');
0205:                JMenu helpMenu = new JMenu("Help"); // Create Help menu
0206:                helpMenu.setMnemonic('H'); // Create shortcut 
0207:
0208:                printItem.addActionListener(this );
0209:                newConItem.addActionListener(this ); // Add Item Listener from HERE!!!
0210:                newWinItem.addActionListener(this );
0211:                saveItem.addActionListener(this );
0212:                exortXMLItem.addActionListener(this );
0213:                exortHTMLItem.addActionListener(this );
0214:                saveSQLItem.addActionListener(this );
0215:                loadSQLItem.addActionListener(this );
0216:                clearQueryItem.addActionListener(this );
0217:                executeItem.addActionListener(this );
0218:                historyItem.addActionListener(this );
0219:                exitItem.addActionListener(this );
0220:                cutItem.addActionListener(this );
0221:                copyItem.addActionListener(this );
0222:                pasteItem.addActionListener(this );
0223:                previousSQLItem.addActionListener(this );
0224:                commitItem.addActionListener(this );
0225:                rollBackItem.addActionListener(this );
0226:                objectTableItem.addActionListener(this );
0227:                objectIndexItem.addActionListener(this );
0228:                objectProcedureItem.addActionListener(this );
0229:                objectPackageItem.addActionListener(this );
0230:                preferencesItem.addActionListener(this );
0231:                scriptRunnerItem.addActionListener(this );
0232:                undoItem.addActionListener(this );
0233:                redoItem.addActionListener(this );
0234:                nextWindowItem.addActionListener(this );
0235:                nextWindowItem.setAccelerator(KeyStroke.getKeyStroke('G',
0236:                        Event.CTRL_MASK));
0237:                //nextWindowItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_TAB, java.awt.Event.CTRL_MASK, false));
0238:
0239:                planItem.addActionListener(this );
0240:                aboutpklItem.addActionListener(this );
0241:
0242:                newConItem.setAccelerator(KeyStroke.getKeyStroke('N',
0243:                        Event.CTRL_MASK));
0244:                newWinItem.setAccelerator(KeyStroke.getKeyStroke('W',
0245:                        Event.CTRL_MASK));
0246:                saveItem.setAccelerator(KeyStroke.getKeyStroke('S',
0247:                        Event.CTRL_MASK));
0248:                clearQueryItem.setAccelerator(KeyStroke.getKeyStroke('D',
0249:                        Event.CTRL_MASK));
0250:                executeItem.setAccelerator(KeyStroke.getKeyStroke('R',
0251:                        Event.CTRL_MASK));
0252:                historyItem.setAccelerator(KeyStroke.getKeyStroke('I',
0253:                        Event.CTRL_MASK));
0254:                cutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
0255:                        ActionEvent.CTRL_MASK));
0256:                cutItem.getAccessibleContext().setAccessibleDescription("Cut");
0257:                cutItem.setAction(new DefaultEditorKit.CutAction());
0258:                cutItem.setText("Cut"); // need to do this because setAction () changes the message 
0259:                copyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
0260:                        ActionEvent.CTRL_MASK));
0261:                copyItem.getAccessibleContext()
0262:                        .setAccessibleDescription("Copy");
0263:                copyItem.setAction(new DefaultEditorKit.CopyAction());
0264:                copyItem.setText("Copy");
0265:                pasteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,
0266:                        ActionEvent.CTRL_MASK));
0267:                pasteItem.getAccessibleContext().setAccessibleDescription(
0268:                        "Paste");
0269:                pasteItem.setAction(new DefaultEditorKit.PasteAction());
0270:                pasteItem.setText("Paste");
0271:                previousSQLItem.setAccelerator(KeyStroke.getKeyStroke('P',
0272:                        Event.CTRL_MASK));
0273:                planItem.setAccelerator(KeyStroke.getKeyStroke('E',
0274:                        Event.CTRL_MASK));
0275:
0276:                JMenu tuningMenu = new JMenu("Tuning");
0277:                tuningMenu.setMnemonic('T');
0278:                fileMenu.add(newConItem); // Add file menu Item from HERE!!!
0279:                fileMenu.add(newWinItem);
0280:                fileMenu.add(executeItem);
0281:                fileMenu.add(printItem);
0282:                fileMenu.addSeparator();
0283:                JMenu exportMenu = new JMenu("Export Results...");
0284:                exportMenu.add(saveItem);
0285:                exportMenu.add(exortXMLItem);
0286:                exportMenu.add(exortHTMLItem);
0287:                fileMenu.add(exportMenu);
0288:                //		fileMenu.add(saveItem);
0289:                //		fileMenu.add(exortXMLItem);
0290:                //		fileMenu.add(exortHTMLItem);
0291:                fileMenu.add(saveSQLItem);
0292:                fileMenu.add(loadSQLItem);
0293:                //fileMenu.add(clearQueryItem);  // to edit menu 
0294:
0295:                fileMenu.add(exitItem);
0296:                editMenu.add(cutItem);
0297:                editMenu.add(copyItem);
0298:                editMenu.add(pasteItem);
0299:                editMenu.add(undoItem);
0300:                editMenu.add(redoItem);
0301:                editMenu.addSeparator(); // Add separator 
0302:                editMenu.add(clearQueryItem);
0303:                editMenu.add(previousSQLItem);
0304:                editMenu.add(historyItem);
0305:                editMenu.addSeparator();
0306:                editMenu.add(commitItem);
0307:                editMenu.add(rollBackItem);
0308:                objectMenu.add(objectTableItem); // Add object menu Item from HERE!!!  
0309:                objectMenu.add(objectIndexItem);
0310:                objectMenu.add(objectProcedureItem);
0311:                objectMenu.add(objectPackageItem);
0312:
0313:                tuningMenu.add(planItem);
0314:                helpMenu.add(aboutpklItem); // Add help menu Item from HERE!!!
0315:
0316:                windowMenu.addSeparator();
0317:                windowMenu.add(nextWindowItem);
0318:                windowMenu.addSeparator();
0319:                windowMenu.add(scriptRunnerItem);
0320:                windowMenu.add(preferencesItem);
0321:                menuBar.add(fileMenu); // Add menu to the menubar
0322:                menuBar.add(editMenu);
0323:                menuBar.add(objectMenu);
0324:                menuBar.add(tuningMenu);
0325:                menuBar.add(windowMenu);
0326:                menuBar.add(helpMenu);
0327:
0328:                return menuBar;
0329:
0330:            }
0331:
0332:            public void createFrame() {
0333:                frame = new MyInternalFrame(this );
0334:                desktop.add(frame);
0335:            }
0336:
0337:            public void createMyNewWindow() {
0338:                MyInternalFrame tmpMyInternalFrame = getSelectedMyFrame();
0339:                frame = new MyInternalFrame(this ,
0340:                        tmpMyInternalFrame.connection,
0341:                        tmpMyInternalFrame.userid, tmpMyInternalFrame
0342:                                .getConnectionName());
0343:                String tmpConncetionKey = tmpMyInternalFrame.getConncetionKey();
0344:                frame.setConncetionKey(tmpConncetionKey);
0345:                ConnectionInformation tmpConnectionInformation = (ConnectionInformation) connectionList
0346:                        .get(tmpConncetionKey);
0347:                tmpConnectionInformation
0348:                        .setNumberOfWindows(tmpConnectionInformation
0349:                                .getNumberOfWindows() + 1);
0350:                frame.setKeywords(tmpConnectionInformation.getDatabaseDialect()
0351:                        .getKeywords());
0352:                connectionList.put(tmpConncetionKey, tmpConnectionInformation);
0353:                desktop.add(frame);
0354:
0355:                try {
0356:                    frame.setSelected(true);
0357:
0358:                } catch (java.beans.PropertyVetoException e) {
0359:                }
0360:                createWindowMenu();
0361:            }
0362:
0363:            public MyInternalFrame getSelectedMyFrame() {
0364:                if (desktop.getSelectedFrame() != null
0365:                        && desktop.getSelectedFrame() instanceof  MyInternalFrame)
0366:                    return (MyInternalFrame) desktop.getSelectedFrame();
0367:                else
0368:                    JOptionPane
0369:                            .showMessageDialog(this ,
0370:                                    "Please activate and select the window you want to handle...");
0371:                return null;
0372:            }
0373:
0374:            public void actionPerformed(ActionEvent e) {
0375:                Object source = e.getSource();
0376:
0377:                if (source instanceof  WindowJMenuItem) {
0378:                    WindowJMenuItem tmpWindowJMenuItem = (WindowJMenuItem) source;
0379:                    MyInternalFrame tmp = null;
0380:                    try {
0381:                        tmp = (MyInternalFrame) myInternalFrameList
0382:                                .get(tmpWindowJMenuItem.getWindowIndex());
0383:                        desktop.getSelectedFrame().setSelected(false);
0384:                        desktop.setSelectedFrame(tmp);
0385:
0386:                        tmp.setSelected(true);
0387:                    } catch (PropertyVetoException e1) {
0388:                        e1.printStackTrace();
0389:                    }
0390:                } else if (source == nextWindowItem) {
0391:                    //TODO code next window
0392:                    nextWindow();
0393:                } else if (source == newConItem) {
0394:                    createFrame();
0395:                }
0396:
0397:                else if (source == newWinItem) {
0398:                    createMyNewWindow();
0399:                }
0400:
0401:                else if (source == saveItem) {
0402:                    try {
0403:                        doSaveCommand();
0404:                    } catch (IOException ioe) {
0405:                        JOptionPane.showMessageDialog(this , " " + ioe,
0406:                                "Territory Reporter",
0407:                                JOptionPane.WARNING_MESSAGE);
0408:                    }
0409:
0410:                } else if (source == exortXMLItem) {
0411:                    try {
0412:                        doExportXMLCommand();
0413:                    } catch (IOException ioe) {
0414:                        JOptionPane.showMessageDialog(this , " " + ioe,
0415:                                "Territory Reporter",
0416:                                JOptionPane.WARNING_MESSAGE);
0417:                    }
0418:
0419:                } else if (source == exortHTMLItem) {
0420:                    try {
0421:                        doExportHTMLCommand();
0422:                    } catch (IOException ioe) {
0423:                        JOptionPane.showMessageDialog(this , " " + ioe,
0424:                                "Territory Reporter",
0425:                                JOptionPane.WARNING_MESSAGE);
0426:                    }
0427:
0428:                } else if (source == loadSQLItem) {
0429:                    try {
0430:                        doLoadSQL();
0431:                    } catch (IOException ioe) {
0432:                        JOptionPane.showMessageDialog(this , " " + ioe,
0433:                                "Territory Reporter",
0434:                                JOptionPane.WARNING_MESSAGE);
0435:                    }
0436:
0437:                } else if (source == printItem) {
0438:                    try {
0439:                        doPrintCommand();
0440:                    } catch (Exception ex) {
0441:                        ex.printStackTrace();
0442:                    }
0443:                }
0444:
0445:                else if (source == clearQueryItem) // Clear query menu item
0446:                {
0447:
0448:                    getSelectedMyFrame().setSqlTextArea(""); // Clear SQL entry 
0449:                } else if (source == undoItem) // Clear query menu item
0450:                {
0451:
0452:                    getSelectedMyFrame().undoLastEdit();
0453:                } else if (source == redoItem) // Clear query menu item
0454:                {
0455:
0456:                    getSelectedMyFrame().redoLastEdit();
0457:                }
0458:
0459:                else if (source == executeItem) {
0460:                    getSelectedMyFrame().prexecuteSQL();
0461:                } else if (source == saveSQLItem) {
0462:                    try {
0463:                        doSaveSQL();
0464:                    } catch (IOException ioe) {
0465:                        JOptionPane.showMessageDialog(this , " " + ioe,
0466:                                "Territory Reporter",
0467:                                JOptionPane.WARNING_MESSAGE);
0468:                    }
0469:                }
0470:
0471:                else if (source == exitItem) // Exit menu item
0472:                {
0473:                    dispose(); // Release the window resources
0474:                    System.exit(0); // End the application
0475:                }
0476:
0477:                else if (source == previousSQLItem) {
0478:                    if (getSelectedMyFrame().index_of_sqls == 0) {
0479:                        JOptionPane.showMessageDialog(this ,
0480:                                "There is not any SQL statement saved...");
0481:                    } else {
0482:                        if (--getSelectedMyFrame().local_index_of_sqls >= 0) {
0483:                            getSelectedMyFrame()
0484:                                    .setSqlTextArea(
0485:                                            (String) getSelectedMyFrame().sqls
0486:                                                    .get(getSelectedMyFrame().local_index_of_sqls));
0487:
0488:                        } else {
0489:                            getSelectedMyFrame().local_index_of_sqls = getSelectedMyFrame().index_of_sqls - 1;
0490:                            getSelectedMyFrame()
0491:                                    .setSqlTextArea(
0492:                                            (String) getSelectedMyFrame().sqls
0493:                                                    .get(getSelectedMyFrame().local_index_of_sqls));
0494:                        }
0495:                    }
0496:                }
0497:
0498:                else if (source == objectTableItem) {
0499:                    if (getSelectedMyFrame().tableBrowseFlag == 0) {
0500:                        if (getSelectedMyFrame().getConnectionInformation()
0501:                                .getDatabaseDialect().getTableInfoSQLString(
0502:                                        "test",
0503:                                        getSelectedMyFrame()
0504:                                                .getConnectionInformation()) == null) {
0505:                            JOptionPane
0506:                                    .showMessageDialog(
0507:                                            this ,
0508:                                            "This operation is not supported by this database dialect.",
0509:                                            "Unsupported Operation",
0510:                                            JOptionPane.INFORMATION_MESSAGE);
0511:                            return;
0512:                        }
0513:                        new TableBrowse(getSelectedMyFrame(),
0514:                                getSelectedMyFrame().connection,
0515:                                getSelectedMyFrame().userid);
0516:                        getSelectedMyFrame().tableBrowseFlag = 1;
0517:                    } else if (getSelectedMyFrame().tableBrowseFlag == 1) {
0518:                    }
0519:                }
0520:
0521:                else if (source == objectIndexItem) {
0522:                    if (getSelectedMyFrame().indexBrowseFlag == 0) {
0523:                        if (getSelectedMyFrame().getConnectionInformation()
0524:                                .getDatabaseDialect().getTableInfoSQLString(
0525:                                        "test",
0526:                                        getSelectedMyFrame()
0527:                                                .getConnectionInformation()) == null) {
0528:                            JOptionPane
0529:                                    .showMessageDialog(
0530:                                            this ,
0531:                                            "This operation is not supported by this database dialect.",
0532:                                            "Unsupported Operation",
0533:                                            JOptionPane.INFORMATION_MESSAGE);
0534:                            return;
0535:                        }
0536:                        new IndexBrowse(getSelectedMyFrame(),
0537:                                getSelectedMyFrame().connection,
0538:                                getSelectedMyFrame().userid);
0539:
0540:                        getSelectedMyFrame().indexBrowseFlag = 1;
0541:                    }
0542:                }
0543:
0544:                else if (source == objectProcedureItem) {
0545:                    if (getSelectedMyFrame().procedureBrowseFlag == 0) {
0546:                        if (getSelectedMyFrame().getConnectionInformation()
0547:                                .getDatabaseDialect()
0548:                                .getProcedureInfoSQLString(
0549:                                        "test",
0550:                                        getSelectedMyFrame()
0551:                                                .getConnectionInformation()) == null) {
0552:                            JOptionPane
0553:                                    .showMessageDialog(
0554:                                            this ,
0555:                                            "This operation is not supported by this database dialect.",
0556:                                            "Unsupported Operation",
0557:                                            JOptionPane.INFORMATION_MESSAGE);
0558:                            return;
0559:                        }
0560:                        new ProcedureBrowse(getSelectedMyFrame(),
0561:                                getSelectedMyFrame().connection,
0562:                                getSelectedMyFrame().userid);
0563:
0564:                        getSelectedMyFrame().procedureBrowseFlag = 1;
0565:                    }
0566:                }
0567:
0568:                else if (source == objectPackageItem) {
0569:                    if (getSelectedMyFrame().packageBrowseFlag == 0) {
0570:
0571:                        if (getSelectedMyFrame().getConnectionInformation()
0572:                                .getDatabaseDialect().getPackageInfoSQLString(
0573:                                        "test",
0574:                                        getSelectedMyFrame()
0575:                                                .getConnectionInformation()) == null) {
0576:                            JOptionPane
0577:                                    .showMessageDialog(
0578:                                            this ,
0579:                                            "This operation is not supported by this database dialect.",
0580:                                            "Unsupported Operation",
0581:                                            JOptionPane.INFORMATION_MESSAGE);
0582:                            return;
0583:                        }
0584:                        new PackageBrowse(getSelectedMyFrame(),
0585:                                getSelectedMyFrame().connection,
0586:                                getSelectedMyFrame().userid);
0587:
0588:                        getSelectedMyFrame().packageBrowseFlag = 1;
0589:                    }
0590:                }
0591:
0592:                else if (source == planItem) {
0593:                    getSelectedMyFrame().executePlanSQL();
0594:                }
0595:
0596:                else if (source == aboutpklItem) {
0597:                    aboutPkl();
0598:                }
0599:
0600:                else if (source == historyItem) {
0601:                    showHistory(getSelectedMyFrame());
0602:                } else if (source == commitItem) {
0603:                    MyInternalFrame tmpMyInternalFrame = getSelectedMyFrame();
0604:                    if (tmpMyInternalFrame != null
0605:                            && tmpMyInternalFrame.connection != null) {
0606:                        tmpMyInternalFrame.commitTransaction();
0607:                    }
0608:                } else if (source == rollBackItem) {
0609:                    MyInternalFrame tmpMyInternalFrame = getSelectedMyFrame();
0610:                    if (tmpMyInternalFrame != null
0611:                            && tmpMyInternalFrame.connection != null) {
0612:                        tmpMyInternalFrame.rollBackTransaction();
0613:                    }
0614:                } else if (source == preferencesItem) {
0615:                    int yPos = 0;
0616:                    int xPos = 0;
0617:                    if (preferencesJDialog == null) {
0618:                        preferencesJDialog = new JDialog(this , true);
0619:                        preferencesJDialog.setTitle("Preferences");
0620:                        preferencesJDialog.setVisible(false);
0621:                        propertiyFrame.setJDialog(preferencesJDialog);
0622:                        preferencesJDialog.getContentPane().add(propertiyFrame);
0623:                        preferencesJDialog.setSize(Preferences.HEIGHT,
0624:                                Preferences.WIDTH + 20);
0625:                    }
0626:                    //tmpJDialog.pack();
0627:
0628:                    yPos = getBounds().y
0629:                            + ((getHeight() / 2) - (preferencesJDialog
0630:                                    .getHeight() / 2));
0631:                    xPos = getBounds().x
0632:                            + ((getWidth() / 2) - (preferencesJDialog
0633:                                    .getWidth() / 2));
0634:                    preferencesJDialog.setBounds(xPos, yPos, preferencesJDialog
0635:                            .getWidth(), preferencesJDialog.getHeight());
0636:
0637:                    preferencesJDialog.setVisible(true);
0638:                    preferencesJDialog.setResizable(false);
0639:
0640:                } else if (source == scriptRunnerItem) {
0641:                    int yPos = 0;
0642:                    int xPos = 0;
0643:                    if (scriptPanel == null) {
0644:                        scriptPanel = new ScriptPanel();
0645:                        scriptPanel.init(config);
0646:                    }
0647:
0648:                    JFrame tmp = scriptPanel.getFrame();
0649:                    tmp.setSize(725, 670);
0650:                    yPos = getBounds().y
0651:                            + ((getHeight() / 2) - (tmp.getHeight() / 2));
0652:                    xPos = getBounds().x
0653:                            + ((getWidth() / 2) - (tmp.getWidth() / 2));
0654:                    tmp.setBounds(xPos, yPos, tmp.getWidth(), tmp.getHeight());
0655:
0656:                    tmp.setVisible(true);
0657:
0658:                }
0659:            }
0660:
0661:            /**
0662:             * 
0663:             */
0664:            public void nextWindow() {
0665:                try {
0666:                    MyInternalFrame selectedInternalFrame = getSelectedMyFrame();
0667:                    MyInternalFrame nextInternalFrame = null;
0668:                    if (selectedInternalFrame == null) {
0669:                        return;
0670:                    }
0671:
0672:                    int tmpIndex = selectedInternalFrame.getFrameIndex();
0673:
0674:                    desktop.getSelectedFrame().setSelected(false);
0675:                    if (tmpIndex < (myInternalFrameList.size() - 1)) {
0676:                        nextInternalFrame = (MyInternalFrame) myInternalFrameList
0677:                                .get((tmpIndex + 1));
0678:
0679:                    } else {
0680:                        nextInternalFrame = (MyInternalFrame) myInternalFrameList
0681:                                .get(0);
0682:                    }
0683:                    desktop.setSelectedFrame(nextInternalFrame);
0684:                    nextInternalFrame.setSelected(true);
0685:                } catch (PropertyVetoException ex) {
0686:                    ex.printStackTrace();
0687:                }
0688:            }
0689:
0690:            /**
0691:             * @param frame
0692:             */
0693:            private void showHistory(MyInternalFrame frame) {
0694:                int yPos = 0;
0695:                int xPos = 0;
0696:                JDialog test = new JDialog();
0697:                test.setTitle("History");
0698:                test.setModal(true);
0699:                History history = new History(getSelectedMyFrame(), test);
0700:
0701:                test.getContentPane().add(history);
0702:
0703:                test.pack();
0704:                yPos = getBounds().y
0705:                        + ((getHeight() / 2) - (test.getHeight() / 2));
0706:                xPos = getBounds().x
0707:                        + ((getWidth() / 2) - (test.getWidth() / 2));
0708:                test.setBounds(xPos, yPos, test.getWidth(), test.getHeight());
0709:                test.setResizable(false);
0710:                test.show(true);
0711:                test.repaint();
0712:
0713:            }
0714:
0715:            void doSaveSQL() throws IOException {
0716:                FileDialog exportFile = new FileDialog(this , "Save File",
0717:                        FileDialog.SAVE);
0718:
0719:                exportFile.show();
0720:                String curFile = exportFile.getFile();
0721:                String filename = exportFile.getDirectory() + curFile;
0722:                if (curFile == null) {
0723:                    return;
0724:                }
0725:                if (filename.lastIndexOf(".sql") == -1) {
0726:                    filename += ".sql";
0727:                }
0728:                File tmpFile = new File(filename);
0729:
0730:                BufferedWriter out = new BufferedWriter(new FileWriter(tmpFile));
0731:                out.write(getSelectedMyFrame().sqlTextArea.getText());
0732:                out.close();
0733:
0734:            }
0735:
0736:            void doLoadSQL() throws IOException {
0737:
0738:                FileDialog exportFile = new FileDialog(this , "Load File",
0739:                        FileDialog.LOAD);
0740:
0741:                exportFile.show();
0742:                String curFile = exportFile.getFile();
0743:                String filename = exportFile.getDirectory() + curFile;
0744:                if (curFile == null) {
0745:                    return;
0746:                }
0747:
0748:                FileReader tmpFile = new FileReader(filename);
0749:                BufferedReader in = new BufferedReader(tmpFile);
0750:                String tmpSQL = new String();
0751:                String tmpSQL2 = new String();
0752:                while ((tmpSQL2 = in.readLine()) != null) {
0753:                    tmpSQL += tmpSQL2 + "\n";
0754:                }
0755:                in.close();
0756:                getSelectedMyFrame().sqlTextArea.setText(tmpSQL);
0757:            }
0758:
0759:            void doPrintCommand() throws IOException {
0760:                PrintTable tmp = new PrintTable();
0761:                tmp.setJTable(getSelectedMyFrame().table);
0762:                tmp.doPrintJTable();
0763:            }
0764:
0765:            void doSaveCommand() throws IOException {
0766:
0767:                try {
0768:                    String delimiter = config.getExportDelimiterChar();
0769:                    String enclosedBy = config.getEncloseByChar();
0770:
0771:                    Connection con = getSelectedMyFrame().connection;
0772:                    Statement stmt = con.createStatement();
0773:                    ResultSet rs = stmt
0774:                            .executeQuery(getSelectedMyFrame().commentHandling(
0775:                                    getSelectedMyFrame().sqlTextArea.getText()));
0776:
0777:                    ResultSetMetaData rsmd = rs.getMetaData();
0778:                    int noOfColumns = rsmd.getColumnCount();
0779:                    String dataRow = "";
0780:
0781:                    FileDialog exportFile = new FileDialog(this , "Save File",
0782:                            FileDialog.SAVE);
0783:
0784:                    exportFile.show();
0785:                    String curFile = exportFile.getFile();
0786:                    if (curFile == null) {
0787:                        return;
0788:                    }
0789:                    if (curFile.lastIndexOf(".csv") == -1) {
0790:                        curFile += ".csv";
0791:                    }
0792:
0793:                    String filename = exportFile.getDirectory() + curFile;
0794:
0795:                    File tmpFile = new File(filename);
0796:
0797:                    BufferedWriter out = new BufferedWriter(new FileWriter(
0798:                            tmpFile));
0799:
0800:                    for (int a = 1; a < noOfColumns + 1; a++) {
0801:                        if (a == 1) {
0802:                            dataRow = rsmd.getColumnName(a);
0803:
0804:                        } else {
0805:                            dataRow = dataRow + delimiter
0806:                                    + rsmd.getColumnName(a);
0807:                        }
0808:
0809:                    }
0810:                    out.write(dataRow);
0811:                    out.newLine();
0812:
0813:                    while (rs.next()) {
0814:                        for (int a = 1; a < noOfColumns + 1; a++) {
0815:                            if (a == 1) {
0816:                                if (rs.getString(a) == null) {
0817:                                    dataRow = enclosedBy + enclosedBy;
0818:                                } else {
0819:                                    dataRow = enclosedBy + rs.getString(a)
0820:                                            + enclosedBy;
0821:                                }
0822:                            } else {
0823:                                if (rs.getString(a) == null) {
0824:                                    dataRow = dataRow + delimiter + enclosedBy
0825:                                            + enclosedBy;
0826:                                } else {
0827:                                    dataRow = dataRow + delimiter + enclosedBy
0828:                                            + rs.getString(a) + enclosedBy;
0829:                                }
0830:                            }
0831:                        }
0832:                        out.write(dataRow);
0833:                        out.newLine();
0834:                    }
0835:                    // close the file 
0836:                    out.close();
0837:
0838:                } catch (SQLException sqle) {
0839:                    JOptionPane.showMessageDialog(this , sqle.getMessage());
0840:                }
0841:            }
0842:
0843:            void doExportXMLCommand() throws IOException {
0844:
0845:                try {
0846:                    boolean useCdata = config.isUseCdata();
0847:                    Connection con = getSelectedMyFrame().connection;
0848:                    Statement stmt = con.createStatement();
0849:                    ResultSet rs = stmt
0850:                            .executeQuery(getSelectedMyFrame().commentHandling(
0851:                                    getSelectedMyFrame().sqlTextArea.getText()));
0852:
0853:                    ResultSetMetaData rsmd = rs.getMetaData();
0854:                    int noOfColumns = rsmd.getColumnCount();
0855:                    String dataRow = "";
0856:
0857:                    FileDialog exportFile = new FileDialog(this , "Save File",
0858:                            FileDialog.SAVE);
0859:
0860:                    exportFile.show();
0861:                    String curFile = exportFile.getFile();
0862:                    if (curFile == null) {
0863:                        return;
0864:                    }
0865:                    if (curFile.lastIndexOf(".xml") == -1) {
0866:                        curFile += ".xml";
0867:                    }
0868:
0869:                    String filename = exportFile.getDirectory() + curFile;
0870:
0871:                    File tmpFile = new File(filename);
0872:
0873:                    BufferedWriter out = new BufferedWriter(new FileWriter(
0874:                            tmpFile));
0875:
0876:                    //out.write("<?xml version=\"1.0\" encoding=\"" + System.getProperty("file.encoding")+ "\"?>");
0877:                    out.write("<?xml version=\"1.0\"?>");
0878:                    out.newLine();
0879:                    out.write("\t<resultSet>");
0880:                    out.newLine();
0881:                    int rowCount = 0;
0882:                    while (rs.next()) {
0883:                        out.write("\t\t<row rowNumber = \""
0884:                                + String.valueOf(rowCount) + "\" >");
0885:                        out.newLine();
0886:                        for (int a = 1; a < noOfColumns + 1; a++) {
0887:                            if (rs.getString(a) == null) {
0888:                                dataRow = "\t\t\t<" + rsmd.getColumnName(a)
0889:                                        + " />";
0890:                            } else {
0891:                                dataRow = dataRow = "\t\t\t<"
0892:                                        + rsmd.getColumnName(a) + ">"
0893:                                        + (useCdata ? "<![CDATA[" : "")
0894:                                        + rs.getString(a)
0895:                                        + (useCdata ? "]]>" : "") + "</"
0896:                                        + rsmd.getColumnName(a) + ">";
0897:                            }
0898:                            out.write(dataRow);
0899:                            out.newLine();
0900:                        }
0901:                        out.write("\t\t</row>");
0902:                        out.newLine();
0903:                        rowCount++;
0904:                    }
0905:                    out.write("\t</resultSet>");
0906:                    out.newLine();
0907:                    // close the file 
0908:                    out.close();
0909:
0910:                } catch (SQLException sqle) {
0911:                    JOptionPane.showMessageDialog(this , sqle.getMessage());
0912:                }
0913:            }
0914:
0915:            void doExportHTMLCommand() throws IOException {
0916:
0917:                try {
0918:                    boolean altRowColor = false;
0919:                    Connection con = getSelectedMyFrame().connection;
0920:                    Statement stmt = con.createStatement();
0921:                    ResultSet rs = stmt
0922:                            .executeQuery(getSelectedMyFrame().commentHandling(
0923:                                    getSelectedMyFrame().sqlTextArea.getText()));
0924:
0925:                    ResultSetMetaData rsmd = rs.getMetaData();
0926:                    int noOfColumns = rsmd.getColumnCount();
0927:
0928:                    FileDialog exportFile = new FileDialog(this , "Save File",
0929:                            FileDialog.SAVE);
0930:
0931:                    exportFile.show();
0932:                    String curFile = exportFile.getFile();
0933:                    if (curFile == null) {
0934:                        return;
0935:                    }
0936:                    if (curFile.lastIndexOf(".html") == -1) {
0937:                        curFile += ".html";
0938:                    }
0939:
0940:                    String filename = exportFile.getDirectory() + curFile;
0941:
0942:                    File tmpFile = new File(filename);
0943:
0944:                    BufferedWriter out = new BufferedWriter(new FileWriter(
0945:                            tmpFile));
0946:                    out.write("<HTML>");
0947:                    out.newLine();
0948:                    out.write("<BODY>");
0949:                    out.newLine();
0950:                    out
0951:                            .write("<TABLE style=\"border-collapse= collapse\" border=\"1\" bordercolor=\""
0952:                                    + config.getBorderColor()
0953:                                    + "\"  rules=\"cols,rows\">");
0954:                    out.newLine();
0955:                    out.write("<tbody>");
0956:                    out.newLine();
0957:                    out.write("<TR bgcolor=\"" + config.getHeaderColor()
0958:                            + "\">");
0959:                    out.newLine();
0960:                    for (int a = 1; a < noOfColumns + 1; a++) {
0961:                        out.write("<TH>"
0962:                                + Util.escapeHTML(rsmd.getColumnName(a))
0963:                                + "</TH>");
0964:                        out.newLine();
0965:                    }
0966:                    while (rs.next()) {
0967:                        //Alternate row color
0968:                        if (altRowColor) {
0969:                            out.write("<TR bgcolor=\""
0970:                                    + config.getAltRowColor() + "\" >");
0971:                            out.newLine();
0972:                            altRowColor = false;
0973:                        } else {
0974:                            altRowColor = true;
0975:                            out.write("<TR>");
0976:                            out.newLine();
0977:                        }
0978:                        for (int a = 1; a < noOfColumns + 1; a++) {
0979:                            if (rs.getString(a) == (null)) {
0980:                                out.write("<TD>&nbsp;</TD>");
0981:                                out.newLine();
0982:                            } else {
0983:                                out.write("<TD>"
0984:                                        + Util.escapeHTML(rs.getString(a))
0985:                                        + "</TD>");
0986:                                out.newLine();
0987:                            }
0988:                        }
0989:                        out.write("</TR>");
0990:                        out.newLine();
0991:                    }
0992:
0993:                    out.write("</tbody>");
0994:                    out.newLine();
0995:                    out.write("</TABLE>");
0996:                    out.newLine();
0997:                    out.write("</BODY>");
0998:                    out.newLine();
0999:                    out.write("</HTML>");
1000:                    //          close the file 
1001:                    out.close();
1002:
1003:                } catch (SQLException sqle) {
1004:                    JOptionPane.showMessageDialog(this , sqle.getMessage());
1005:                }
1006:            }
1007:
1008:            public void aboutPkl() {
1009:                //JOptionPane.showMessageDialog(this, "Pklite is a modified version of a program called Pretty Kid\nFor more information about Pretty Kid click on the \nabout pretty kid menu item in the help menu\nhttp://pklite.sourceforge.net/", "About PKLite", JOptionPane.INFORMATION_MESSAGE, new ImageIcon("images/yoda.gif"));
1010:                int yPos = 0;
1011:                int xPos = 0;
1012:                JDialog tmpJDialog = new JDialog(this , true);
1013:                tmpJDialog.setTitle("About");
1014:
1015:                AboutPanel tmpAboutPanel = new AboutPanel(tmpJDialog);
1016:                tmpJDialog.getContentPane().add(tmpAboutPanel);
1017:                tmpJDialog.pack();
1018:
1019:                yPos = getBounds().y
1020:                        + ((getHeight() / 2) - (tmpJDialog.getHeight() / 2));
1021:                xPos = getBounds().x
1022:                        + ((getWidth() / 2) - (tmpJDialog.getWidth() / 2));
1023:                tmpJDialog.setBounds(xPos, yPos, tmpJDialog.getWidth(),
1024:                        tmpJDialog.getHeight());
1025:
1026:                tmpJDialog.setVisible(true);
1027:                tmpJDialog.setResizable(false);
1028:
1029:            }
1030:
1031:            class HandleControlButton implements  ActionListener {
1032:                private int buttonID;
1033:
1034:                public HandleControlButton(int buttonID) {
1035:                    this .buttonID = buttonID;
1036:                }
1037:
1038:                public void actionPerformed(ActionEvent e) {
1039:                    switch (buttonID) {
1040:                    case 1: // Execute SQL
1041:                        getSelectedMyFrame().prexecuteSQL();
1042:                        break;
1043:
1044:                    case 2: // New connection(session)
1045:                        createMyNewWindow();
1046:                        break;
1047:
1048:                    case 3: // Save
1049:                        try {
1050:                            doSaveCommand();
1051:                        } catch (IOException ioe) {
1052:                            System.out.println("IOException occured... " + ioe);
1053:                        }
1054:                        break;
1055:
1056:                    case 4: // Cut
1057:                        getSelectedMyFrame().sqlTextArea.cut();
1058:                        break;
1059:
1060:                    case 5: // Copy
1061:                        //	  	if(getSelectedMyFrame().get)
1062:                        // 	{
1063:                        //	int d = 0;
1064:                        //d=d;
1065:                        //}
1066:                        getSelectedMyFrame().sqlTextArea.copy();
1067:                        break;
1068:
1069:                    case 6: // Paste
1070:                        getSelectedMyFrame().sqlTextArea.paste();
1071:                        break;
1072:
1073:                    case 7: // Help
1074:                        aboutPkl();
1075:                        break;
1076:                    case 8: // History
1077:                        showHistory(getSelectedMyFrame());
1078:                        break;
1079:
1080:                    }
1081:                }
1082:            }
1083:
1084:            class WindowHandler extends WindowAdapter {
1085:                public void windowActivated(WindowEvent e) {
1086:                    //System.out.println("Window activated.");
1087:                }
1088:
1089:                public void windowLostFocus(WindowEvent e) {
1090:                    //System.out.println("Window lost focus.");
1091:                }
1092:
1093:                public void windowGainedFocus(WindowEvent e) {
1094:                    //System.out.println("Window gained focus.");
1095:                }
1096:
1097:                public void windowStateChanged(WindowEvent e) {
1098:                    //System.out.println("Window state changed.");
1099:                }
1100:
1101:                // Handler for window closing event
1102:                public void windowClosing(WindowEvent e) {
1103:                    dispose(); // Release the window resources
1104:                    System.exit(0); // End the application
1105:                }
1106:            }
1107:
1108:            class WinHandlerForSgaItem extends WindowAdapter {
1109:                public void windowClosing(WindowEvent e) {
1110:                    isSgaFrameOpened = 0;
1111:                }
1112:            }
1113:
1114:            protected void addButtons(JToolBar toolBar) {
1115:                JButton button = null;
1116:
1117:                button = new JButton(new ImageIcon("images/run.gif"));
1118:                button.setToolTipText("Run Query");
1119:                toolBar.add(button);
1120:                button.addActionListener(new HandleControlButton(1));
1121:
1122:                button = new JButton(new ImageIcon("images/New16.gif"));
1123:                button.setToolTipText("New Window");
1124:                toolBar.add(button);
1125:                button.addActionListener(new HandleControlButton(2));
1126:
1127:                button = new JButton(new ImageIcon("images/Save16.gif"));
1128:                button.setToolTipText("Save Results to CSV File");
1129:                toolBar.add(button);
1130:                button.addActionListener(new HandleControlButton(3));
1131:
1132:                button = new JButton(new ImageIcon("images/Cut16.gif"));
1133:                button.setToolTipText("Cut");
1134:                toolBar.add(button);
1135:                button.addActionListener(new HandleControlButton(4));
1136:
1137:                button = new JButton(new ImageIcon("images/Copy16.gif"));
1138:                button.setToolTipText("Copy");
1139:                toolBar.add(button);
1140:                button.addActionListener(new HandleControlButton(5));
1141:
1142:                button = new JButton(new ImageIcon("images/Paste16.gif"));
1143:                button.setToolTipText("past");
1144:                toolBar.add(button);
1145:                button.addActionListener(new HandleControlButton(6));
1146:
1147:                button = new JButton(new ImageIcon("images/Help16.gif"));
1148:                button.setToolTipText("Help");
1149:                toolBar.add(button);
1150:                button.addActionListener(new HandleControlButton(7));
1151:                button = new JButton(new ImageIcon("images/History16.gif"));
1152:                button.setToolTipText("Show Statment History");
1153:                toolBar.add(button);
1154:                button.addActionListener(new HandleControlButton(8));
1155:
1156:            }
1157:
1158:            public class TabbedPanel extends JPanel {
1159:                /**
1160:                 * 
1161:                 */
1162:                private static final long serialVersionUID = 1L;
1163:                String tabs[] = { "Library Cache", "Dictionary Cache",
1164:                        "Buffer Cache", "Sort", "Redo Log Request" };
1165:                String result;
1166:                String rs[] = { "xxx", "xxx" };
1167:
1168:                public JTabbedPane tabbedPane = new JTabbedPane();
1169:
1170:                public TabbedPanel() {
1171:                    setLayout(new BorderLayout());
1172:                    for (int i = 0; i < tabs.length; i++) {
1173:                        switch (i) {
1174:                        case 0:
1175:                            result = executeLibrarayCacheSQL();
1176:                            break;
1177:                        case 1:
1178:                            result = executeDictionaryCacheSQL();
1179:                            break;
1180:                        case 2:
1181:                            result = executeBufferCacheSQL();
1182:                            break;
1183:                        case 3:
1184:                            executeSortSQL();
1185:                            break;
1186:                        case 4:
1187:                            result = executeRedoLogSQL();
1188:                            break;
1189:                        }
1190:                        tabbedPane.addTab(tabs[i], null, createPane(i, " "));
1191:                    }
1192:                    tabbedPane.setSelectedIndex(0);
1193:                    add(tabbedPane, BorderLayout.CENTER);
1194:                }
1195:
1196:                public String executeLibrarayCacheSQL() {
1197:                    String query = "select to_char(trunc(sum(reloads)/sum(pins)*100, 5),99.99999)||'%'"
1198:                            + " as libcache from v$librarycache";
1199:                    String libCacheRatio = "xxx";
1200:
1201:                    try {
1202:                        ResultSet r = frame.statement.executeQuery(query);
1203:                        while (r.next()) {
1204:                            libCacheRatio = r.getString("libcache");
1205:                        }
1206:                    } catch (SQLException sqle) {
1207:                        frame.statusBar.setMessagePane(sqle.getMessage()); // Display error message
1208:                    }
1209:
1210:                    return libCacheRatio;
1211:
1212:                }
1213:
1214:                public String executeDictionaryCacheSQL() {
1215:                    String query = "select trunc(sum(getmisses)/sum(gets)*100, 5)||'%  (less than 9.8%)' "
1216:                            + " as dictionary from v$rowcache";
1217:                    String dictionaryRatio = "xxx";
1218:
1219:                    try {
1220:                        ResultSet r = frame.statement.executeQuery(query);
1221:                        while (r.next()) {
1222:                            dictionaryRatio = r.getString("dictionary");
1223:                        }
1224:                    } catch (SQLException sqle) {
1225:                        frame.statusBar.setMessagePane(sqle.getMessage()); // Display error message
1226:                    }
1227:
1228:                    return dictionaryRatio;
1229:
1230:                }
1231:
1232:                public String executeBufferCacheSQL() {
1233:                    String query = "select trunc((1 - (cc/(aa+bb)))*100, 5)||'%  (more than 60-70%)' "
1234:                            + " as buffercache from buffer_cache";
1235:                    String bufferRatio = "xxx";
1236:
1237:                    try {
1238:                        frame.statement
1239:                                .executeUpdate("create table buffer_cache "
1240:                                        + "( aa   number(10), "
1241:                                        + "bb   number(10), "
1242:                                        + "cc   number(10))");
1243:                        frame.statement
1244:                                .executeUpdate("insert into buffer_cache (aa) select value from v$sysstat "
1245:                                        + "where name ='db block gets'");
1246:                        frame.statement
1247:                                .executeUpdate("update buffer_cache set bb = (select value from v$sysstat "
1248:                                        + "where name ='consistent gets')");
1249:                        frame.statement
1250:                                .executeUpdate("update buffer_cache set cc = (select value from v$sysstat "
1251:                                        + "where name ='physical reads')");
1252:                        ResultSet r = frame.statement.executeQuery(query);
1253:                        while (r.next()) {
1254:                            bufferRatio = r.getString("buffercache");
1255:                        }
1256:                        frame.statement
1257:                                .executeUpdate("drop table buffer_cache");
1258:                    } catch (SQLException sqle) {
1259:                        JOptionPane.showMessageDialog(this , sqle.getMessage());
1260:                        frame.statusBar.setMessagePane(sqle.getMessage()); // Display error message
1261:                    }
1262:
1263:                    return bufferRatio;
1264:
1265:                }
1266:
1267:                public void executeSortSQL() {
1268:                    String query = "select value from v$sysstat "
1269:                            + "where name in ('sorts (memory)', 'sorts (disk)')";
1270:                    int j = 0;
1271:
1272:                    try {
1273:                        ResultSet r = frame.statement.executeQuery(query);
1274:                        while (r.next()) {
1275:                            rs[j] = r.getString("value");
1276:                            j++;
1277:                        }
1278:                    } catch (SQLException sqle) {
1279:                        frame.statusBar.setMessagePane(sqle.getMessage()); // Display error message
1280:                    }
1281:
1282:                }
1283:
1284:                public String executeRedoLogSQL() {
1285:                    String query = "select value as redologrequest "
1286:                            + "from v$sysstat "
1287:                            + "where name = 'redo log space requests'";
1288:                    String redoLogReq = "xxx";
1289:
1290:                    try {
1291:                        ResultSet r = frame.statement.executeQuery(query);
1292:                        while (r.next()) {
1293:                            redoLogReq = r.getString("redologrequest");
1294:                        }
1295:                    } catch (SQLException sqle) {
1296:                        frame.statusBar.setMessagePane(sqle.getMessage()); // Display error message
1297:                    }
1298:
1299:                    return redoLogReq;
1300:
1301:                }
1302:
1303:                JPanel createPane(int i, String s) {
1304:                    JPanel p = new JPanel();
1305:                    p.add(new JLabel(s));
1306:
1307:                    switch (i) {
1308:                    case 0:
1309:                        p.add(new JLabel("Library Cache Miss Ratio is "
1310:                                + result));
1311:                        p
1312:                                .add(new JLabel(
1313:                                        "Libary cache miss ratio is good if it is less than 1~2%"));
1314:                        p
1315:                                .add(new JLabel(
1316:                                        "Increase shared_pool_size value if it is more than 2%"));
1317:                        p
1318:                                .add(new JLabel(
1319:                                        "If shared_pool_size value is too small, it will affect performance"));
1320:                        p.add(new JLabel(
1321:                                "SGA should be less than 50% of OS memory"));
1322:                        break;
1323:                    case 1:
1324:                        p.add(new JLabel("Dictionary Cache Miss Ratio is "
1325:                                + result));
1326:                        break;
1327:                    case 2:
1328:                        p
1329:                                .add(new JLabel("Buffer Cache Hit Ratio is "
1330:                                        + result));
1331:                        break;
1332:                    case 3:
1333:                        p
1334:                                .add(new JLabel("Memory Sort Count : " + rs[0]
1335:                                        + ", "));
1336:                        p.add(new JLabel("Disk Sort Count : " + rs[1]));
1337:                        break;
1338:                    case 4:
1339:                        p
1340:                                .add(new JLabel("Redo Log Request Count is "
1341:                                        + result));
1342:                        break;
1343:                    }
1344:                    return p;
1345:                }
1346:            }
1347:
1348:            public void createWindowMenu() {
1349:                JMenu tmpwindowMenu = menuBar.getMenu(4);
1350:                WindowJMenuItem jMenuItem = null;
1351:                MyInternalFrame tmp = null;
1352:                tmpwindowMenu.removeAll();
1353:                int size = myInternalFrameList.size();
1354:                tmpwindowMenu.add(nextWindowItem);
1355:                tmpwindowMenu.addSeparator();
1356:                if (size > 0) {
1357:                    for (int x = 0; x < size; x++) {
1358:                        tmp = (MyInternalFrame) myInternalFrameList.get(x);
1359:                        tmp.setFrameIndex(x);
1360:                        jMenuItem = new WindowJMenuItem(tmp.getConnectionName());
1361:                        tmpwindowMenu.add(jMenuItem);
1362:                        if (x + 1 < 10) {
1363:                            jMenuItem.setAccelerator(KeyStroke.getKeyStroke(
1364:                                    String.valueOf(x + 1).charAt(0),
1365:                                    Event.CTRL_MASK));
1366:                        }
1367:                        jMenuItem.addActionListener(this );
1368:                        jMenuItem.setWindowIndex(x);
1369:                    }
1370:                }
1371:                tmpwindowMenu.addSeparator();
1372:                tmpwindowMenu.add(scriptRunnerItem);
1373:                tmpwindowMenu.add(preferencesItem);
1374:            }
1375:
1376:            /**
1377:             * @return
1378:             */
1379:            public Vector getMyInternalFrameList() {
1380:                return myInternalFrameList;
1381:            }
1382:
1383:            /**
1384:             * @param vector
1385:             */
1386:            public void setMyInternalFrameList(Vector vector) {
1387:                myInternalFrameList = vector;
1388:            }
1389:
1390:            /**
1391:             * @return
1392:             */
1393:            public Hashtable getConnectionList() {
1394:                return connectionList;
1395:            }
1396:
1397:            /**
1398:             * @return Returns the config.
1399:             */
1400:            public Config getConfig() {
1401:                return config;
1402:            }
1403:
1404:            /**
1405:             * @param config The config to set.
1406:             */
1407:            public void setConfig(Config config) {
1408:                this .config = config;
1409:            }
1410:
1411:            /**
1412:             * @return Returns the props.
1413:             */
1414:            public Preferences getpropertiyFrame() {
1415:                if (propertiyFrame == null) {
1416:                    propertiyFrame = new Preferences();
1417:                }
1418:                return propertiyFrame;
1419:            }
1420:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.