001: /*
002: * Copyright (C) 2006 Rob Manning
003: * manningr@users.sourceforge.net
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package net.sourceforge.squirrel_sql.plugins.refactoring.gui;
021:
022: import java.awt.GridBagConstraints;
023: import java.util.Arrays;
024: import java.util.List;
025:
026: import javax.swing.JCheckBox;
027: import javax.swing.JLabel;
028: import javax.swing.JList;
029: import javax.swing.JScrollPane;
030: import javax.swing.JTextField;
031:
032: import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
033: import net.sourceforge.squirrel_sql.fw.util.StringManager;
034: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
035:
036: public class DropTableDialog extends AbstractRefactoringDialog {
037:
038: private static final long serialVersionUID = 1L;
039:
040: /** Internationalized strings for this class */
041: private static final StringManager s_stringMgr = StringManagerFactory
042: .getStringManager(DropTableDialog.class);
043:
044: static interface i18n {
045: //i18n[DropTableDialog.cascadeLabel=Cascade Constraints:]
046: String CASCADE_LABEL = s_stringMgr
047: .getString("DropTableDialog.cascadeLabel");
048:
049: //i18n[DropTableDialog.catalogLabel=Catalog:]
050: String CATALOG_LABEL = s_stringMgr
051: .getString("DropTableDialog.catalogLabel");
052:
053: //i18n[DropTableDialog.schemaLabel=Schema:]
054: String SCHEMA_LABEL = s_stringMgr
055: .getString("DropTableDialog.schemaLabel");
056:
057: //i18n[DropTableDialog.tableLabel=Table(s):]
058: String TABLE_LABEL = s_stringMgr
059: .getString("DropTableDialog.tableLabel");
060:
061: //i18n[DropTableDialog.title=Drop Table(s)]
062: String TITLE = s_stringMgr.getString("DropTableDialog.title");
063:
064: }
065:
066: private JLabel catalogLabel = null;
067: private JLabel schemaLabel = null;
068: private JTextField catalogTF = null;
069: private JTextField schemaTF = null;
070: private JList tableList = null;
071: private JLabel tableListLabel = null;
072: private JLabel cascadeConstraintsLabel = null;
073:
074: private JCheckBox cascadeCB = null;
075:
076: private ITableInfo[] tableInfos = null;
077:
078: public DropTableDialog(ITableInfo[] tables) {
079: super (false);
080: setTitle(i18n.TITLE);
081: tableInfos = tables;
082: init();
083: }
084:
085: public ITableInfo[] getTableInfos() {
086: return tableInfos;
087: }
088:
089: public List<ITableInfo> getTableInfoList() {
090: return Arrays.asList(tableInfos);
091: }
092:
093: public boolean getCascadeConstraints() {
094: return cascadeCB.isSelected();
095: }
096:
097: protected void init() {
098: // Catalog
099: catalogLabel = getBorderedLabel(i18n.CATALOG_LABEL + " ",
100: emptyBorder);
101: pane.add(catalogLabel, getLabelConstraints(c));
102:
103: catalogTF = new JTextField();
104: catalogTF.setPreferredSize(mediumField);
105: catalogTF.setEditable(false);
106: catalogTF.setText(tableInfos[0].getCatalogName());
107: pane.add(catalogTF, getFieldConstraints(c));
108:
109: // Schema
110: schemaLabel = getBorderedLabel(i18n.SCHEMA_LABEL + " ",
111: emptyBorder);
112: pane.add(schemaLabel, getLabelConstraints(c));
113:
114: schemaTF = new JTextField();
115: schemaTF.setPreferredSize(mediumField);
116: schemaTF.setEditable(false);
117: schemaTF.setText(tableInfos[0].getSchemaName());
118: pane.add(schemaTF, getFieldConstraints(c));
119:
120: // table list
121: tableListLabel = getBorderedLabel(i18n.TABLE_LABEL + " ",
122: emptyBorder);
123: tableListLabel.setVerticalAlignment(JLabel.NORTH);
124: pane.add(tableListLabel, getLabelConstraints(c));
125:
126: tableList = new JList(getSimpleNames(tableInfos));
127: tableList.setEnabled(false);
128:
129: JScrollPane sp = new JScrollPane(tableList);
130: c = getFieldConstraints(c);
131: c.weightx = 1;
132: c.weighty = 1;
133: c.fill = GridBagConstraints.BOTH;
134: pane.add(sp, c);
135:
136: // Cascade Constraints Checkbox
137: cascadeConstraintsLabel = new JLabel(i18n.CASCADE_LABEL + " ");
138: cascadeConstraintsLabel.setBorder(emptyBorder);
139: pane.add(cascadeConstraintsLabel, getLabelConstraints(c));
140:
141: cascadeCB = new JCheckBox();
142: cascadeCB.setPreferredSize(mediumField);
143: pane.add(cascadeCB, getFieldConstraints(c));
144: super .executeButton.setRequestFocusEnabled(true);
145: }
146:
147: private String[] getSimpleNames(ITableInfo[] tableInfos) {
148: String[] result = new String[tableInfos.length];
149: for (int i = 0; i < result.length; i++) {
150: result[i] = tableInfos[i].getSimpleName();
151: }
152: return result;
153: }
154:
155: }
|