001: package net.sourceforge.squirrel_sql.plugins.sqlval;
002:
003: /*
004: * Copyright (C) 2002-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.GridBagConstraints;
022: import java.awt.GridBagLayout;
023: import java.awt.Insets;
024: import java.awt.event.ActionEvent;
025: import java.awt.event.ActionListener;
026:
027: import javax.swing.BorderFactory;
028: import javax.swing.JButton;
029: import javax.swing.JDialog;
030: import javax.swing.JPanel;
031:
032: import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
033: import net.sourceforge.squirrel_sql.fw.util.BaseException;
034: import net.sourceforge.squirrel_sql.fw.util.StringManager;
035: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
036: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
037: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
038: import net.sourceforge.squirrel_sql.plugins.sqlval.cmd.ConnectCommand;
039: import net.sourceforge.squirrel_sql.plugins.sqlval.cmd.DisconnectCommand;
040:
041: import net.sourceforge.squirrel_sql.client.session.ISession;
042:
043: public class LogonDialog extends JDialog {
044: private static final StringManager s_stringMgr = StringManagerFactory
045: .getStringManager(LogonDialog.class);
046:
047: /** Logger for this class. */
048: private final static ILogger s_log = LoggerController
049: .createLogger(LogonDialog.class);
050:
051: /** Current session. */
052: private final ISession _session;
053:
054: private final WebServicePreferences _prefs;
055:
056: private final WebServiceSessionProperties _sessionProps;
057:
058: /** Application preferences panel. */
059: private AppPreferencesPanel _appPrefsPnl;
060:
061: /** Confirmation panel. */
062: private SessionSettingsPanel _confirmPnl;
063:
064: public LogonDialog(ISession session, WebServicePreferences prefs,
065: WebServiceSessionProperties sessionProps) {
066: // i18n[sqlval.logon=SQL Validation Logon]
067: super (session.getApplication().getMainFrame(), s_stringMgr
068: .getString("sqlval.logon"), true);
069:
070: if (session == null) {
071: throw new IllegalArgumentException("ISession = null");
072: }
073: if (prefs == null) {
074: throw new IllegalArgumentException(
075: "WebServicePreferences = null");
076: }
077: if (sessionProps == null) {
078: throw new IllegalArgumentException(
079: "WebServiceSessionProperties = null");
080: }
081:
082: _session = session;
083: _prefs = prefs;
084: _sessionProps = sessionProps;
085:
086: createGUI();
087:
088: // Close existing session.
089: try {
090: new DisconnectCommand(_session, _prefs, _sessionProps)
091: .execute();
092: } catch (BaseException ex) {
093: s_log.error(ex);
094: }
095: }
096:
097: /**
098: * Close this dialog.
099: */
100: private void performClose() {
101: dispose();
102: }
103:
104: /**
105: * OK button pressed so logon to web service.
106: */
107: private void performOk() {
108: _appPrefsPnl.save();
109: _confirmPnl.save();
110:
111: // Connect.
112: ConnectCommand cmd = new ConnectCommand(_session, _prefs,
113: _sessionProps);
114: try {
115: cmd.execute();
116: dispose();
117: } catch (Throwable th) {
118: final String msg = "Error occured when talking to the web service";
119: s_log.error(msg, th);
120: _session.getApplication().showErrorDialog(msg, th);
121: }
122: }
123:
124: /**
125: * Create this sheets user interface.
126: */
127: private void createGUI() {
128: setDefaultCloseOperation(DISPOSE_ON_CLOSE);
129:
130: final JPanel contentPane = new JPanel(new GridBagLayout());
131: contentPane.setBorder(BorderFactory.createEmptyBorder());
132: setContentPane(contentPane);
133:
134: final GridBagConstraints gbc = new GridBagConstraints();
135: gbc.fill = GridBagConstraints.BOTH;
136: gbc.insets = new Insets(1, 4, 1, 4);
137: gbc.weightx = 1;
138:
139: gbc.weighty = 1;
140: gbc.gridx = 0;
141: gbc.gridy = 0;
142: _appPrefsPnl = new AppPreferencesPanel(_prefs);
143: contentPane.add(_appPrefsPnl, gbc);
144:
145: gbc.weighty = 0;
146: ++gbc.gridy;
147: _confirmPnl = new SessionSettingsPanel(_prefs, _sessionProps);
148: contentPane.add(_confirmPnl, gbc);
149:
150: ++gbc.gridy;
151: contentPane.add(createButtonsPanel(), gbc);
152:
153: pack();
154: GUIUtils.centerWithinParent(this );
155: setResizable(true);
156: }
157:
158: /**
159: * Create panel at bottom containing the buttons.
160: *
161: * @return New panel.
162: */
163: private JPanel createButtonsPanel() {
164: JPanel pnl = new JPanel();
165:
166: // i18n[sqlval.logonOk=OK]
167: JButton okBtn = new JButton(s_stringMgr
168: .getString("sqlval.logonOk"));
169: okBtn.addActionListener(new ActionListener() {
170: public void actionPerformed(ActionEvent evt) {
171: performOk();
172: }
173: });
174: // i18n[sqlval.logonClose=Close]
175: JButton closeBtn = new JButton(s_stringMgr
176: .getString("sqlval.logonClose"));
177: closeBtn.addActionListener(new ActionListener() {
178: public void actionPerformed(ActionEvent evt) {
179: performClose();
180: }
181: });
182:
183: GUIUtils
184: .setJButtonSizesTheSame(new JButton[] { okBtn, closeBtn });
185:
186: pnl.add(okBtn);
187: pnl.add(closeBtn);
188:
189: getRootPane().setDefaultButton(okBtn);
190:
191: return pnl;
192: }
193: }
|