01: package net.sourceforge.squirrel_sql.plugins.sqlscript.table_script;
02:
03: import net.sourceforge.squirrel_sql.client.session.ISession;
04: import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
05:
06: import java.awt.event.ActionListener;
07: import java.awt.event.ActionEvent;
08: import java.util.prefs.Preferences;
09:
10: public class CreateTableOfCurrentSQLCtrl {
11: private CreateTableOfCurrentSQLDialog _dlg;
12: private boolean _isOk;
13: private static final String PREFS_KEY_LAST_TABLE_NAME = "squirrel_sqlscript_tempSqlResultTable";
14: private static final String PREFS_KEY_SCRIPT_ONLY = "squirrel_sqlscript_script_only";
15: private static final String PREFS_KEY_DROP_TABLE = "squirrel_sqlscript_drop_table";
16:
17: public CreateTableOfCurrentSQLCtrl(ISession session) {
18: _dlg = new CreateTableOfCurrentSQLDialog(session
19: .getApplication().getMainFrame());
20:
21: _dlg.btnOK.addActionListener(new ActionListener() {
22: public void actionPerformed(ActionEvent e) {
23: onOK();
24: }
25: });
26:
27: _dlg.btnCancel.addActionListener(new ActionListener() {
28: public void actionPerformed(ActionEvent e) {
29: onCancel();
30: }
31: });
32:
33: String tempSqlResultTable = Preferences.userRoot().get(
34: PREFS_KEY_LAST_TABLE_NAME, "tempSqlResultTable");
35: boolean dropTable = Preferences.userRoot().getBoolean(
36: PREFS_KEY_DROP_TABLE, false);
37: boolean scriptOnly = Preferences.userRoot().getBoolean(
38: PREFS_KEY_SCRIPT_ONLY, true);
39:
40: _dlg.txtTableName.setText(tempSqlResultTable);
41: _dlg.chkDropTable.setSelected(dropTable);
42: _dlg.chkScriptOnly.setSelected(scriptOnly);
43:
44: _dlg.setSize(360, 160);
45: GUIUtils.centerWithinParent(_dlg);
46:
47: _dlg.setVisible(true);
48:
49: }
50:
51: private void onCancel() {
52: //System.out.println(_dlg.getSize());
53: close();
54: }
55:
56: private void onOK() {
57: _isOk = true;
58: Preferences.userRoot().put(PREFS_KEY_LAST_TABLE_NAME,
59: _dlg.txtTableName.getText());
60: Preferences.userRoot().putBoolean(PREFS_KEY_DROP_TABLE,
61: _dlg.chkDropTable.isSelected());
62: Preferences.userRoot().putBoolean(PREFS_KEY_SCRIPT_ONLY,
63: _dlg.chkScriptOnly.isSelected());
64: close();
65: }
66:
67: private void close() {
68: _dlg.setVisible(false);
69: _dlg.dispose();
70: }
71:
72: public boolean isOK() {
73: return _isOk;
74: }
75:
76: public String getTableName() {
77: return _dlg.txtTableName.getText();
78: }
79:
80: public boolean isScriptOnly() {
81: return _dlg.chkScriptOnly.isSelected();
82: }
83:
84: public boolean isDropTable() {
85: return _dlg.chkDropTable.isSelected();
86: }
87: }
|