001: package org.jsqltool.gui.tablepanel;
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.model.CustomTableModel;
010: import java.sql.*;
011: import java.util.*;
012: import org.jsqltool.gui.*;
013: import org.jsqltool.*;
014: import org.jsqltool.gui.panel.*;
015:
016: /**
017: * <p>Title: JSqlTool Project</p>
018: * <p>Description: Generic plugin panel: each plugin panel has to extend this.
019: * </p>
020: * <p>Copyright: Copyright (C) 2006 Mauro Carniel</p>
021: *
022: * <p> This file is part of JSqlTool project.
023: * This library is free software; you can redistribute it and/or
024: * modify it under the terms of the (LGPL) Lesser General Public
025: * License as published by the Free Software Foundation;
026: *
027: * GNU LESSER GENERAL PUBLIC LICENSE
028: * Version 2.1, February 1999
029: *
030: * This library is distributed in the hope that it will be useful,
031: * but WITHOUT ANY WARRANTY; without even the implied warranty of
032: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
033: * Library General Public License for more details.
034: *
035: * You should have received a copy of the GNU Library General Public
036: * License along with this library; if not, write to the Free
037: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
038: *
039: * The author may be contacted at:
040: * maurocarniel@tin.it</p>
041: *
042: * @author Mauro Carniel
043: * @version 1.0
044: */
045: public class TablePluginAdapter extends JPanel implements TablePlugin {
046:
047: protected String tableName = null;
048: private Hashtable pk = null;
049: DataPanel dataPanel = null;
050: BorderLayout borderLayout1 = new BorderLayout();
051: private DbConnectionUtil dbConnUtil = null;
052: private JFrame parent = null;
053: BorderLayout borderLayout2 = new BorderLayout();
054:
055: public TablePluginAdapter() {
056: try {
057: jbInit();
058: } catch (Exception e) {
059: e.printStackTrace();
060: }
061: }
062:
063: public String getQuery(String tableName, DbConnectionUtil dbConnUtil) {
064: return null;
065: }
066:
067: /**
068: * This method is called from the table detail before the inizialization of the plugin panel
069: */
070: public void init(DbConnectionUtil dbConnUtil) {
071: }
072:
073: /**
074: * @return panel position inside the JTabbedPane related to the table detail
075: */
076: public int getTabbedPosition() {
077: return -1;
078: }
079:
080: /**
081: * @return folder name of the plugin panel, inside the JTabbedPane related to the table detail
082: */
083: public String getTabbedName() {
084: return "";
085: }
086:
087: /**
088: * @return entity name
089: */
090: public String getTableName() {
091: return tableName;
092: }
093:
094: public void setQuery(String tableName) {
095: this .tableName = tableName;
096: String query = getQuery(tableName, dbConnUtil);
097: if (query != null) {
098: this .dataPanel.setQuery(query, new Vector());
099: }
100: try {
101: ((CustomTableModel) dataPanel.getTableModel())
102: .setEditMode(CustomTableModel.DETAIL_REC);
103: } catch (Exception ex) {
104: }
105: }
106:
107: private void jbInit() throws Exception {
108: this .setLayout(borderLayout2);
109: }
110:
111: public final void resetPanel() {
112: dataPanel.resetPanel();
113: }
114:
115: /**
116: * This method is called from the table detail to inizialize the plugin panel
117: */
118: public final void initPanel(MainFrame parent,
119: DbConnectionUtil dbConnUtil) {
120: this .parent = parent;
121: this .dbConnUtil = dbConnUtil;
122: this .dataPanel = new DataPanel(dbConnUtil,
123: new TableModelListener() {
124: public void tableChanged(TableModelEvent e) {
125: }
126: });
127: this .add(dataPanel, BorderLayout.CENTER);
128: init(dbConnUtil);
129: }
130:
131: /**
132: * This method is called from the table detail to set entity name.
133: * @param tableName table name (edventualy including catalog name) that table plugin have to show
134: */
135: public final void setTableName(String tableName) {
136: this .tableName = tableName;
137: }
138:
139: /**
140: * This method is called from the table detail to update the plugin panel content.
141: */
142: public final void updateContent() {
143: setQuery(tableName);
144: }
145:
146: public final DbConnectionUtil getDbConnUtil() {
147: return dbConnUtil;
148: }
149:
150: public DataPanel getDataPanel() {
151: return dataPanel;
152: }
153:
154: /**
155: * @return infos about the author of the plugin panel; "" or null does not report any info about the plugin panel
156: */
157: public String getAuthor() {
158: return "";
159: }
160:
161: /**
162: * @return plugin panel version
163: */
164: public String getVersion() {
165: return "1.0";
166: }
167:
168: /**
169: * @return plugin panel name, reported into the about window
170: */
171: public String getName() {
172: return this .getClass().getName();
173: }
174:
175: public boolean equals(Object o) {
176: return (o instanceof TablePlugin && ((TablePlugin) o).getName()
177: .equals(getName()));
178: }
179:
180: }
|