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.constraints.*;
017: import org.jsqltool.gui.panel.*;
018: import org.jsqltool.utils.ImageLoader;
019: import org.jsqltool.utils.Options;
020:
021: /**
022: * <p>Title: JSqlTool Project</p>
023: * <p>Description: Panel used to show the table constraints.
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 ConstraintsTablePanel 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: BorderLayout borderLayout2 = new BorderLayout();
069:
070: /** implementation class related to database type */
071: private Constraints cons = null;
072:
073: public ConstraintsTablePanel() {
074: try {
075: jbInit();
076: } catch (Exception e) {
077: e.printStackTrace();
078: }
079: }
080:
081: /**
082: * @return position of this panel inside the JTabbedPane of table detail
083: */
084: public int getTabbedPosition() {
085: return 2;
086: }
087:
088: /**
089: * @return folder name
090: */
091: public String getTabbedName() {
092: return Options.getInstance().getResource("constraints");
093: }
094:
095: public void init(DbConnectionUtil dbConnUtil) {
096: if (dbConnUtil.getDbConnection().getDbType() == DbConnection.ORACLE_TYPE)
097: cons = new OracleConstraints(dbConnUtil);
098: else if (dbConnUtil.getDbConnection().getDbType() == DbConnection.SQLSERVER_TYPE)
099: cons = new SqlServerConstraints(dbConnUtil);
100: else
101: cons = new VoidConstraints(dbConnUtil);
102: }
103:
104: public void jbInit() {
105: flowLayout1.setVgap(0);
106: this .setLayout(borderLayout2);
107: borderLayout2.setHgap(5);
108: borderLayout2.setVgap(5);
109: this .add(buttonsPanel, BorderLayout.NORTH);
110: buttonsPanel.setLayout(flowLayout1);
111: flowLayout1.setAlignment(FlowLayout.LEFT);
112: flowLayout1.setHgap(0);
113: enableAllButton
114: .addActionListener(new ConstraintsTablePanel_enableAllButton_actionAdapter(
115: this ));
116: disableAllButton
117: .addActionListener(new ConstraintsTablePanel_disableAllButton_actionAdapter(
118: this ));
119: enableButton
120: .addActionListener(new ConstraintsTablePanel_enableButton_actionAdapter(
121: this ));
122: disableButton
123: .addActionListener(new ConstraintsTablePanel_disableButton_actionAdapter(
124: this ));
125: dropButton
126: .addActionListener(new ConstraintsTablePanel_dropButton_actionAdapter(
127: this ));
128: enableAllButton.setBorder(null);
129: enableAllButton.setPreferredSize(new Dimension(24, 24));
130: disableAllButton.setBorder(null);
131: disableAllButton.setPreferredSize(new Dimension(24, 24));
132: enableButton.setBorder(null);
133: enableButton.setPreferredSize(new Dimension(24, 24));
134: disableButton.setBorder(null);
135: disableButton.setPreferredSize(new Dimension(24, 24));
136: dropButton.setBorder(null);
137: dropButton.setPreferredSize(new Dimension(24, 24));
138: enableAllImage = ImageLoader.getInstance().getIcon(
139: "enableall.gif");
140: disableAllImage = ImageLoader.getInstance().getIcon(
141: "disableall.gif");
142: enableImage = ImageLoader.getInstance().getIcon("enable.gif");
143: disableImage = ImageLoader.getInstance().getIcon("disable.gif");
144: dropImage = ImageLoader.getInstance().getIcon("drop.gif");
145:
146: enableAllButton.setIcon(enableAllImage);
147: enableAllButton.setToolTipText(Options.getInstance()
148: .getResource("enable all constraints"));
149: enableAllButton.setMaximumSize(new Dimension(24, 24));
150: disableAllButton.setIcon(disableAllImage);
151: disableAllButton.setToolTipText(Options.getInstance()
152: .getResource("disable all constraints"));
153: disableAllButton.setMaximumSize(new Dimension(24, 24));
154: enableButton.setIcon(enableImage);
155: enableButton.setToolTipText(Options.getInstance().getResource(
156: "enable the current constraint"));
157: enableButton.setMaximumSize(new Dimension(24, 24));
158: disableButton.setIcon(disableImage);
159: disableButton.setToolTipText(Options.getInstance().getResource(
160: "disable the current constraint"));
161: disableButton.setMaximumSize(new Dimension(24, 24));
162: dropButton.setIcon(dropImage);
163: dropButton.setToolTipText(Options.getInstance().getResource(
164: "drop constraint"));
165: dropButton.setMaximumSize(new Dimension(24, 24));
166:
167: buttonsPanel.add(enableAllButton, null);
168: buttonsPanel.add(disableAllButton, null);
169: buttonsPanel.add(enableButton, null);
170: buttonsPanel.add(disableButton, null);
171: buttonsPanel.add(dropButton, null);
172:
173: }
174:
175: public String getQuery(String tableName, DbConnectionUtil dbConnUtil) {
176: return cons.getQueryConstraints(tableName);
177: }
178:
179: void enableAllButton_actionPerformed(ActionEvent e) {
180: Object[] row = new Object[getDataPanel().getTableModel()
181: .getColumnCount()];
182: for (int j = 0; j < getDataPanel().getTableModel()
183: .getRowCount(); j++) {
184: for (int i = 0; i < getDataPanel().getTableModel()
185: .getColumnCount(); i++)
186: row[i] = getDataPanel().getTableModel()
187: .getValueAt(j, i);
188: cons.enableConstraint(tableName, row);
189: }
190: this .setQuery(tableName);
191: }
192:
193: void disableAllButton_actionPerformed(ActionEvent e) {
194: Object[] row = new Object[getDataPanel().getTableModel()
195: .getColumnCount()];
196: for (int j = 0; j < getDataPanel().getTableModel()
197: .getRowCount(); j++) {
198: for (int i = 0; i < getDataPanel().getTableModel()
199: .getColumnCount(); i++)
200: row[i] = getDataPanel().getTableModel()
201: .getValueAt(j, i);
202: cons.disableConstraint(tableName, row);
203: }
204: this .setQuery(tableName);
205: }
206:
207: void enableButton_actionPerformed(ActionEvent e) {
208: if (getDataPanel().getTable().getSelectedRow() != -1) {
209: Object[] row = new Object[getDataPanel().getTableModel()
210: .getColumnCount()];
211: for (int i = 0; i < getDataPanel().getTableModel()
212: .getColumnCount(); i++)
213: row[i] = getDataPanel().getTableModel().getValueAt(
214: getDataPanel().getTable().getSelectedRow(), i);
215: cons.enableConstraint(tableName, row);
216: this .setQuery(tableName);
217: }
218: }
219:
220: void disableButton_actionPerformed(ActionEvent e) {
221: if (getDataPanel().getTable().getSelectedRow() != -1) {
222: Object[] row = new Object[getDataPanel().getTableModel()
223: .getColumnCount()];
224: for (int i = 0; i < getDataPanel().getTableModel()
225: .getColumnCount(); i++)
226: row[i] = getDataPanel().getTableModel().getValueAt(
227: getDataPanel().getTable().getSelectedRow(), i);
228: cons.disableConstraint(tableName, row);
229: this .setQuery(tableName);
230: }
231: }
232:
233: void dropButton_actionPerformed(ActionEvent e) {
234: if (getDataPanel().getTable().getSelectedRow() != -1) {
235: if (JOptionPane
236: .showConfirmDialog(
237: parent,
238: Options.getInstance().getResource(
239: "are you sure to drop constraint?"),
240: Options.getInstance().getResource(
241: "drop contraint"),
242: JOptionPane.YES_NO_OPTION,
243: JOptionPane.QUESTION_MESSAGE) == 1)
244: return;
245: Object[] row = new Object[getDataPanel().getTableModel()
246: .getColumnCount()];
247: for (int i = 0; i < getDataPanel().getTableModel()
248: .getColumnCount(); i++)
249: row[i] = getDataPanel().getTableModel().getValueAt(
250: getDataPanel().getTable().getSelectedRow(), i);
251: cons.dropConstraint(tableName, row);
252: this .setQuery(tableName);
253: }
254: }
255:
256: /**
257: * @return infos about the author of the plugin panel; "" or null does not report any info about the plugin panel
258: */
259: public String getAuthor() {
260: return "";
261: }
262:
263: /**
264: * @return plugin panel version
265: */
266: public String getVersion() {
267: return "1.0";
268: }
269:
270: /**
271: * @return plugin panel name, reported into the about window
272: */
273: public String getName() {
274: return Options.getInstance().getResource(
275: "table constraints plugin");
276: }
277:
278: }
279:
280: class ConstraintsTablePanel_enableAllButton_actionAdapter implements
281: java.awt.event.ActionListener {
282: ConstraintsTablePanel adaptee;
283:
284: ConstraintsTablePanel_enableAllButton_actionAdapter(
285: ConstraintsTablePanel adaptee) {
286: this .adaptee = adaptee;
287: }
288:
289: public void actionPerformed(ActionEvent e) {
290: adaptee.enableAllButton_actionPerformed(e);
291: }
292: }
293:
294: class ConstraintsTablePanel_disableAllButton_actionAdapter implements
295: java.awt.event.ActionListener {
296: ConstraintsTablePanel adaptee;
297:
298: ConstraintsTablePanel_disableAllButton_actionAdapter(
299: ConstraintsTablePanel adaptee) {
300: this .adaptee = adaptee;
301: }
302:
303: public void actionPerformed(ActionEvent e) {
304: adaptee.disableAllButton_actionPerformed(e);
305: }
306: }
307:
308: class ConstraintsTablePanel_enableButton_actionAdapter implements
309: java.awt.event.ActionListener {
310: ConstraintsTablePanel adaptee;
311:
312: ConstraintsTablePanel_enableButton_actionAdapter(
313: ConstraintsTablePanel adaptee) {
314: this .adaptee = adaptee;
315: }
316:
317: public void actionPerformed(ActionEvent e) {
318: adaptee.enableButton_actionPerformed(e);
319: }
320: }
321:
322: class ConstraintsTablePanel_disableButton_actionAdapter implements
323: java.awt.event.ActionListener {
324: ConstraintsTablePanel adaptee;
325:
326: ConstraintsTablePanel_disableButton_actionAdapter(
327: ConstraintsTablePanel adaptee) {
328: this .adaptee = adaptee;
329: }
330:
331: public void actionPerformed(ActionEvent e) {
332: adaptee.disableButton_actionPerformed(e);
333: }
334: }
335:
336: class ConstraintsTablePanel_dropButton_actionAdapter implements
337: java.awt.event.ActionListener {
338: ConstraintsTablePanel adaptee;
339:
340: ConstraintsTablePanel_dropButton_actionAdapter(
341: ConstraintsTablePanel adaptee) {
342: this .adaptee = adaptee;
343: }
344:
345: public void actionPerformed(ActionEvent e) {
346: adaptee.dropButton_actionPerformed(e);
347: }
348: }
|