001: package net.sourceforge.squirrel_sql.plugins.mysql.gui;
002:
003: /*
004: * Copyright (C) 2003 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.awt.BorderLayout;
022: import java.awt.Frame;
023: import java.sql.SQLException;
024:
025: import javax.swing.JButton;
026: import javax.swing.JComponent;
027: import javax.swing.JDialog;
028: import javax.swing.JPanel;
029: import javax.swing.JTabbedPane;
030:
031: import com.jgoodies.forms.builder.ButtonBarBuilder;
032: import com.jgoodies.forms.factories.Borders;
033:
034: import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
035: import net.sourceforge.squirrel_sql.fw.util.StringManager;
036: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory; //import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
037: //import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
038:
039: import net.sourceforge.squirrel_sql.client.gui.builders.UIFactory;
040: import net.sourceforge.squirrel_sql.client.session.ISession;
041:
042: import net.sourceforge.squirrel_sql.plugins.mysql.MysqlPlugin;
043:
044: /**
045: * Dialog that allows user to alter the dtructure of a table
046: *
047: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
048: */
049: public class AlterTableDialog extends JDialog {
050: /** Logger for this class. */
051: // private final static ILogger s_log =
052: // LoggerController.createLogger(AlterTableDialog.class);
053: private static final long serialVersionUID = 1L;
054:
055: /** Internationalized strings for this class. */
056: private static final StringManager s_stringMgr = StringManagerFactory
057: .getStringManager(AlterTableDialog.class);
058:
059: /**
060: * Ctor.
061: *
062: * @param app Appliocation API.
063: * @param plugin This plugin.
064: * @param ti Points to table to be modified.
065: *
066: * @throws IllegalArgumentException
067: * Thrown if <TT>null</TT> <TT>ISession</TT>,
068: * <TT>MysqlPlugin</TT>, or <TT>ITableInfo</TT> passed.
069: */
070: public AlterTableDialog(ISession session, MysqlPlugin plugin,
071: ITableInfo ti) throws SQLException {
072: super (ctorHelper(session, plugin, ti), true);
073:
074: createGUI(session, plugin, ti);
075: }
076:
077: private void createGUI(ISession session, MysqlPlugin plugin,
078: ITableInfo ti) throws SQLException {
079: setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
080: setTitle(s_stringMgr.getString("AlterTableDialog.title", ti
081: .getQualifiedName()));
082: setContentPane(buildContentPane(session, plugin, ti));
083: }
084:
085: @SuppressWarnings("unused")
086: private JComponent buildContentPane(ISession session,
087: MysqlPlugin plugin, ITableInfo ti) throws SQLException {
088: final JPanel pnl = new JPanel(new BorderLayout());
089: pnl.add(buildMainPanel(session, ti), BorderLayout.CENTER);
090: pnl.add(buildToolBar(), BorderLayout.SOUTH);
091: pnl.setBorder(Borders.TABBED_DIALOG_BORDER);
092:
093: return pnl;
094:
095: // final FormLayout layout = new FormLayout(
096: // "3dlu, 75dlu:grow(1.0), 3dlu",
097: // "center:pref:grow(1.0), 8dlu, bottom:pref");
098: // final DefaultFormBuilder builder = new DefaultFormBuilder(layout);
099: // builder.setDefaultDialogBorder();
100: // builder.setLeadingColumnOffset(1);
101: //
102: // builder.append(buildMainPanel(session, ti));
103: // builder.nextLine();
104: // builder.appendSeparator();
105: // builder.nextLine();
106: // builder.append(buildToolBar());
107: //
108: // return builder.getPanel();
109: }
110:
111: private JTabbedPane buildMainPanel(ISession session, ITableInfo ti)
112: throws SQLException {
113: final JTabbedPane tabPnl = UIFactory.getInstance()
114: .createTabbedPane();
115: final JPanel pnl = new AlterColumnsPanelBuilder().buildPanel(
116: session, ti);
117: tabPnl.addTab(getString("AlterTableDialog.columns"), null, pnl,
118: getString("AlterTableDialog.columnshint"));
119: return tabPnl;
120: }
121:
122: private JPanel buildToolBar() {
123: final ButtonBarBuilder builder = new ButtonBarBuilder();
124: builder.addGlue();
125: // i18n[mysql.alterDlgAlter=Alter]
126: builder.addGridded(new JButton(s_stringMgr
127: .getString("mysql.alterDlgAlter")));
128: builder.addRelatedGap();
129: // i18n[mysql.alterDlgClose=Close]
130: builder.addGridded(new JButton(s_stringMgr
131: .getString("mysql.alterDlgClose")));
132:
133: return builder.getPanel();
134: }
135:
136: private static String getString(String stringMgrKey) {
137: return s_stringMgr.getString(stringMgrKey);
138: }
139:
140: private static Frame ctorHelper(ISession session,
141: MysqlPlugin plugin, ITableInfo ti) {
142: if (session == null) {
143: throw new IllegalArgumentException("ISession == null");
144: }
145: if (plugin == null) {
146: throw new IllegalArgumentException("MysqlPlugin == null");
147: }
148: if (ti == null) {
149: throw new IllegalArgumentException("ITableInfo == null");
150: }
151: return session.getApplication().getMainFrame();
152: }
153: }
|