0001: /*
0002: * Copyright 2007 Madhav Pulipaka
0003: *
0004: * This file is part of Vela.
0005:
0006: * Vela is free software; you can redistribute it and/or modify
0007: * it under the terms of the GNU General Public License as published by
0008: * the Free Software Foundation; either version 2 of the License, or
0009: * (at your option) any later version.
0010: *
0011: * Vela is distributed in the hope that it will be useful,
0012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0014: * GNU General Public License for more details.
0015: *
0016: * You should have received a copy of the GNU General Public License
0017: * along with Vela; if not, write to the Free Software
0018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0019: */
0020: package vela.view;
0021:
0022: import javax.swing.*;
0023: import javax.swing.text.*;
0024:
0025: import java.awt.*;
0026: import java.awt.event.*;
0027: import java.io.FileInputStream;
0028: import java.net.MalformedURLException;
0029: import java.net.URL;
0030: import java.net.URLClassLoader;
0031: import java.sql.SQLException;
0032: import java.util.*;
0033:
0034: import javax.swing.UIManager.LookAndFeelInfo;
0035: import javax.swing.event.*;
0036: import javax.swing.table.*;
0037:
0038: import vela.common.Constants;
0039: import vela.db.*;
0040: import vela.model.*;
0041: import vela.view.util.*;
0042: import java.util.regex.*;
0043: import java.awt.image.BufferedImage;
0044:
0045: public class MainFrame extends JFrame implements ActionListener,
0046: WindowListener, ItemListener, ListSelectionListener,
0047: DocumentListener, Constants, CaretListener {
0048:
0049: JMenuBar menu;
0050: Container cont;
0051: JTextField statusBar;
0052: JEditorPane editor;
0053: JEditorPane sqlEditor;
0054: JScrollPane spEditor;
0055: JList list;
0056: Color toolbarColor = new Color(250, 255, 255);
0057: JButton btnConn;
0058: JButton btnCommit;
0059: JButton btnRollback;
0060: JButton btnDisc;
0061: JButton btnHelp;
0062: JButton btnAbout;
0063: JButton btnLicense;
0064: JButton btnSQLEd;
0065: JButton btnObjViewer;
0066: JButton btnRun;
0067: JButton btnMetalLF;
0068: JButton btnSystemLF;
0069: JButton btnMotifLF;
0070: JPanel leftPanel;
0071: JPanel rightPanel;
0072: JComboBox cbDBObjects;
0073: ArrayList dbObjects = new ArrayList(0);
0074: JMenuItem miConn = new JMenuItem("Connect");
0075: JMenuItem miCommit = new JMenuItem("Commit");
0076: JMenuItem miRollback = new JMenuItem("Rollback");
0077: JMenuItem miDisc = new JMenuItem("Disconnect");
0078: JMenuItem miHelp = new JMenuItem("Help");
0079: JMenuItem miAbout = new JMenuItem("About");
0080: JMenuItem miLicense = new JMenuItem("License");
0081: JMenuItem miSystem = new JMenuItem("System");
0082: JMenuItem miMetal = new JMenuItem("Metal");
0083: JMenuItem miMotif = new JMenuItem("Motif");
0084: JMenuItem miSQLEd = new JMenuItem("SQL Editor");
0085: JMenuItem miDBViewer = new JMenuItem("Object Viewer");
0086: DefaultComboBoxModel cb;
0087: DBStructure dbStructure;
0088: String objectTypes[] = { "FUNCTION", "INDEX", "PROCEDURE",
0089: "SEQUENCE", "SYNONYM", "TABLE", "TRIGGER", "VIEW",
0090: "PACKAGE" };
0091: DefaultListModel listModel;
0092: JTable tableDetails;
0093: JTable seqDetails;
0094: JTable indxDetails;
0095: JTable synDetails;
0096: //JTable tableData;
0097: Vector tabDescVector;
0098: Vector colHdr;
0099: Vector colHdrSeq;
0100: Vector colHdrIndx;
0101: Vector colHdrSyn;
0102: Vector tableColumns;
0103: ReadOnlyTableModel tabModel;
0104: ReadOnlyTableModel tabModelSeq;
0105: ReadOnlyTableModel tabModelIndx;
0106: ReadOnlyTableModel tabModelSyn;
0107: ReadOnlyTableModel tabDataModel;
0108: ReadOnlyTableModel tabDataModelSE;
0109: JTabbedPane tabbedPaneTable;
0110: int tableDataStartRowNum;
0111: int tableDataEndRowNum;
0112: JButton btnNextRecords = new JButton(">>");
0113: JButton btnPrevRecords = new JButton("<<");
0114: JButton btnDataFilter = new JButton("::}:");
0115: JButton btnDataSort = new JButton("_-_");
0116: //JButton btnDataFilter = new JButton("Y");
0117: ArrayList lstKeyWords = new ArrayList(0);
0118: ArrayList lstSQLCommands = new ArrayList(0);
0119: ArrayList allDBObjectNames = new ArrayList(0);
0120: JDesktopPane desktop = new JDesktopPane();
0121: JPanel panPLSQLEditorTop;
0122: JButton btnCompile;
0123: Vector dataDesc;
0124: int currentTabSelection;
0125: int currTabRowCount;
0126: JSplitPane splitPane;
0127: JInternalFrame objViewerFrame;
0128: JInternalFrame sqlEditorFrame;
0129: JTextField positionBar = new JTextField("");
0130: JPanel seSouthPanel;
0131: JPanel seNorthPanel;
0132: JEditorPane textSEResult;
0133: DBManager dbManager;
0134: Properties properties;
0135:
0136: public MainFrame() {
0137: init();
0138: }
0139:
0140: public void init() {
0141: cont = getContentPane();
0142: statusBar = new JTextField(
0143: "Welcome - Click on Connect to start.");
0144: //getContentPane().add(desktop);
0145: /*frameDBViewer.moveToFront();
0146: frameDBViewer.setVisible(true);
0147: cont = frameDBViewer.getContentPane();
0148: JPanel panDBViewer = new JPanel(new BorderLayout());
0149: cont.add(panDBViewer);*/
0150: menu = new JMenuBar();
0151: JMenu menuConn = new JMenu("Connection");
0152: JMenu menuHelp = new JMenu("Help");
0153: JMenu menuTools = new JMenu("Tools");
0154: JMenu menuLF = new JMenu("Look & Feel");
0155:
0156: menuConn.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0157: menuHelp.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0158: menuLF.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0159: menuTools.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0160: menuConn.add(miConn);
0161: menuConn.add(miDisc);
0162: menuConn.add(miCommit);
0163: menuConn.add(miRollback);
0164: menuHelp.add(miHelp);
0165: menuHelp.add(miAbout);
0166: menuHelp.add(miLicense);
0167: menuLF.add(miSystem);
0168: menuLF.add(miMetal);
0169: menuLF.add(miMotif);
0170: menuTools.add(miSQLEd);
0171: menuTools.add(miDBViewer);
0172:
0173: miConn.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0174: miDisc.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0175: miCommit.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0176: miRollback.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0177: miAbout.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0178: miLicense.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0179: miHelp.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0180: miSystem.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0181: miMetal.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0182: miMotif.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0183: miSQLEd.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0184: miDBViewer.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0185: menu.add(menuConn);
0186: menu.add(menuTools);
0187: menu.add(menuLF);
0188: menu.add(menuHelp);
0189: //menu.setBackground(toolbarColor);
0190: //miConn.setBackground(toolbarColor);
0191: //miDisc.setBackground(toolbarColor);
0192: //menuConn.setBackground(toolbarColor);
0193: menu.setForeground(Color.BLACK);
0194: miConn.setForeground(Color.BLACK);
0195: miDisc.setForeground(Color.BLACK);
0196: miCommit.setForeground(Color.BLACK);
0197: miRollback.setForeground(Color.BLACK);
0198: menuConn.setForeground(Color.BLACK);
0199: menuHelp.setForeground(Color.BLACK);
0200: menuLF.setForeground(Color.BLACK);
0201: menuTools.setForeground(Color.BLACK);
0202: JToolBar toolbar = new JToolBar();
0203: btnConn = new JButton("-( )-");
0204: btnCommit = new JButton("OO>");
0205: btnRollback = new JButton("<OO");
0206: //btnConn.setRolloverEnabled(true);
0207: btnConn.setToolTipText("Connect");
0208: btnCommit.setToolTipText("Commit");
0209: btnRollback.setToolTipText("Rollback");
0210: btnConn.setActionCommand("Connect");
0211: btnCommit.setActionCommand("Commit");
0212: btnRollback.setActionCommand("Rollback");
0213: btnDisc = new JButton("-( )-");
0214: btnAbout = new JButton("?");
0215: btnLicense = new JButton("License");
0216: btnHelp = new JButton("!!");
0217: btnSQLEd = new JButton("SQL");
0218: btnObjViewer = new JButton("[][]");
0219: btnSQLEd.setEnabled(false);
0220: btnObjViewer.setEnabled(false);
0221: btnRun = new JButton("R");
0222: btnMetalLF = new JButton("Metal Look");
0223: btnMotifLF = new JButton("Motif Look");
0224: btnSystemLF = new JButton("System Look");
0225: btnAbout.setToolTipText("About");
0226: btnLicense.setToolTipText("License");
0227: btnHelp.setToolTipText("Help");
0228: btnSQLEd.setToolTipText("SQL Editor");
0229: btnObjViewer.setToolTipText("Object Viewer");
0230: btnRun.setToolTipText("Run Script");
0231: btnMetalLF.setToolTipText("Metal Look");
0232: btnMotifLF.setToolTipText("Motif Look");
0233: btnSystemLF.setToolTipText("System Look");
0234: btnDisc.setActionCommand("Disconnect");
0235: btnAbout.setActionCommand("About");
0236: btnLicense.setActionCommand("License");
0237: btnHelp.setActionCommand("Help");
0238: btnSQLEd.setActionCommand("SQLEditor");
0239: btnObjViewer.setActionCommand("ShowObjectViewer");
0240: btnRun.setActionCommand("RunSQL");
0241: btnMetalLF.setActionCommand("MetalLF");
0242: btnMotifLF.setActionCommand("MotifLF");
0243: btnSystemLF.setActionCommand("SystemLF");
0244: btnConn.setFont(new Font("Lucida Console", Font.BOLD, fontBig));
0245: btnCommit
0246: .setFont(new Font("Lucida Console", Font.BOLD, fontBig));
0247: btnRollback.setFont(new Font("Lucida Console", Font.BOLD,
0248: fontBig));
0249: btnDisc.setFont(new Font("Lucida Console", Font.BOLD, fontBig));
0250: btnAbout
0251: .setFont(new Font("Lucida Console", Font.BOLD, fontBig));
0252: btnLicense.setFont(new Font("Lucida Console", Font.BOLD,
0253: fontBig));
0254: btnHelp.setFont(new Font("Lucida Console", Font.BOLD, fontBig));
0255: btnSQLEd
0256: .setFont(new Font("Lucida Console", Font.BOLD, fontBig));
0257: btnObjViewer.setFont(new Font("Lucida Console", Font.BOLD,
0258: fontBig));
0259: btnRun.setFont(new Font("Lucida Console", Font.BOLD, fontBig));
0260: btnMetalLF.setFont(new Font("Lucida Console", Font.BOLD,
0261: fontBig));
0262: btnMotifLF.setFont(new Font("Lucida Console", Font.BOLD,
0263: fontBig));
0264: btnSystemLF.setFont(new Font("Lucida Console", Font.BOLD,
0265: fontBig));
0266: toolbar.add(btnConn);
0267: toolbar.add(btnCommit);
0268: toolbar.add(btnRollback);
0269: toolbar.add(btnSQLEd);
0270: toolbar.add(btnObjViewer);
0271: toolbar.add(btnSystemLF);
0272: toolbar.add(btnMetalLF);
0273: toolbar.add(btnMotifLF);
0274: toolbar.add(btnHelp);
0275: toolbar.add(btnAbout);
0276: toolbar.add(btnLicense);
0277: //toolbar.add(btnDisc);
0278: btnConn.setForeground(new Color(128, 0, 0));
0279: btnCommit.setForeground(new Color(0, 128, 0));
0280: btnRollback.setForeground(new Color(128, 0, 0));
0281: //btnDisc.setForeground(Color.RED);
0282: //btnConn.setBackground(new Color(0,0,100));
0283: //btnAbout.setForeground(Color.YELLOW);
0284: //btnAbout.setBackground(new Color(0,0,100));
0285: //btnDisc.setBackground(new Color(0,0,100));
0286: toolbar.setForeground(Color.BLACK);
0287: //toolbar.setBackground(toolbarColor);
0288: JPanel topPan = new JPanel();
0289: topPan.setLayout(new BorderLayout());
0290: topPan.add(menu);
0291: topPan.add(toolbar, BorderLayout.SOUTH);
0292: cont.add(topPan, BorderLayout.NORTH);
0293:
0294: statusBar.setOpaque(true);
0295: statusBar.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0296: statusBar.setEnabled(false);
0297: statusBar.setDisabledTextColor(Color.BLACK);
0298:
0299: positionBar.setOpaque(true);
0300: positionBar.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0301: positionBar.setEnabled(false);
0302: positionBar.setDisabledTextColor(Color.BLACK);
0303: positionBar.setPreferredSize(new Dimension(200, 20));
0304:
0305: JPanel southPanel = new JPanel(new BorderLayout());
0306: southPanel.add(statusBar);
0307: southPanel.add(positionBar, BorderLayout.EAST);
0308:
0309: cont.add(southPanel, BorderLayout.SOUTH);
0310: editor = new JEditorPane("text/rtf", "");
0311: sqlEditor = new JEditorPane();
0312: spEditor = new JScrollPane(editor);
0313: DefaultStyledDocument editorDocument = new DefaultStyledDocument();
0314: editor.setDocument(editorDocument);
0315: editorDocument.addDocumentListener(this );
0316: listModel = new DefaultListModel();
0317: leftPanel = new JPanel();
0318: rightPanel = new JPanel();
0319: cb = new DefaultComboBoxModel();
0320: cbDBObjects = new JComboBox(cb);
0321: cbDBObjects.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0322: list = new JList(listModel);
0323: leftPanel.setLayout(new BorderLayout());
0324: cbDBObjects.setBackground(Color.WHITE);
0325: cbDBObjects.setForeground(Color.BLACK);
0326: leftPanel.add(cbDBObjects, BorderLayout.NORTH);
0327: list.setFont(new Font(fontFamily, Font.BOLD, fontSmall));
0328: editor.setFont(new Font("Courier New", Font.PLAIN, fontBig));
0329: sqlEditor.setFont(new Font("Courier New", Font.PLAIN, fontBig));
0330: editor.setForeground(Color.BLACK);
0331: sqlEditor.setForeground(Color.BLACK);
0332: editor.addCaretListener(this );
0333: list.addListSelectionListener(this );
0334: leftPanel.add(new JScrollPane(list));
0335: rightPanel.setLayout(new BorderLayout());
0336: //rightPanel.add(editor);
0337: miConn.addActionListener(this );
0338: miCommit.addActionListener(this );
0339: miRollback.addActionListener(this );
0340: miAbout.addActionListener(this );
0341: miLicense.addActionListener(this );
0342: miHelp.addActionListener(this );
0343: miSystem.addActionListener(this );
0344: miMetal.addActionListener(this );
0345: miMotif.addActionListener(this );
0346: miHelp.setActionCommand("Help");
0347: miSystem.setActionCommand("SystemLF");
0348: miMetal.setActionCommand("MetalLF");
0349: miMotif.setActionCommand("MotifLF");
0350: miSQLEd.addActionListener(this );
0351: miSQLEd.setActionCommand("SQLEditor");
0352: miDBViewer.addActionListener(this );
0353: miDBViewer.setActionCommand("ShowObjectViewer");
0354: btnConn.addActionListener(this );
0355: btnCommit.addActionListener(this );
0356: btnRollback.addActionListener(this );
0357: addWindowListener(this );
0358: miDisc.addActionListener(this );
0359: btnDisc.addActionListener(this );
0360: btnAbout.addActionListener(this );
0361: btnLicense.addActionListener(this );
0362: btnHelp.addActionListener(this );
0363: btnSQLEd.addActionListener(this );
0364: btnObjViewer.addActionListener(this );
0365: btnRun.addActionListener(this );
0366: btnMetalLF.addActionListener(this );
0367: btnMotifLF.addActionListener(this );
0368: btnSystemLF.addActionListener(this );
0369: dbObjects = null;
0370: cbDBObjects.addItemListener(this );
0371:
0372: tabDescVector = new Vector(0, 1);
0373: colHdr = new Vector(0, 1);
0374: colHdr.addElement("COLUMN NAME");
0375: colHdr.addElement("DATA TYPE");
0376: colHdr.addElement("LENGTH");
0377: colHdr.addElement("NULL");
0378: colHdr.addElement("DEFAULT");
0379: tableColumns = new Vector(0, 1);
0380: tableColumns.addElement("Col1");
0381: tableColumns.addElement("Col1");
0382: tableColumns.addElement("Col1");
0383: tableColumns.addElement("Col1");
0384: tabModel = new ReadOnlyTableModel(null, colHdr);
0385: tableDetails = new JTable(tabModel);
0386: tableDetails
0387: .setFont(new Font(fontFamily, Font.BOLD, fontSmall));
0388: JTableHeader tabDescTabHdr = tableDetails.getTableHeader();
0389: tabDescTabHdr
0390: .setFont(new Font(fontFamily, Font.BOLD, fontSmall));
0391: tabDescTabHdr.setForeground(Color.WHITE);
0392: tabDescTabHdr.setBackground(new Color(0, 0, 100));
0393: tableDetails.setShowGrid(false);
0394: tableDetails.setCellSelectionEnabled(true);
0395: JTextField cellLabel = new JTextField();
0396: cellLabel.setEnabled(false);
0397: rightPanel.setOpaque(true);
0398: DefaultTableCellRenderer centerColumn = new DefaultTableCellRenderer();
0399: centerColumn.setHorizontalAlignment(JTextField.CENTER);
0400: tableDetails.getColumnModel().getColumn(2).setCellRenderer(
0401: centerColumn);
0402: tableDetails.getColumnModel().getColumn(3).setCellRenderer(
0403: centerColumn);
0404: tableDetails.getColumnModel().getColumn(4).setCellRenderer(
0405: centerColumn);
0406: tableDetails.getColumnModel().getColumn(0).setPreferredWidth(
0407: (int) (0.600 * tableDetails.getPreferredSize()
0408: .getWidth()));
0409: tableDetails.getColumnModel().getColumn(1).setPreferredWidth(
0410: (int) (0.080 * tableDetails.getPreferredSize()
0411: .getWidth()));
0412: tableDetails.getColumnModel().getColumn(2).setPreferredWidth(
0413: (int) (0.010 * tableDetails.getPreferredSize()
0414: .getWidth()));
0415: tableDetails.getColumnModel().getColumn(3).setPreferredWidth(
0416: (int) (0.010 * tableDetails.getPreferredSize()
0417: .getWidth()));
0418: tableDetails.getColumnModel().getColumn(4).setPreferredWidth(
0419: (int) (0.300 * tableDetails.getPreferredSize()
0420: .getWidth()));
0421:
0422: colHdrSeq = new Vector(0, 1);
0423: colHdrSeq.addElement("MINIMUM VALUE");
0424: colHdrSeq.addElement("MAXIMUM VALUE");
0425: colHdrSeq.addElement("INCREMENT BY");
0426: colHdrSeq.addElement("LAST NUMBER");
0427: tabModelSeq = new ReadOnlyTableModel(null, colHdrSeq);
0428: seqDetails = new JTable(tabModelSeq);
0429: seqDetails.setFont(new Font(fontFamily, Font.BOLD, fontSmall));
0430: JTableHeader seqTabHdr = seqDetails.getTableHeader();
0431: seqTabHdr.setFont(new Font(fontFamily, Font.BOLD, fontSmall));
0432: seqTabHdr.setForeground(Color.WHITE);
0433: seqTabHdr.setBackground(new Color(0, 0, 100));
0434: seqDetails.setShowGrid(false);
0435: seqDetails.setCellSelectionEnabled(true);
0436: seqDetails.getColumnModel().getColumn(0).setCellRenderer(
0437: centerColumn);
0438: seqDetails.getColumnModel().getColumn(1).setCellRenderer(
0439: centerColumn);
0440: seqDetails.getColumnModel().getColumn(2).setCellRenderer(
0441: centerColumn);
0442: seqDetails.getColumnModel().getColumn(3).setCellRenderer(
0443: centerColumn);
0444:
0445: colHdrIndx = new Vector(0, 1);
0446: colHdrIndx.addElement("COLUMN NAME");
0447: colHdrIndx.addElement("COLUMN POSITION");
0448: tabModelIndx = new ReadOnlyTableModel(null, colHdrIndx);
0449: indxDetails = new JTable(tabModelIndx);
0450: indxDetails.setFont(new Font(fontFamily, Font.BOLD, fontSmall));
0451: JTableHeader indxTabHdr = indxDetails.getTableHeader();
0452: indxTabHdr.setFont(new Font(fontFamily, Font.BOLD, fontSmall));
0453: indxTabHdr.setForeground(Color.WHITE);
0454: indxTabHdr.setBackground(new Color(0, 0, 100));
0455: indxDetails.setShowGrid(false);
0456: indxDetails.setCellSelectionEnabled(true);
0457: indxDetails.getColumnModel().getColumn(1).setCellRenderer(
0458: centerColumn);
0459: indxDetails.getColumnModel().getColumn(1)
0460: .setPreferredWidth(
0461: (int) (0.95 * indxDetails.getPreferredSize()
0462: .getWidth()));
0463:
0464: colHdrSyn = new Vector(0, 1);
0465: colHdrSyn.addElement("OWNER");
0466: colHdrSyn.addElement("OBJECT NAME");
0467: colHdrSyn.addElement("OBJECT OWNER");
0468: tabModelSyn = new ReadOnlyTableModel(null, colHdrSyn);
0469: synDetails = new JTable(tabModelSyn);
0470: synDetails.setFont(new Font(fontFamily, Font.BOLD, fontSmall));
0471: JTableHeader synTabHdr = synDetails.getTableHeader();
0472: synTabHdr.setFont(new Font(fontFamily, Font.BOLD, fontSmall));
0473: synTabHdr.setForeground(Color.WHITE);
0474: synTabHdr.setBackground(new Color(0, 0, 100));
0475: synDetails.setShowGrid(false);
0476: synDetails.setCellSelectionEnabled(true);
0477:
0478: btnNextRecords
0479: .setFont(new Font("Lucida Console", Font.BOLD, 14));
0480: btnPrevRecords
0481: .setFont(new Font("Lucida Console", Font.BOLD, 14));
0482: btnDataFilter
0483: .setFont(new Font("Lucida Console", Font.BOLD, 14));
0484: btnDataSort.setFont(new Font("Lucida Console", Font.BOLD, 14));
0485: btnNextRecords.setForeground(new Color(0, 0, 128));
0486: btnPrevRecords.setForeground(new Color(0, 0, 128));
0487: btnDataFilter.setForeground(new Color(0, 0, 128));
0488: btnDataSort.setForeground(new Color(0, 0, 128));
0489: //btnNextRecords.setBackground(new Color(0,0,100));
0490: //btnPrevRecords.setBackground(new Color(0,0,100));
0491: //btnDataFilter.setBackground(new Color(0,0,100));
0492: //btnDataSort.setBackground(new Color(0,0,100));
0493: btnNextRecords.setToolTipText("Next "
0494: + Constants.PAGING_RECORD_COUNT);
0495: btnPrevRecords.setToolTipText("Previous "
0496: + Constants.PAGING_RECORD_COUNT);
0497: btnDataFilter.setToolTipText("Data Filter");
0498: btnDataSort.setToolTipText("Sort Data");
0499: btnNextRecords.setActionCommand("Next");
0500: btnPrevRecords.setActionCommand("Previous");
0501: btnDataFilter.setActionCommand("FilterData");
0502: btnDataSort.setActionCommand("SortData");
0503: btnNextRecords.addActionListener(this );
0504: btnPrevRecords.addActionListener(this );
0505: btnDataFilter.addActionListener(this );
0506: btnDataSort.addActionListener(this );
0507:
0508: populateKeyWords();
0509:
0510: //JScrollPane rightSP = new JScrollPane(rightPanel);
0511: splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
0512: leftPanel, rightPanel);
0513: splitPane.setOneTouchExpandable(true);
0514: //cont.add(splitPane);
0515:
0516: panPLSQLEditorTop = new JPanel(new FlowLayout(FlowLayout.LEFT));
0517: btnCompile = new JButton("C");
0518: btnCompile.setFont(new Font("Lucida Console", Font.BOLD, 14));
0519: btnCompile.setForeground(new Color(0, 0, 128));
0520: //btnCompile.setBackground(new Color(0,0,100));
0521: panPLSQLEditorTop.add(btnCompile);
0522: btnCompile.setActionCommand("Compile");
0523: btnCompile.addActionListener(this );
0524: btnCompile.setToolTipText("Compile");
0525:
0526: currentTabSelection = 0;
0527:
0528: currTabRowCount = 0;
0529:
0530: objViewerFrame = new JInternalFrame("Object Viewer", true,
0531: false, true, false);
0532: objViewerFrame.getContentPane().add(splitPane);
0533: objViewerFrame.setBounds(5, 5, 1000, 625);
0534: objViewerFrame.setVisible(true);
0535: objViewerFrame.isMaximizable();
0536: objViewerFrame.isResizable();
0537: cont.add(desktop);
0538:
0539: miConn.setEnabled(true);
0540: miDisc.setEnabled(false);
0541: miCommit.setEnabled(false);
0542: miRollback.setEnabled(false);
0543: /*ImageIcon icon = new ImageIcon("vela.jpg");
0544: JLabel l = new JLabel(icon);
0545: l.setBounds(0,-300,icon.getIconWidth(),icon.getIconHeight());
0546: desktop.add(l, new Integer(Integer.MIN_VALUE)); */
0547: seSouthPanel = new JPanel(new BorderLayout());
0548: seNorthPanel = new JPanel(new BorderLayout());
0549: JToolBar seToolbar = new JToolBar();
0550: seToolbar.add(btnRun);
0551: seNorthPanel.add(seToolbar, BorderLayout.NORTH);
0552: seNorthPanel.add(new JScrollPane(sqlEditor));
0553: textSEResult = new JEditorPane();
0554: textSEResult.setEnabled(false);
0555: seSouthPanel.add(textSEResult);
0556: textSEResult.setFont(new Font(fontFamily, Font.BOLD, fontBig));
0557: seSouthPanel.setBorder(BorderFactory
0558: .createTitledBorder("Output"));
0559: btnSystemLF.setEnabled(false);
0560: miSystem.setEnabled(false);
0561: }
0562:
0563: public static void main(String[] args) {
0564: /*System.setProperty("java.ext.dirs","C:\\VenLak\\lib");
0565: try {
0566: System.out.println("Loding Driver... = ");
0567: System.out.println("URL = "+new URL("file:///C:/VenLak/lib/classes12.zip"));
0568: ClassLoader a1 = ClassLoader.getSystemClassLoader();
0569: System.out.println("ClassLoader = "+a1);
0570: Class c1 = a1.loadClass("oracle.jdbc.driver.OracleDriver");
0571: Class.forName("oracle.jdbc.driver.OracleDriver");
0572: System.out.println("DriverClass = "+c1);
0573: //} catch (MalformedURLException e) {
0574: } catch (Exception e) {
0575: // TODO Auto-generated catch block
0576: e.printStackTrace();
0577: } */
0578: String laf = UIManager.getSystemLookAndFeelClassName();
0579: //String laf = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
0580: //String laf = "javax.swing.plaf.metal.MetalLookAndFeel";
0581: //String laf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
0582: //String laf = "javax.swing.plaf.metal.MetalTheme";
0583: //String laf = "javax.swing.plaf.metal.OceanTheme";
0584: /*LookAndFeelInfo lf[] = UIManager.getInstalledLookAndFeels();
0585: boolean metalLFInstalled = false;
0586: for(int i=0; i<lf.length;i++)
0587: {
0588: if(lf[i].getClassName()!=null && lf[i].getClassName().equals("javax.swing.plaf.metal.MetalLookAndFeel"))
0589: {
0590: metalLFInstalled = true;
0591: break;
0592: }
0593: }
0594: if(metalLFInstalled)
0595: laf = "javax.swing.plaf.metal.MetalLookAndFeel";*/
0596: try {
0597: UIManager.setLookAndFeel(laf);
0598: //UIManager.setLookAndFeel(new SynthLookAndFeel());
0599: } catch (UnsupportedLookAndFeelException exc) {
0600: System.out.println("Unsupported: " + laf);
0601: } catch (Exception exc) {
0602: System.out.println("Error loading: " + laf);
0603: }
0604: MainFrame frame = new MainFrame();
0605: frame.setResizable(true);
0606: frame.setBounds(50, 25, 900, 700);
0607: frame.setTitle("Vela - Database Objects");
0608: frame.setVisible(true);
0609: frame.setIconImage(new ImageIcon("vela.jpg").getImage());
0610: }
0611:
0612: public void actionPerformed(ActionEvent ae) {
0613: setCursor(new Cursor(Cursor.WAIT_CURSOR));
0614: try {
0615: statusBar.setText("");
0616: positionBar.setText("");
0617: if (ae.getActionCommand().equalsIgnoreCase("Connect")) {
0618: properties = new Properties();
0619: try {
0620: properties.load(new FileInputStream(
0621: "Vela.properties"));
0622: } catch (Exception ex) {
0623: ex.printStackTrace();
0624: }
0625: String dbms = (String) properties.get("DBMS");
0626: if (dbms != null && dbms.equalsIgnoreCase("Oracle"))
0627: dbManager = OraDBManager.getInstance();
0628: ConnectionParams connParams = new ConnectionParams(
0629: this , properties, dbManager);
0630: connParams.setVisible(true);
0631: int retStatus = connParams.getRetStatus();
0632: if (retStatus == 1)
0633: return;
0634: ConnectionProperties currConnProps = connParams
0635: .getSelectedConnProps();
0636: setTitle("Vela - Connected to "
0637: + currConnProps.getDbName());
0638: Hashtable hDBObjects = dbManager.getDBObjects();
0639: dbObjects = (ArrayList) hDBObjects.get("DB_OBJECTS");
0640: allDBObjectNames = (ArrayList) hDBObjects
0641: .get("DB_OBJECT_NAMES");
0642: initDBStructure();
0643: if (dbObjects != null && dbObjects.size() > 0) {
0644: desktop.add(objViewerFrame);
0645: initUI();
0646: statusBar.setDisabledTextColor(Color.BLACK);
0647: statusBar.setText("Connected to the database.");
0648: btnConn.setActionCommand("Disconnect");
0649: btnConn.setText("-()-");
0650: btnConn.setToolTipText("Disconnect");
0651: btnConn.setForeground(new Color(0, 128, 0));
0652: miConn.setEnabled(false);
0653: miDisc.setEnabled(true);
0654: miCommit.setEnabled(true);
0655: miRollback.setEnabled(true);
0656: btnSQLEd.setEnabled(true);
0657: btnObjViewer.setEnabled(true);
0658: }
0659: repaint();
0660: } else if (ae.getActionCommand().equalsIgnoreCase(
0661: "Disconnect")) {
0662: dbManager.cleanup();
0663: dbObjects = new ArrayList(0);
0664: statusBar.setDisabledTextColor(Color.BLUE);
0665: statusBar.setText("Not Connected to the database.");
0666: setTitle("Vela - Database objects");
0667: rightPanel.removeAll();
0668: cbDBObjects.setSelectedItem(null);
0669: cbDBObjects.removeAllItems();
0670: rightPanel.repaint();
0671: listModel.clear();
0672: btnConn.setActionCommand("Connect");
0673: btnConn.setText("-( )-");
0674: btnConn.setToolTipText("Connect");
0675: btnConn.setForeground(new Color(128, 0, 0));
0676: desktop.remove(objViewerFrame);
0677: miConn.setEnabled(true);
0678: miDisc.setEnabled(false);
0679: miCommit.setEnabled(false);
0680: miRollback.setEnabled(false);
0681: btnSQLEd.setEnabled(false);
0682: btnObjViewer.setEnabled(false);
0683: if (sqlEditorFrame != null)
0684: sqlEditorFrame.hide();
0685: repaint();
0686: } else if (ae.getActionCommand()
0687: .equalsIgnoreCase("Compile")) {
0688: Document doc = editor.getDocument();
0689: String result = "Compilation unsucessful.";
0690: try {
0691: result = dbManager.compile(doc.getText(0, doc
0692: .getLength()), (String) list
0693: .getSelectedValue());
0694: } catch (BadLocationException ex) {
0695: //Never Mind
0696: }
0697: DBObject dbObject = dbStructure
0698: .getDBObject((String) list.getSelectedValue());
0699: if (!result.startsWith("Successfully")) {
0700: dbObject.setObjectStatus("INVALID");
0701: statusBar.setDisabledTextColor(Color.RED);
0702: statusBar.setText("Compilation failed.");
0703: MessageBox.showMessage(this , "Compilation Error",
0704: true, result);
0705: } else {
0706: dbObject.setObjectStatus("VALID");
0707: statusBar.setDisabledTextColor(Color.BLACK);
0708: statusBar.setText(result);
0709: }
0710: } else if (ae.getActionCommand().equalsIgnoreCase("Next")) {
0711: String selectedObject = (String) list
0712: .getSelectedValue();
0713: tableDataStartRowNum = tableDataStartRowNum
0714: + Constants.PAGING_RECORD_COUNT;
0715: tableDataEndRowNum = tableDataEndRowNum
0716: + Constants.PAGING_RECORD_COUNT;
0717: setTableData(selectedObject, dataDesc,
0718: tableDataStartRowNum, tableDataEndRowNum);
0719: tabbedPaneTable.setSelectedIndex(1);
0720: } else if (ae.getActionCommand().equalsIgnoreCase(
0721: "Previous")) {
0722: String selectedObject = (String) list
0723: .getSelectedValue();
0724: tableDataStartRowNum = tableDataStartRowNum
0725: - Constants.PAGING_RECORD_COUNT;
0726: tableDataEndRowNum = tableDataEndRowNum
0727: - Constants.PAGING_RECORD_COUNT;
0728: setTableData(selectedObject, dataDesc,
0729: tableDataStartRowNum, tableDataEndRowNum);
0730: tabbedPaneTable.setSelectedIndex(1);
0731: } else if (ae.getActionCommand().equalsIgnoreCase(
0732: "FilterData")) {
0733: DBObject tableObj = dbStructure.getTable((String) list
0734: .getSelectedValue());
0735: String dataFilterOld = tableObj.getTableFilter();
0736: DataFilter df = new DataFilter(this , tableObj,
0737: "Filter Data");
0738: df.setVisible(true);
0739: String dataFilterNew = tableObj.getTableFilter();
0740: if ((dataFilterOld != null && !dataFilterOld.trim()
0741: .equalsIgnoreCase(dataFilterNew))
0742: || (dataFilterNew != null && !dataFilterNew
0743: .trim().equalsIgnoreCase(dataFilterOld))) {
0744: tableDataStartRowNum = 1;
0745: tableDataEndRowNum = Constants.PAGING_RECORD_COUNT;
0746: setTableData((String) list.getSelectedValue(),
0747: dataDesc, tableDataStartRowNum,
0748: tableDataEndRowNum);
0749: tabbedPaneTable.setSelectedIndex(1);
0750: }
0751: } else if (ae.getActionCommand().equalsIgnoreCase(
0752: "SortData")) {
0753: DBObject tableObj = dbStructure.getTable((String) list
0754: .getSelectedValue());
0755: String dataSortOld = tableObj.getTableSort();
0756: DataFilter df = new DataFilter(this , tableObj,
0757: "Sort Data");
0758: df.setVisible(true);
0759: String dataSortNew = tableObj.getTableSort();
0760: if ((dataSortOld != null && !dataSortOld.trim()
0761: .equalsIgnoreCase(dataSortNew))
0762: || (dataSortNew != null && !dataSortNew.trim()
0763: .equalsIgnoreCase(dataSortOld))) {
0764: tableDataStartRowNum = 1;
0765: tableDataEndRowNum = Constants.PAGING_RECORD_COUNT;
0766: setTableData((String) list.getSelectedValue(),
0767: dataDesc, tableDataStartRowNum,
0768: tableDataEndRowNum);
0769: tabbedPaneTable.setSelectedIndex(1);
0770: }
0771: } else if (ae.getActionCommand().equalsIgnoreCase("About")) {
0772: About.showMessage(this , "About Vela", true);
0773: } else if (ae.getActionCommand()
0774: .equalsIgnoreCase("License")) {
0775: License.showMessage(this , "Vela - License", true);
0776: } else if (ae.getActionCommand().equalsIgnoreCase("Help")) {
0777: Help.showMessage(this , "Vela - Help", true);
0778: } else if (ae.getActionCommand().equalsIgnoreCase(
0779: "SQLEditor")) {
0780: if (sqlEditorFrame != null) {
0781: sqlEditorFrame.setVisible(true);
0782: sqlEditorFrame.moveToFront();
0783: } else {
0784: sqlEditorFrame = new JInternalFrame("SQL Editor",
0785: true, false, true, false);
0786: JSplitPane seSplitPane = new JSplitPane(
0787: JSplitPane.VERTICAL_SPLIT, seNorthPanel,
0788: seSouthPanel);
0789: seSplitPane.setOneTouchExpandable(true);
0790: sqlEditorFrame.getContentPane().add(seSplitPane);
0791: sqlEditor
0792: .setPreferredSize(new Dimension(1000, 400));
0793: sqlEditorFrame.setBounds(5, 5, 1000, 800);
0794: sqlEditorFrame.setVisible(true);
0795: desktop.add(sqlEditorFrame);
0796: sqlEditorFrame.toFront();
0797: }
0798: } else if (ae.getActionCommand().equalsIgnoreCase("RunSQL")) {
0799: Document doc = sqlEditor.getDocument();
0800: String script = null;
0801: try {
0802: script = sqlEditor.getSelectedText();
0803: if (script == null || script.trim().length() == 0)
0804: script = doc.getText(0, doc.getLength());
0805: } catch (BadLocationException e) {
0806: e.printStackTrace();
0807: }
0808: System.out.println("script = " + script);
0809: if (script == null || script.trim().length() == 0) {
0810: JOptionPane
0811: .showMessageDialog(this ,
0812: "Please key-in your SQL or PL/SQL script in the editor to run the script.");
0813: } else if (!script.trim().toUpperCase().startsWith(
0814: "CREATE")
0815: && !script.trim().toUpperCase().startsWith(
0816: "ALTER")
0817: && !script.trim().toUpperCase().startsWith(
0818: "DROP")
0819: && !script.trim().toUpperCase().startsWith(
0820: "INSERT")
0821: && !script.trim().toUpperCase().startsWith(
0822: "UPDATE")
0823: && !script.trim().toUpperCase().startsWith(
0824: "DELETE")
0825: && !script.trim().toUpperCase().startsWith(
0826: "SELECT")) {
0827: JOptionPane.showMessageDialog(this ,
0828: "Not a valid SQL or PL/SQL statement.");
0829: } else if (script.trim().toUpperCase().startsWith(
0830: "SELECT")) {
0831: Hashtable hTabData = null;
0832: try {
0833: hTabData = dbManager.getQueryData(script);
0834: } catch (SQLException sqlEx) {
0835: JOptionPane.showMessageDialog(this , sqlEx
0836: .getMessage());
0837: } catch (Exception ex) {
0838: JOptionPane
0839: .showMessageDialog(this ,
0840: "System is unable to execute the script.");
0841: ex.printStackTrace();
0842: }
0843: if (hTabData != null) {
0844: Vector tableDataVectorSE = (Vector) hTabData
0845: .get("DATA");
0846: Vector vColumns = (Vector) hTabData
0847: .get("COLUMNS");
0848: Vector colSizes = (Vector) hTabData
0849: .get("COLUMN_SIZES");
0850: String recCount = (String) hTabData
0851: .get("RECORD_COUNT");
0852: int retrievedRecCount = tableDataVectorSE
0853: .size();
0854: int totRecCount = 0;
0855: try {
0856: totRecCount = new Integer(recCount)
0857: .intValue();
0858: } catch (Exception ex) {
0859: //Its OK
0860: }
0861: tabDataModelSE = new ReadOnlyTableModel(null,
0862: vColumns);
0863: tabDataModelSE.setDataVector(tableDataVectorSE,
0864: vColumns);
0865: JTable tableDataSE = new JTable(tabDataModelSE);
0866: tableDataSE
0867: .setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
0868: setDataTableColSizes(tableDataSE, colSizes,
0869: vColumns);
0870: JTableHeader tabDataTabHdrSE = tableDataSE
0871: .getTableHeader();
0872: tabDataTabHdrSE.setFont(new Font(fontFamily,
0873: Font.BOLD, 9));
0874: tabDataTabHdrSE.setForeground(Color.WHITE);
0875: tabDataTabHdrSE.setBackground(new Color(0, 0,
0876: 100));
0877: tableDataSE.setBackground(new Color(255, 255,
0878: 235));
0879: seSouthPanel.removeAll();
0880: seSouthPanel.add(new JScrollPane(tableDataSE));
0881: statusBar.setDisabledTextColor(Color.BLACK);
0882: if (retrievedRecCount < totRecCount)
0883: statusBar
0884: .setText(retrievedRecCount
0885: + " records retrieved out of a total of "
0886: + totRecCount + " records.");
0887: else
0888: statusBar.setText(retrievedRecCount
0889: + " records found.");
0890: } else {
0891: statusBar.setDisabledTextColor(Color.RED);
0892: statusBar.setText("No data found.");
0893: }
0894: seSouthPanel.setVisible(false);
0895: seSouthPanel.setVisible(true);
0896: } else {
0897: seSouthPanel.removeAll();
0898: seSouthPanel.add(textSEResult);
0899: String result = "Script is executed successfully.";
0900: try {
0901: result = dbManager.compile(script,
0902: (String) list.getSelectedValue());
0903: } catch (Exception ex) {
0904: //Never Mind
0905: }
0906: if (!result.startsWith("Successfully")) {
0907: statusBar.setDisabledTextColor(Color.RED);
0908: statusBar.setText("Compilation failed.");
0909: textSEResult.setDisabledTextColor(new Color(
0910: 128, 0, 0));
0911: textSEResult.setText(result);
0912: } else {
0913: statusBar.setDisabledTextColor(Color.BLACK);
0914: textSEResult
0915: .setText("Script is executed successfully.");
0916: statusBar
0917: .setText("Script is executed successfully.");
0918: textSEResult.setDisabledTextColor(Color.BLACK);
0919: }
0920: seSouthPanel.setVisible(false);
0921: seSouthPanel.setVisible(true);
0922: }
0923: } else if (ae.getActionCommand().equalsIgnoreCase(
0924: "ShowObjectViewer")) {
0925: objViewerFrame.toFront();
0926: } else if (ae.getActionCommand().equalsIgnoreCase("Commit")) {
0927: dbManager.commit();
0928: } else if (ae.getActionCommand().equalsIgnoreCase(
0929: "Rollback")) {
0930: dbManager.rollback();
0931: } else if (ae.getActionCommand()
0932: .equalsIgnoreCase("MetalLF")) {
0933: try {
0934: UIManager
0935: .setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
0936: SwingUtilities.updateComponentTreeUI(this );
0937: btnMetalLF.setEnabled(false);
0938: btnMotifLF.setEnabled(true);
0939: btnSystemLF.setEnabled(true);
0940: miMetal.setEnabled(false);
0941: miMotif.setEnabled(true);
0942: miSystem.setEnabled(true);
0943: } catch (Exception ex) {
0944: ex.printStackTrace();
0945: }
0946: } else if (ae.getActionCommand().equalsIgnoreCase(
0947: "SystemLF")) {
0948: try {
0949: UIManager.setLookAndFeel(UIManager
0950: .getSystemLookAndFeelClassName());
0951: SwingUtilities.updateComponentTreeUI(this );
0952: btnMetalLF.setEnabled(true);
0953: btnMotifLF.setEnabled(true);
0954: btnSystemLF.setEnabled(false);
0955: miMetal.setEnabled(true);
0956: miMotif.setEnabled(true);
0957: miSystem.setEnabled(false);
0958: } catch (Exception ex) {
0959: ex.printStackTrace();
0960: }
0961: } else if (ae.getActionCommand()
0962: .equalsIgnoreCase("MotifLF")) {
0963: try {
0964: UIManager
0965: .setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
0966: SwingUtilities.updateComponentTreeUI(this );
0967: btnMetalLF.setEnabled(true);
0968: btnMotifLF.setEnabled(false);
0969: btnSystemLF.setEnabled(true);
0970: miMetal.setEnabled(true);
0971: miMotif.setEnabled(false);
0972: miSystem.setEnabled(true);
0973: } catch (Exception ex) {
0974: ex.printStackTrace();
0975: }
0976: }
0977: } finally {
0978: setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
0979: }
0980: }
0981:
0982: /**
0983: * Invoked the first time a window is made visible.
0984: */
0985: public void windowOpened(WindowEvent e) {
0986: }
0987:
0988: /**
0989: * Invoked when the user attempts to close the window
0990: * from the window's system menu. If the program does not
0991: * explicitly hide or dispose the window while processing
0992: * this event, the window close operation will be cancelled.
0993: */
0994: public void windowClosing(WindowEvent e) {
0995: setCursor(new Cursor(Cursor.WAIT_CURSOR));
0996: try {
0997: if (dbManager != null && dbManager.isConnectionOpen()) {
0998: Object options[] = { "Commit", "Rollback" };
0999: int retStatus = JOptionPane
1000: .showOptionDialog(
1001: this ,
1002: "Click on \"Commit\" to save the changes done to the table data in this session.\nOtherwise click on \"Rollback\".\nClick on \"Rollback\" if no changes are done to the table data in this session.",
1003: "Save/Undo Table Data Changes",
1004: JOptionPane.DEFAULT_OPTION,
1005: JOptionPane.QUESTION_MESSAGE, null,
1006: options, options[1]);
1007: if (retStatus == 0) {
1008: dbManager.commit();
1009: } else {
1010: dbManager.rollback();
1011: }
1012: dbManager.cleanup();
1013: }
1014: System.exit(0);
1015: } finally {
1016: setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
1017: }
1018: }
1019:
1020: /**
1021: * Invoked when a window has been closed as the result
1022: * of calling dispose on the window.
1023: */
1024: public void windowClosed(WindowEvent e) {
1025: }
1026:
1027: /**
1028: * Invoked when a window is changed from a normal to a
1029: * minimized state. For many platforms, a minimized window
1030: * is displayed as the icon specified in the window's
1031: * iconImage property.
1032: * @see java.awt.Frame#setIconImage
1033: */
1034: public void windowIconified(WindowEvent e) {
1035: }
1036:
1037: /**
1038: * Invoked when a window is changed from a minimized
1039: * to a normal state.
1040: */
1041: public void windowDeiconified(WindowEvent e) {
1042: }
1043:
1044: /**
1045: * Invoked when the Window is set to be the active Window. Only a Frame or
1046: * a Dialog can be the active Window. The native windowing system may
1047: * denote the active Window or its children with special decorations, such
1048: * as a highlighted title bar. The active Window is always either the
1049: * focused Window, or the first Frame or Dialog that is an owner of the
1050: * focused Window.
1051: */
1052: public void windowActivated(WindowEvent e) {
1053: }
1054:
1055: /**
1056: * Invoked when a Window is no longer the active Window. Only a Frame or a
1057: * Dialog can be the active Window. The native windowing system may denote
1058: * the active Window or its children with special decorations, such as a
1059: * highlighted title bar. The active Window is always either the focused
1060: * Window, or the first Frame or Dialog that is an owner of the focused
1061: * Window.
1062: */
1063: public void windowDeactivated(WindowEvent e) {
1064: }
1065:
1066: public void initDBStructure() {
1067: if (dbObjects == null || dbObjects.size() == 0)
1068: return;
1069: TreeMap tables = new TreeMap();
1070: TreeMap indexes = new TreeMap();
1071: TreeMap functions = new TreeMap();
1072: TreeMap sequences = new TreeMap();
1073: TreeMap procedures = new TreeMap();
1074: TreeMap triggers = new TreeMap();
1075: TreeMap views = new TreeMap();
1076: TreeMap synonyms = new TreeMap();
1077: TreeMap packages = new TreeMap();
1078: TreeMap allDBObjects = new TreeMap();
1079: int szDBObjects = dbObjects.size();
1080: for (int i = 0; i < szDBObjects; i++) {
1081: DBObject dbObject = (DBObject) dbObjects.get(i);
1082: String objectName = dbObject.getObjectName();
1083: String objectType = dbObject.getObjectType();
1084: if (objectType.equalsIgnoreCase("TABLE"))
1085: tables.put(objectName, dbObject);
1086: if (objectType.equalsIgnoreCase("FUNCTION"))
1087: functions.put(objectName, dbObject);
1088: if (objectType.equalsIgnoreCase("INDEX"))
1089: indexes.put(objectName, dbObject);
1090: if (objectType.equalsIgnoreCase("SEQUENCE"))
1091: sequences.put(objectName, dbObject);
1092: if (objectType.equalsIgnoreCase("PROCEDURE"))
1093: procedures.put(objectName, dbObject);
1094: if (objectType.equalsIgnoreCase("TRIGGER"))
1095: triggers.put(objectName, dbObject);
1096: if (objectType.equalsIgnoreCase("VIEW"))
1097: views.put(objectName, dbObject);
1098: if (objectType.equalsIgnoreCase("SYNONYM"))
1099: synonyms.put(objectName, dbObject);
1100: if (objectType.equalsIgnoreCase("PACKAGE"))
1101: packages.put(objectName, dbObject);
1102: allDBObjects.put(objectName, dbObject);
1103: }
1104: dbStructure = new DBStructure();
1105: dbStructure.setFunctions(functions);
1106: dbStructure.setTables(tables);
1107: dbStructure.setIndexes(indexes);
1108: dbStructure.setSequences(sequences);
1109: dbStructure.setProcedures(procedures);
1110: dbStructure.setTriggers(triggers);
1111: dbStructure.setViews(views);
1112: dbStructure.setSynonyms(synonyms);
1113: dbStructure.setPackages(packages);
1114: dbStructure.setAllDBObjectsMap(allDBObjects);
1115: }
1116:
1117: public void initUI() {
1118: //desktop.add(frameDBViewer);
1119: //frameDBViewer.moveToFront();
1120: //frameDBViewer.setVisible(true);
1121: //cont = frameDBViewer.getContentPane();
1122: //JPanel panDBViewer = new JPanel(new BorderLayout());
1123: //frameDBViewer.add(panDBViewer);
1124: //panDBViewer.add(splitPane);
1125: cb.removeAllElements();
1126: for (int i = 0; i < objectTypes.length; i++) {
1127: cb.addElement(objectTypes[i]);
1128: }
1129: cb.setSelectedItem("TABLE");
1130: }
1131:
1132: public void itemStateChanged(ItemEvent e) {
1133: setCursor(new Cursor(Cursor.WAIT_CURSOR));
1134: try {
1135: statusBar.setText("");
1136: positionBar.setText("");
1137: if (e.getSource().equals(cbDBObjects)
1138: && e.getStateChange() == ItemEvent.SELECTED) {
1139: rightPanel.removeAll();
1140: listModel.removeAllElements();
1141: String objectType = (String) cbDBObjects
1142: .getSelectedItem();
1143: System.out.println("objectType = " + objectType);
1144: TreeMap dbObjects = dbStructure
1145: .getDBObjects(objectType);
1146: System.out.println("dbObjects = " + dbObjects);
1147: Iterator iter = dbObjects.keySet().iterator();
1148: while (iter.hasNext()) {
1149: String objectName = (String) iter.next();
1150: listModel.addElement(objectName);
1151: }
1152: }
1153: } finally {
1154: setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
1155: }
1156: }
1157:
1158: public void valueChanged(ListSelectionEvent e) {
1159: setCursor(new Cursor(Cursor.WAIT_CURSOR));
1160: try {
1161: statusBar.setText("");
1162: positionBar.setText("");
1163: statusBar.setDisabledTextColor(Color.BLACK);
1164: if (e.getSource().equals(list) && !e.getValueIsAdjusting()) {
1165: String selectedObject = (String) list
1166: .getSelectedValue();
1167: String objType = (String) cbDBObjects.getSelectedItem();
1168: if (objType == null || selectedObject == null)
1169: return;
1170: if (objType.equalsIgnoreCase("FUNCTION")
1171: || objType.equalsIgnoreCase("PROCEDURE")
1172: || objType.equalsIgnoreCase("PACKAGE")) {
1173: ArrayList source = dbManager.getSource(
1174: selectedObject, objType);
1175: rightPanel.removeAll();
1176: rightPanel.add(panPLSQLEditorTop,
1177: BorderLayout.NORTH);
1178: rightPanel.add(spEditor);
1179: setSourceToEditor(editor, source);
1180: splitPane.setVisible(false);
1181: splitPane.setVisible(true);
1182: String objectStatus = "";
1183: if (objType.equalsIgnoreCase("FUNCTION"))
1184: objectStatus = dbStructure.getFunction(
1185: selectedObject).getObjectStatus();
1186: if (objType.equalsIgnoreCase("PROCEDURE"))
1187: objectStatus = dbStructure.getProcedure(
1188: selectedObject).getObjectStatus();
1189: if (objType.equalsIgnoreCase("PACKAGE"))
1190: objectStatus = dbStructure.getPackage(
1191: selectedObject).getObjectStatus();
1192: if (objectStatus.equalsIgnoreCase("VALID")) {
1193: statusBar.setText(objectStatus);
1194: statusBar.setDisabledTextColor(Color.BLACK);
1195: } else {
1196: statusBar.setText(objectStatus);
1197: statusBar.setDisabledTextColor(Color.RED);
1198: }
1199: editor.requestFocus(true);
1200: }
1201: if (objType != null
1202: && objType.equalsIgnoreCase("TABLE")) {
1203: if (tabbedPaneTable != null)
1204: currentTabSelection = tabbedPaneTable
1205: .getSelectedIndex();
1206: tableDataStartRowNum = 1;
1207: tableDataEndRowNum = Constants.PAGING_RECORD_COUNT;
1208: rightPanel.removeAll();
1209: tableColumns = new Vector(0, 1);
1210: JScrollPane rightSP = new JScrollPane(tableDetails);
1211: tabbedPaneTable = new JTabbedPane();
1212: tabbedPaneTable.setFont(new Font(fontFamily,
1213: Font.BOLD, fontBig));
1214: dataDesc = dbManager.getTabDesc(selectedObject);
1215: tabModel.setDataVector(dataDesc, colHdr);
1216: tabbedPaneTable.addTab("Definition", rightSP);
1217: setTableData(selectedObject, dataDesc,
1218: tableDataStartRowNum, tableDataEndRowNum);
1219: tabbedPaneTable
1220: .setSelectedIndex(currentTabSelection);
1221: String objectStatus = dbStructure.getTable(
1222: selectedObject).getObjectStatus();
1223: /*if(objectStatus.equalsIgnoreCase("VALID"))
1224: {
1225: statusBar.setText(objectStatus);
1226: statusBar.setDisabledTextColor(Color.BLACK);
1227: }
1228: else
1229: {
1230: statusBar.setText(objectStatus);
1231: statusBar.setDisabledTextColor(Color.RED);
1232: }*/
1233: }
1234: if (objType != null
1235: && objType.equalsIgnoreCase("SEQUENCE")) {
1236: rightPanel.removeAll();
1237: JScrollPane rightSP = new JScrollPane(seqDetails);
1238: rightPanel.add(rightSP, BorderLayout.CENTER);
1239: rightPanel.setVisible(false);
1240: rightPanel.setVisible(true);
1241: Vector dtlsSeq = dbManager
1242: .getSequenceDetails(selectedObject);
1243: tabModelSeq.setDataVector(dtlsSeq, colHdrSeq);
1244: String objectStatus = dbStructure.getSequence(
1245: selectedObject).getObjectStatus();
1246: if (objectStatus.equalsIgnoreCase("VALID")) {
1247: statusBar.setText(objectStatus);
1248: statusBar.setDisabledTextColor(Color.BLACK);
1249: } else {
1250: statusBar.setText(objectStatus);
1251: statusBar.setDisabledTextColor(Color.RED);
1252: }
1253: }
1254: if (objType != null
1255: && objType.equalsIgnoreCase("INDEX")) {
1256: rightPanel.removeAll();
1257: rightPanel.setLayout(new BorderLayout());
1258: JScrollPane rightSP = new JScrollPane(indxDetails);
1259: rightPanel.add(rightSP, BorderLayout.CENTER);
1260: JLabel tabName = new JLabel();
1261: tabName.setOpaque(true);
1262: tabName.setBackground(new Color(0, 0, 100));
1263: tabName.setForeground(Color.WHITE);
1264: tabName.setFont(new Font(fontFamily, Font.BOLD,
1265: fontBig));
1266: Hashtable hIndxDtls = dbManager
1267: .getIndexDetails(selectedObject);
1268: tabName.setText("TABLE NAME: "
1269: + hIndxDtls.get("TABLE_NAME"));
1270: Vector dtlsIndx = (Vector) hIndxDtls.get("DATA");
1271: tabModelIndx.setDataVector(dtlsIndx, colHdrIndx);
1272: rightPanel.add(tabName, BorderLayout.NORTH);
1273: tabName.setPreferredSize(new Dimension(indxDetails
1274: .getWidth(), 15));
1275: rightPanel.setVisible(false);
1276: rightPanel.setVisible(true);
1277: String objectStatus = dbStructure.getIndex(
1278: selectedObject).getObjectStatus();
1279: if (objectStatus.equalsIgnoreCase("VALID")) {
1280: statusBar.setText(objectStatus);
1281: statusBar.setDisabledTextColor(Color.BLACK);
1282: } else {
1283: statusBar.setText(objectStatus);
1284: statusBar.setDisabledTextColor(Color.RED);
1285: }
1286: }
1287: if (objType != null
1288: && objType.equalsIgnoreCase("TRIGGER")) {
1289: ArrayList source = dbManager.getSource(
1290: selectedObject, objType);
1291: rightPanel.removeAll();
1292: rightPanel.add(panPLSQLEditorTop,
1293: BorderLayout.NORTH);
1294: rightPanel.add(spEditor);
1295: setSourceToEditor(editor, source);
1296: splitPane.setVisible(false);
1297: splitPane.setVisible(true);
1298: statusBar.setText(dbStructure.getTrigger(
1299: selectedObject).getObjectStatus());
1300: String objectStatus = dbStructure.getTrigger(
1301: selectedObject).getObjectStatus();
1302: if (objectStatus.equalsIgnoreCase("VALID")) {
1303: statusBar.setText(objectStatus);
1304: statusBar.setDisabledTextColor(Color.BLACK);
1305: } else {
1306: statusBar.setText(objectStatus);
1307: statusBar.setDisabledTextColor(Color.RED);
1308: }
1309: editor.requestFocus(true);
1310: }
1311: if (objType != null && objType.equalsIgnoreCase("VIEW")) {
1312: ArrayList source = dbManager.getSource(
1313: selectedObject, objType);
1314: rightPanel.removeAll();
1315: rightPanel.add(panPLSQLEditorTop,
1316: BorderLayout.NORTH);
1317: rightPanel.add(spEditor);
1318: setSourceToEditor(editor, source);
1319: splitPane.setVisible(false);
1320: splitPane.setVisible(true);
1321: String objectStatus = dbStructure.getView(
1322: selectedObject).getObjectStatus();
1323: if (objectStatus.equalsIgnoreCase("VALID")) {
1324: statusBar.setText(objectStatus);
1325: statusBar.setDisabledTextColor(Color.BLACK);
1326: } else {
1327: statusBar.setText(objectStatus);
1328: statusBar.setDisabledTextColor(Color.RED);
1329: }
1330: editor.requestFocus(true);
1331: }
1332: if (objType != null
1333: && objType.equalsIgnoreCase("SYNONYM")) {
1334: rightPanel.removeAll();
1335: JScrollPane rightSP = new JScrollPane(synDetails);
1336: rightPanel.add(rightSP, BorderLayout.CENTER);
1337: JLabel synName = new JLabel();
1338: synName.setOpaque(true);
1339: synName.setBackground(new Color(0, 0, 100));
1340: synName.setForeground(Color.WHITE);
1341: synName.setFont(new Font(fontFamily, Font.BOLD,
1342: fontBig));
1343: Vector dtlsSyn = dbManager
1344: .getSynDetails(selectedObject);
1345: synName.setText(selectedObject);
1346: tabModelSyn.setDataVector(dtlsSyn, colHdrSyn);
1347: //rightPanel.add(synName, BorderLayout.NORTH);
1348: rightPanel.setVisible(false);
1349: rightPanel.setVisible(true);
1350: }
1351: }
1352: } finally {
1353: setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
1354: }
1355: }
1356:
1357: public void setDataTableColSizes(JTable tableData,
1358: Vector datTabColSizes, Vector columnNames) {
1359: if (datTabColSizes == null)
1360: return;
1361: int noOfCols = datTabColSizes.size();
1362: for (int i = 0; i < noOfCols; i++) {
1363: int colSz = 0;
1364: try {
1365: colSz = new Integer((String) datTabColSizes
1366: .elementAt(i)).intValue();
1367: } catch (Exception ex) {
1368: }
1369: String colName = (String) columnNames.elementAt(i);
1370: if (colSz < colName.trim().length())
1371: colSz = colName.trim().length();
1372: int colWidth = colSz * DATA_TABLE_COL_SIZE_MULTIPLE;
1373: if (colWidth > 500)
1374: colWidth = 500;
1375: tableData.getColumn(colName).setPreferredWidth(colWidth);
1376: }
1377: }
1378:
1379: public void changedUpdate(DocumentEvent e) {
1380: }
1381:
1382: public void insertUpdate(DocumentEvent e) {
1383: }
1384:
1385: public void removeUpdate(DocumentEvent e) {
1386: }
1387:
1388: public void setSourceToEditor(JEditorPane editor,
1389: ArrayList sourceList) {
1390: //if(properties.get("HIGHLIGHT_SYNTAX")==null || properties.get("HIGHLIGHT_SYNTAX").toString().trim().equalsIgnoreCase("NO"))
1391: //{
1392: setSourceToEditorPlainText(editor, sourceList);
1393: //return;
1394: //}
1395: /*editor.setText("");
1396: SimpleAttributeSet keyWordsText = new SimpleAttributeSet();
1397: StyleConstants.setForeground(keyWordsText, Color.BLUE);
1398: StyleConstants.setBold(keyWordsText, true);
1399:
1400: SimpleAttributeSet sqlCommandsText = new SimpleAttributeSet();
1401: StyleConstants.setForeground(sqlCommandsText, Color.RED);
1402: StyleConstants.setBold(sqlCommandsText, true);
1403:
1404: SimpleAttributeSet sqlDBObjectsText = new SimpleAttributeSet();
1405: StyleConstants.setForeground(sqlDBObjectsText, new Color(0,128,0));
1406: StyleConstants.setBold(sqlDBObjectsText, true);
1407:
1408: SimpleAttributeSet commentedText = new SimpleAttributeSet();
1409: StyleConstants.setForeground(commentedText, Color.GRAY);
1410:
1411: SimpleAttributeSet nonAlphaNumericText = new SimpleAttributeSet();
1412: StyleConstants.setForeground(nonAlphaNumericText, new Color(128,0,0));
1413: StyleConstants.setBold(nonAlphaNumericText,true);
1414:
1415: SimpleAttributeSet defaultBlackText = new SimpleAttributeSet();
1416: StyleConstants.setForeground(defaultBlackText, new Color(0,0,100));
1417: //StyleConstants.setBold(defaultBlackText,true);
1418: int nols = sourceList.size();
1419: Document doc = editor.getDocument();
1420: for(int sl = 0; sl<nols; sl++)
1421: {
1422: try{
1423: String source = (String)sourceList.get(sl);
1424: if(source!=null && source.trim().length()==0)
1425: {
1426: doc.insertString(doc.getLength(), "\n", defaultBlackText);
1427: continue;
1428: }
1429: boolean commentedLine = false;
1430: if(source!=null && source.trim().startsWith("--"))
1431: {
1432: commentedLine = true;
1433: }
1434: ArrayList othToks = new ArrayList(0);
1435: Pattern pattern = Pattern.compile("(\\W+)\\w*?");
1436: Matcher matcher = pattern.matcher(source);
1437: while(matcher.find())
1438: {
1439: othToks.add(matcher.group());
1440: }
1441:
1442: ArrayList anToks = new ArrayList(0);
1443: pattern = Pattern.compile("(\\w+)\\W*?");
1444: matcher = pattern.matcher(source);
1445: while(matcher.find())
1446: {
1447: anToks.add(matcher.group());
1448: }
1449: int loopSz = 0;
1450: loopSz = anToks.size();
1451: String firstAN = null;
1452: if(anToks!=null && !anToks.isEmpty())
1453: firstAN = anToks.get(0).toString();
1454: String firstOth = null;
1455: if(othToks!=null && !othToks.isEmpty())
1456: firstOth = othToks.get(0).toString();
1457: for(int i=0;i<loopSz;i++)
1458: {
1459: if(i>0 && source.startsWith(firstAN))
1460: {
1461: doc.insertString(doc.getLength(), ((String)othToks.get(i-1)), nonAlphaNumericText);
1462: }
1463: else if(source.startsWith(firstOth))
1464: {
1465: doc.insertString(doc.getLength(), ((String)othToks.get(i)), nonAlphaNumericText);
1466: }
1467: if(commentedLine)
1468: {
1469: doc.insertString(doc.getLength(), (String)anToks.get(i), commentedText);
1470: }
1471: else if(isSQLCommand((String)anToks.get(i)))
1472: {
1473: doc.insertString(doc.getLength(), (String)anToks.get(i), sqlCommandsText);
1474: }
1475: else if(isDBObject((String)anToks.get(i)))
1476: {
1477: doc.insertString(doc.getLength(), (String)anToks.get(i), sqlDBObjectsText);
1478: }else if(isKeyWord((String)anToks.get(i)))
1479: {
1480: doc.insertString(doc.getLength(), (String)anToks.get(i), keyWordsText);
1481: }
1482: else
1483: {
1484: doc.insertString(doc.getLength(), (String)anToks.get(i), defaultBlackText);
1485: }
1486: }
1487: try{
1488: doc.insertString(doc.getLength(), (String)othToks.get(othToks.size()-1), nonAlphaNumericText);
1489: }catch(Exception ex){
1490: //Its OK
1491: }
1492: editor.setCaretPosition(0);
1493: }catch(BadLocationException exp) {
1494: exp.printStackTrace();
1495: }
1496: }*/
1497: }
1498:
1499: public void setSourceToEditorPlainText(JEditorPane editor,
1500: ArrayList sourceList) {
1501: editor.setText("");
1502: int nols = sourceList.size();
1503: Document doc = editor.getDocument();
1504: SimpleAttributeSet defaultBlueText = new SimpleAttributeSet();
1505: StyleConstants.setFontFamily(defaultBlueText, "Courier New");
1506: StyleConstants.setForeground(defaultBlueText,
1507: new Color(0, 0, 0));
1508: StyleConstants.setFontSize(defaultBlueText, fontBig);
1509: //StyleConstants.setBold(defaultBlueText,true);
1510: for (int sl = 0; sl < nols; sl++) {
1511: try {
1512: String source = (String) sourceList.get(sl);
1513: doc.insertString(doc.getLength(), source,
1514: defaultBlueText);
1515: } catch (BadLocationException exp) {
1516: exp.printStackTrace();
1517: }
1518: }
1519: editor.setCaretPosition(0);
1520: }
1521:
1522: public boolean isKeyWord(String str) {
1523: if (lstKeyWords.contains(str.toUpperCase()))
1524: return true;
1525: return false;
1526: }
1527:
1528: public boolean isSQLCommand(String str) {
1529: if (lstSQLCommands.contains(str.toUpperCase()))
1530: return true;
1531: return false;
1532: }
1533:
1534: public boolean isDBObject(String str) {
1535: if (allDBObjectNames.contains(str.toUpperCase()))
1536: return true;
1537: return false;
1538: }
1539:
1540: public void populateKeyWords() {
1541: lstSQLCommands.add("CREATE");
1542: lstKeyWords.add("OR");
1543: lstSQLCommands.add("REPLACE");
1544: lstSQLCommands.add("SELECT");
1545: lstSQLCommands.add("INSERT");
1546: lstSQLCommands.add("DELETE");
1547: lstSQLCommands.add("UPDATE");
1548: lstKeyWords.add("FROM");
1549: lstKeyWords.add("WHERE");
1550: lstKeyWords.add("HAVING");
1551: lstKeyWords.add("IN");
1552: lstKeyWords.add("IN(");
1553: lstKeyWords.add("AND");
1554: lstKeyWords.add("SET");
1555: lstKeyWords.add("VALUES");
1556: lstSQLCommands.add("COMMIT");
1557: lstSQLCommands.add("ROLLBACK");
1558: lstKeyWords.add("AS");
1559: lstKeyWords.add("DECLARE");
1560: lstKeyWords.add("BEGIN");
1561: lstKeyWords.add("END");
1562: lstKeyWords.add("IF");
1563: lstKeyWords.add("FOR");
1564: lstKeyWords.add("LOOP");
1565: lstSQLCommands.add("PROCEDURE");
1566: lstSQLCommands.add("VIEW");
1567: lstSQLCommands.add("FUNCTION");
1568: lstSQLCommands.add("TRIGGER");
1569: lstKeyWords.add("ON");
1570: lstKeyWords.add("AFTER");
1571: lstKeyWords.add("BEFORE");
1572: lstKeyWords.add("CURSOR");
1573: lstKeyWords.add("VARCHAR");
1574: lstKeyWords.add("CHAR");
1575: lstKeyWords.add("VARCHAR2");
1576: lstKeyWords.add("DATE");
1577: lstKeyWords.add("NUMBER");
1578: lstKeyWords.add("SYSDATE");
1579: lstKeyWords.add("DUAL");
1580: lstKeyWords.add("END;");
1581: lstKeyWords.add("RETURN");
1582: lstKeyWords.add("INTO");
1583: lstKeyWords.add("IF;");
1584: lstKeyWords.add("LOOP;");
1585: lstKeyWords.add("THEN");
1586: lstKeyWords.add("IF(");
1587: lstKeyWords.add("ORDER");
1588: lstKeyWords.add("GROUP");
1589: lstKeyWords.add("BY");
1590: lstKeyWords.add("ROWNUM");
1591: lstKeyWords.add("ROWNUM;");
1592: lstKeyWords.add("IS");
1593: lstKeyWords.add("DUAL;");
1594: lstKeyWords.add("VARCHAR;");
1595: lstKeyWords.add("CHAR;");
1596: lstKeyWords.add("VARCHAR2;");
1597: lstKeyWords.add("DATE;");
1598: lstKeyWords.add("NUMBER;");
1599:
1600: lstKeyWords.add("VARCHAR(");
1601: lstKeyWords.add("CHAR(");
1602: lstKeyWords.add("VARCHAR2(");
1603: lstKeyWords.add("DATE(");
1604: lstKeyWords.add("NUMBER(");
1605:
1606: lstKeyWords.add("VARCHAR)");
1607: lstKeyWords.add("CHAR)");
1608: lstKeyWords.add("VARCHAR2)");
1609: lstKeyWords.add("DATE)");
1610: lstKeyWords.add("NUMBER)");
1611:
1612: lstKeyWords.add("ELSE");
1613: lstKeyWords.add("TO_DATE");
1614: lstKeyWords.add("TO_NUMBER");
1615: lstKeyWords.add("TO_CHAR");
1616: lstKeyWords.add("TRIM");
1617: lstKeyWords.add("LTRIM");
1618: lstKeyWords.add("RTRIM");
1619: lstKeyWords.add("SUBSTR");
1620: lstKeyWords.add("COUNT");
1621: lstKeyWords.add("MAX");
1622: lstKeyWords.add("MIN");
1623: lstKeyWords.add("SUM");
1624: lstKeyWords.add("TO_DATE(");
1625: lstKeyWords.add("TO_NUMBER(");
1626: lstKeyWords.add("TO_CHAR(");
1627: lstKeyWords.add("TRIM(");
1628: lstKeyWords.add("LTRIM(");
1629: lstKeyWords.add("RTRIM(");
1630: lstKeyWords.add("SUBSTR(");
1631: lstKeyWords.add("COUNT(");
1632: lstKeyWords.add("MAX(");
1633: lstKeyWords.add("MIN(");
1634: lstKeyWords.add("SUM(");
1635: lstKeyWords.add("ABS(");
1636: lstKeyWords.add("ABS");
1637: lstKeyWords.add("BETWEEN");
1638: lstKeyWords.add("OLD:");
1639: lstKeyWords.add("NEW:");
1640: }
1641:
1642: public void setTableData(String selectedObject, Vector dataDesc,
1643: int startIndx, int endIndx) {
1644: btnPrevRecords.setEnabled(true);
1645: btnNextRecords.setEnabled(true);
1646: if (tabbedPaneTable.getTabCount() > 1)
1647: tabbedPaneTable.removeTabAt(1);
1648: tableColumns = new Vector(0, 1);
1649: int szDataDesc = 0;
1650: if (dataDesc != null) {
1651: szDataDesc = dataDesc.size();
1652: }
1653: Vector datTabColSizes = new Vector(0, 1);
1654: for (int i = 0; i < szDataDesc; i++) {
1655: tableColumns.addElement(((Vector) dataDesc.elementAt(i))
1656: .elementAt(0));
1657: datTabColSizes.addElement(((Vector) dataDesc.elementAt(i))
1658: .elementAt(2));
1659: }
1660: Hashtable hTabData = null;
1661: try {
1662: hTabData = dbManager.getTableData(dbStructure
1663: .getTable(selectedObject), tableColumns,
1664: tableDataStartRowNum, tableDataEndRowNum);
1665: } catch (SQLException ex) {
1666: JOptionPane
1667: .showMessageDialog(
1668: this ,
1669: "Error occured while retrieving table data. Please check your data filter/sorting criteria.");
1670: ex.printStackTrace();
1671: }
1672: //Vector tableDataVector = dbManager.getTableData(selectedObject, tableColumns, tableDataStartRowNum, tableDataEndRowNum);
1673: Vector tableDataVector = null;
1674: String strRowCount = "0";
1675: if (hTabData != null) {
1676: tableDataVector = (Vector) hTabData.get("DATA");
1677: strRowCount = (String) hTabData.get("RECORD_COUNT");
1678: }
1679: currTabRowCount = 0;
1680: try {
1681: currTabRowCount = new Integer(strRowCount).intValue();
1682: } catch (Exception ex) {
1683: System.out.println("Record count is not valid.");
1684: }
1685: tabDataModel = new ReadOnlyTableModel(null, tableColumns);
1686: tabDataModel.setDataVector(tableDataVector, tableColumns);
1687: JTable tableData = new JTable(tabDataModel);
1688: tableData.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
1689: JTableHeader tabDataTabHdr = tableData.getTableHeader();
1690: tabDataTabHdr.setFont(new Font(fontFamily, Font.BOLD, 9));
1691: tabDataTabHdr.setForeground(Color.WHITE);
1692: tabDataTabHdr.setBackground(new Color(0, 0, 100));
1693: rightPanel.add(tabbedPaneTable, BorderLayout.CENTER);
1694: setDataTableColSizes(tableData, datTabColSizes, tableColumns);
1695: tableData.setBackground(new Color(255, 255, 235));
1696: JScrollPane rightSPTabData = new JScrollPane(tableData);
1697: JPanel panTabData = new JPanel();
1698: panTabData.setLayout(new BorderLayout());
1699: JPanel panTabDataTop = new JPanel(new FlowLayout(
1700: FlowLayout.LEFT));
1701: panTabData.add(panTabDataTop, BorderLayout.NORTH);
1702: panTabData.add(rightSPTabData);
1703: panTabDataTop.add(btnNextRecords);
1704: panTabDataTop.add(btnPrevRecords);
1705: panTabDataTop.add(btnDataFilter);
1706: panTabDataTop.add(btnDataSort);
1707: tabbedPaneTable.addTab("Data", panTabData);
1708: rightPanel.setVisible(false);
1709: rightPanel.setVisible(true);
1710: if (startIndx == 1 || currTabRowCount == 0)
1711: btnPrevRecords.setEnabled(false);
1712: if (endIndx >= currTabRowCount || currTabRowCount == 0)
1713: btnNextRecords.setEnabled(false);
1714: //if(tabbedPaneTable.getSelectedIndex()==1)
1715: //{
1716: //statusBar.setDisabledTextColor(Color.BLACK);
1717: DBObject tableObj = dbStructure.getTable(selectedObject);
1718: String filterInd = "";
1719: if (tableObj.getTableFilter() != null
1720: && tableObj.getTableFilter().trim().length() > 0)
1721: filterInd = " [Filter Applied]";
1722: if (tableDataVector == null || tableDataVector.size() == 0)
1723: statusBar.setText("No records found in this table"
1724: + filterInd + ".");
1725: else if (currTabRowCount > Constants.PAGING_RECORD_COUNT)
1726: statusBar
1727: .setText(tableDataVector.size()
1728: + " records retrieved from this table out of a total of "
1729: + currTabRowCount + " records" + filterInd
1730: + ".");
1731: else
1732: statusBar.setText(tableDataVector.size()
1733: + " records found in this table" + filterInd + ".");
1734: //}
1735: }
1736:
1737: public ArrayList getKeyWordsInfo(String source) {
1738: //String sourceTemp = new String(source);
1739: ArrayList tempLstKeyWords = new ArrayList(0);
1740: if (source == null)
1741: return tempLstKeyWords;
1742: int length = source.length();
1743: if (length == 0)
1744: return tempLstKeyWords;
1745: for (int i = length - 1; i >= 0; i--) {
1746: String sourceTemp = source.substring(i);
1747: int keyWordsSz = lstKeyWords.size();
1748: for (int j = 0; j < keyWordsSz; j++) {
1749: if (sourceTemp.toUpperCase().startsWith(
1750: (String) lstKeyWords.get(j))) {
1751: KeyWord keyWord = new KeyWord();
1752: keyWord.setWord((String) lstKeyWords.get(j));
1753: keyWord.setPosition(i);
1754: //keyWord.setLength(((String)lstKeyWords.get(j)).length());
1755: tempLstKeyWords.add(keyWord);
1756: break;
1757: }
1758: }
1759: }
1760: return tempLstKeyWords;
1761: }
1762:
1763: public void caretUpdate(CaretEvent e) {
1764: setCursor(new Cursor(Cursor.WAIT_CURSOR));
1765: try {
1766: int caretPos = e.getDot();
1767: if (caretPos == 0) {
1768: positionBar.setText("[Line: 1, Position: 1]");
1769: return;
1770: }
1771: String editorText = null;
1772:
1773: try {
1774: editorText = editor.getText(0, caretPos);
1775: } catch (BadLocationException e1) {
1776: e1.printStackTrace();
1777: }
1778: if (editorText == null || editorText.length() == 0)
1779: return;
1780: editorText = editorText + " ";
1781: int lineNo = 1;
1782: int posNo = 1;
1783: String lines[] = editorText.split("(\\n)");
1784: if (lines == null || lines.length > 0) {
1785: lineNo = lines.length;
1786: String lastLine = lines[lineNo - 1];
1787: if ((caretPos - lastLine.length()) < 0)
1788: posNo = caretPos + 1;
1789: else
1790: posNo = editor.getText(0, caretPos).length()
1791: - editor.getText(0,
1792: caretPos - lastLine.length())
1793: .length();
1794: }
1795: positionBar.setText("[Line: " + lineNo + ", Position: "
1796: + posNo + "]");
1797: } catch (Exception ex) {
1798: //Its OK
1799: ex.printStackTrace();
1800: } finally {
1801: setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
1802: }
1803: }
1804:
1805: }
|