001: package org.jsqltool.gui.tableplugins;
002:
003: import javax.swing.*;
004: import java.awt.*;
005: import javax.swing.event.*;
006: import javax.swing.table.*;
007: import java.awt.event.*;
008: import org.jsqltool.conn.DbConnectionUtil;
009: import org.jsqltool.conn.DbConnection;
010: import org.jsqltool.model.CustomTableModel;
011: import java.sql.*;
012: import java.util.*;
013: import org.jsqltool.gui.*;
014: import org.jsqltool.gui.tablepanel.*;
015: import org.jsqltool.*;
016: import org.jsqltool.gui.tableplugins.indexes.*;
017: import org.jsqltool.gui.panel.*;
018: import org.jsqltool.model.CustomTableModel;
019: import org.jsqltool.utils.Options;
020:
021: /**
022: * <p>Title: JSqlTool Project</p>
023: * <p>Description: This panel contains indexes properties.
024: * </p>
025: * <p>Copyright: Copyright (C) 2006 Mauro Carniel</p>
026: *
027: * <p> This file is part of JSqlTool project.
028: * This library is free software; you can redistribute it and/or
029: * modify it under the terms of the (LGPL) Lesser General Public
030: * License as published by the Free Software Foundation;
031: *
032: * GNU LESSER GENERAL PUBLIC LICENSE
033: * Version 2.1, February 1999
034: *
035: * This library is distributed in the hope that it will be useful,
036: * but WITHOUT ANY WARRANTY; without even the implied warranty of
037: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
038: * Library General Public License for more details.
039: *
040: * You should have received a copy of the GNU Library General Public
041: * License along with this library; if not, write to the Free
042: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
043: *
044: * The author may be contacted at:
045: * maurocarniel@tin.it</p>
046: *
047: * @author Mauro Carniel
048: * @version 1.0
049: */
050: public class IndexesTablePanel extends TablePluginAdapter {
051:
052: private Hashtable pk = null;
053: JPanel buttonsPanel = new JPanel();
054: JButton enableAllButton = new JButton();
055: JButton disableAllButton = new JButton();
056: JButton enableButton = new JButton();
057: JButton disableButton = new JButton();
058: JButton dropButton = new JButton();
059: ImageIcon enableAllImage;
060: ImageIcon disableAllImage;
061: ImageIcon enableImage;
062: ImageIcon disableImage;
063: ImageIcon dropImage;
064: FlowLayout flowLayout1 = new FlowLayout();
065: BorderLayout borderLayout1 = new BorderLayout();
066: private JFrame parent = null;
067: GridBagLayout gridBagLayout1 = new GridBagLayout();
068:
069: /** class related to the dabase type currently in use */
070: private Indexes indexes = null;
071:
072: public IndexesTablePanel() {
073: /*
074: try {
075: jbInit();
076: }
077: catch(Exception e) {
078: e.printStackTrace();
079: }
080: */
081: }
082:
083: /**
084: * @return panel position inside the JTabbedPane related to the table detail
085: */
086: public int getTabbedPosition() {
087: return 3;
088: }
089:
090: /**
091: * @return folder name of the plugin panel, inside the JTabbedPane related to the table detail
092: */
093: public String getTabbedName() {
094: return Options.getInstance().getResource("indexes");
095: }
096:
097: /**
098: * This method is called from the table detail before the inizialization of the plugin panel
099: */
100: public void init(DbConnectionUtil dbConnUtil) {
101: if (dbConnUtil.getDbConnection().getDbType() == DbConnection.ORACLE_TYPE)
102: indexes = new OracleIndexes(dbConnUtil);
103: else
104: indexes = new VoidIndexes(dbConnUtil);
105: }
106:
107: public String getQuery(String tableName, DbConnectionUtil dbConnUtil) {
108: return indexes.getQueryIndexes(tableName);
109: }
110:
111: /**
112: * @return infos about the author of the plugin panel; "" or null does not report any info about the plugin panel
113: */
114: public String getAuthor() {
115: return "";
116: }
117:
118: /**
119: * @return plugin panel version
120: */
121: public String getVersion() {
122: return "1.0";
123: }
124:
125: /**
126: * @return plugin panel name, reported into the about window
127: */
128: public String getName() {
129: return Options.getInstance()
130: .getResource("table indexes plugin");
131: }
132:
133: public void setQuery(String tableName) {
134: if (indexes.getQueryIndexes(tableName) != null) {
135: super .setQuery(tableName);
136: return;
137: }
138: this .tableName = tableName;
139: try {
140: ResultSet rset = this .getDbConnUtil().getConn()
141: .getMetaData().getIndexInfo(null, null, tableName,
142: false, true);
143: int num = rset.getMetaData().getColumnCount();
144: String[] colNames = new String[num];
145: Class[] classNames = new Class[num];
146: int[] typeNames = new int[num];
147: for (int i = 0; i < num; i++) {
148: try {
149: colNames[i] = rset.getMetaData().getColumnName(
150: i + 1);
151: classNames[i] = Class.forName(rset.getMetaData()
152: .getColumnClassName(i + 1));
153: typeNames[i] = rset.getMetaData().getColumnType(
154: i + 1);
155: } catch (Exception ex) {
156: } catch (Error er) {
157: }
158: }
159: CustomTableModel model = new CustomTableModel(colNames,
160: classNames, typeNames);
161: Object[] row = null;
162: while (rset.next()) {
163: row = new Object[num];
164: for (int i = 0; i < num; i++)
165: row[i] = rset.getObject(i + 1);
166: model.addRow(row);
167: }
168: rset.close();
169: this .getDataPanel().getTable().setModel(model);
170: ((CustomTableModel) this .getDataPanel().getTableModel())
171: .setEditMode(CustomTableModel.DETAIL_REC);
172: } catch (Exception ex) {
173: ex.printStackTrace();
174: }
175: }
176:
177: }
|