001: package org.jsqltool.conn.gui;
002:
003: import java.awt.*;
004: import javax.swing.*;
005: import java.awt.event.*;
006: import java.sql.Connection;
007: import org.jsqltool.conn.*;
008: import org.jsqltool.utils.Options;
009:
010: /**
011: * <p>Title: JSqlTool Project</p>
012: * <p>Description: Dialog used to edit/delete a connection.
013: * </p>
014: * <p>Copyright: Copyright (C) 2006 Mauro Carniel</p>
015: *
016: * <p> This file is part of JSqlTool project.
017: * This library is free software; you can redistribute it and/or
018: * modify it under the terms of the (LGPL) Lesser General Public
019: * License as published by the Free Software Foundation;
020: *
021: * GNU LESSER GENERAL PUBLIC LICENSE
022: * Version 2.1, February 1999
023: *
024: * This library is distributed in the hope that it will be useful,
025: * but WITHOUT ANY WARRANTY; without even the implied warranty of
026: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
027: * Library General Public License for more details.
028: *
029: * You should have received a copy of the GNU Library General Public
030: * License along with this library; if not, write to the Free
031: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
032: *
033: * The author may be contacted at:
034: * maurocarniel@tin.it</p>
035: *
036: * @author Mauro Carniel
037: * @version 1.0
038: */
039: public class ConnectionDialog extends JDialog {
040: JPanel mainPanel = new JPanel();
041: BorderLayout borderLayout1 = new BorderLayout();
042: JPanel centralPanel = new JPanel();
043: JPanel buttonsPanel = new JPanel();
044: JButton cancelButton = new JButton();
045: JButton okButton = new JButton();
046: JPanel typePanel = new JPanel();
047: JLabel connTypeLabel = new JLabel();
048: JComboBox connTypeComboBox = new JComboBox(new String[] {
049: Options.getInstance().getResource("oracle database"),
050: Options.getInstance().getResource("ms sqlserver"),
051: Options.getInstance().getResource("odbc source"),
052: Options.getInstance().getResource("other source") });
053: GridBagLayout gridBagLayout1 = new GridBagLayout();
054: JPanel defaultPanel = new JPanel();
055: JPanel odbcPanel = new JPanel();
056: JPanel otherPanel = new JPanel();
057: BorderLayout borderLayout2 = new BorderLayout();
058: JPanel connPanel = new JPanel();
059: JLabel usernameLabel = new JLabel();
060: JTextField usernameTF = new JTextField();
061: JLabel passwdLabel = new JLabel();
062: JPasswordField passwdTF = new JPasswordField();
063: JLabel SIDLabel = new JLabel();
064: JTextField SIDTF = new JTextField();
065: JLabel hostLabel = new JLabel();
066: JTextField hostTF = new JTextField();
067: JLabel portLabel = new JLabel();
068: JTextField portTF = new JTextField();
069: JLabel nameLabel = new JLabel();
070: JTextField nameTF = new JTextField();
071: JCheckBox autoCommitCheckBox = new JCheckBox();
072: JLabel isolLabel = new JLabel();
073: JComboBox isolComboBox = new JComboBox(new String[] {
074: "TRANSACTION_NONE", "TRANSACTION_READ_COMMITTED",
075: "TRANSACTION_READ_UNCOMMITTED",
076: "TRANSACTION_REPEATABLE_READ", "TRANSACTION_SERIALIZABLE" });
077: GridBagLayout gridBagLayout2 = new GridBagLayout();
078: JLabel nameLabel1 = new JLabel();
079: JTextField nameTF1 = new JTextField();
080: JLabel classNameLabel = new JLabel();
081: JTextField classNameTF = new JTextField();
082: JLabel urlLabel = new JLabel();
083: JTextField urlTF = new JTextField();
084: JCheckBox autoCommitCheckBox1 = new JCheckBox();
085: JLabel isolLabel1 = new JLabel();
086: JComboBox isolComboBox1 = new JComboBox(new String[] {
087: "TRANSACTION_NONE", "TRANSACTION_READ_COMMITTED",
088: "TRANSACTION_READ_UNCOMMITTED",
089: "TRANSACTION_REPEATABLE_READ", "TRANSACTION_SERIALIZABLE" });
090: GridBagLayout gridBagLayout3 = new GridBagLayout();
091: ConnectionFrame parent = null;
092: DbConnection c = null;
093: JLabel nameLabel2 = new JLabel();
094: JTextField nameTF2 = new JTextField();
095: JLabel odbcLabel = new JLabel();
096: JTextField odbcTF = new JTextField();
097: JLabel usaernameLabel2 = new JLabel();
098: JTextField usernameTF2 = new JTextField();
099: JLabel passwdLabel2 = new JLabel();
100: JPasswordField passwdTF2 = new JPasswordField();
101: JCheckBox autoCommitCheckBox2 = new JCheckBox();
102: JLabel isolLabel2 = new JLabel();
103: JComboBox isol2ComboBox = new JComboBox(new String[] {
104: "TRANSACTION_NONE", "TRANSACTION_READ_COMMITTED",
105: "TRANSACTION_READ_UNCOMMITTED",
106: "TRANSACTION_REPEATABLE_READ", "TRANSACTION_SERIALIZABLE" });
107: GridBagLayout gridBagLayout4 = new GridBagLayout();
108: private int mode;
109: JCheckBox readonlyCheckBox = new JCheckBox();
110: JCheckBox readonly2CheckBox = new JCheckBox();
111: JCheckBox readonly1CheckBox = new JCheckBox();
112: JCheckBox quotes2CheckBox = new JCheckBox();
113: private JLabel username1Label = new JLabel();
114: private JTextField username1TF = new JTextField();
115: private JLabel passwd1Label = new JLabel();
116: private JPasswordField passwd1TF = new JPasswordField();
117: private JLabel catalogLabel = new JLabel();
118: private JTextField catalog1TF = new JTextField();
119:
120: public static final int EDIT = 0;
121: public static final int INSERT = 1;
122: public static final int COPY = 2;
123:
124: CardLayout cardLayout = new CardLayout();
125:
126: public ConnectionDialog(JFrame frame, ConnectionFrame parent,
127: DbConnection c, int mode) {
128: super (frame, Options.getInstance().getResource(
129: "database connection"), true);
130: this .parent = parent;
131: this .c = c;
132: this .mode = mode;
133: try {
134: jbInit();
135: if (mode != INSERT)
136: init();
137: pack();
138: setSize(500, 450);
139: Dimension screenSize = Toolkit.getDefaultToolkit()
140: .getScreenSize();
141: Dimension frameSize = this .getSize();
142: if (frameSize.height > screenSize.height) {
143: frameSize.height = screenSize.height;
144: }
145: if (frameSize.width > screenSize.width) {
146: frameSize.width = screenSize.width;
147: }
148: this .setLocation((screenSize.width - frameSize.width) / 2,
149: (screenSize.height - frameSize.height) / 2);
150: setVisible(true);
151: } catch (Exception ex) {
152: ex.printStackTrace();
153: }
154: }
155:
156: public ConnectionDialog() {
157: this (null, null, null, 0);
158: }
159:
160: private void init() {
161:
162: nameTF.setText(c.getName());
163: nameTF1.setText(c.getName());
164: nameTF2.setText(c.getName());
165: usernameTF.setText(c.getUsername());
166: passwdTF.setText(c.getPassword());
167: username1TF.setText(c.getUsername());
168: passwd1TF.setText(c.getPassword());
169: catalog1TF.setText(c.getCatalog());
170: usernameTF2.setText(c.getUsername());
171: passwdTF2.setText(c.getPassword());
172: urlTF.setText(c.getUrl());
173: classNameTF.setText(c.getClassName());
174: connTypeComboBox.setSelectedIndex(c.getDbType());
175: autoCommitCheckBox.setSelected(c.isAutoCommit());
176: autoCommitCheckBox1.setSelected(c.isAutoCommit());
177: autoCommitCheckBox2.setSelected(c.isAutoCommit());
178: isolComboBox.setSelectedIndex(c.getIsolationLevel());
179: isolComboBox1.setSelectedIndex(c.getIsolationLevel());
180: isol2ComboBox.setSelectedIndex(c.getIsolationLevel());
181: SIDTF.setText(c.getSID());
182: hostTF.setText(c.getHost());
183: portTF.setText(c.getPort());
184: odbcTF.setText(c.getSID());
185: readonlyCheckBox.setSelected(c.isReadOnly());
186: readonly1CheckBox.setSelected(c.isReadOnly());
187: readonly2CheckBox.setSelected(c.isReadOnly());
188: quotes2CheckBox.setSelected(c.isQuotes());
189: }
190:
191: private void jbInit() throws Exception {
192: connPanel.setLayout(cardLayout);
193:
194: mainPanel.setLayout(borderLayout1);
195: buttonsPanel.setBorder(BorderFactory.createEtchedBorder());
196: cancelButton.setMnemonic(Options.getInstance().getResource(
197: "cancelbutton.mnemonic").charAt(0));
198: cancelButton.setText(Options.getInstance().getResource(
199: "cancelbutton.text"));
200: cancelButton
201: .addActionListener(new ConnectionDialog_cancelButton_actionAdapter(
202: this ));
203: okButton.setMnemonic(Options.getInstance().getResource(
204: "okbutton.mnemonic").charAt(0));
205: okButton.setText(Options.getInstance().getResource(
206: "okbutton.text"));
207: okButton
208: .addActionListener(new ConnectionDialog_okButton_actionAdapter(
209: this ));
210: connTypeLabel.setText(Options.getInstance().getResource(
211: "database type"));
212: typePanel.setLayout(gridBagLayout1);
213: connTypeComboBox
214: .addItemListener(new ConnectionDialog_connTypeComboBox_itemAdapter(
215: this ));
216: centralPanel.setLayout(borderLayout2);
217: defaultPanel.setLayout(gridBagLayout2);
218: usernameLabel.setText(Options.getInstance().getResource(
219: "username"));
220: usernameTF.setText("");
221: usernameTF.setColumns(20);
222: passwdLabel.setText(Options.getInstance().getResource(
223: "password"));
224: passwdTF.setText("");
225: passwdTF.setColumns(20);
226: SIDLabel.setText("SID");
227: SIDTF.setText("");
228: SIDTF.setColumns(20);
229: hostLabel.setText(Options.getInstance().getResource("host"));
230: hostTF.setText("");
231: hostTF.setColumns(20);
232: portLabel.setText(Options.getInstance().getResource("port"));
233: portTF.setText("");
234: portTF.setColumns(5);
235: nameLabel.setText(Options.getInstance().getResource(
236: "connection name"));
237: nameTF.setText("");
238: nameTF.setColumns(20);
239: nameTF.addFocusListener(new java.awt.event.FocusAdapter() {
240: public void focusLost(FocusEvent e) {
241: nameTF_focusLost(e);
242: }
243: });
244: nameTF1.addFocusListener(new java.awt.event.FocusAdapter() {
245: public void focusLost(FocusEvent e) {
246: nameTF1_focusLost(e);
247: }
248: });
249: nameTF2.addFocusListener(new java.awt.event.FocusAdapter() {
250: public void focusLost(FocusEvent e) {
251: nameTF2_focusLost(e);
252: }
253: });
254:
255: autoCommitCheckBox.setText(Options.getInstance().getResource(
256: "auto commit"));
257: isolLabel.setText(Options.getInstance().getResource(
258: "transaction isolation level"));
259: otherPanel.setLayout(gridBagLayout3);
260: nameLabel1.setText(Options.getInstance().getResource(
261: "connection name"));
262: nameTF1.setText("");
263: nameTF1.setColumns(20);
264: classNameLabel.setRequestFocusEnabled(true);
265: classNameLabel.setText(Options.getInstance().getResource(
266: "jdbc driver name"));
267: classNameTF.setText("");
268: classNameTF.setColumns(20);
269: urlLabel.setText(Options.getInstance().getResource(
270: "connection url"));
271: urlTF.setText("");
272: urlTF.setColumns(40);
273: autoCommitCheckBox1.setText(Options.getInstance().getResource(
274: "auto commit"));
275: isolLabel1.setText(Options.getInstance().getResource(
276: "transaction isolation level"));
277: odbcPanel.setLayout(gridBagLayout4);
278: nameLabel2.setText(Options.getInstance().getResource(
279: "connection name"));
280: nameTF2.setText("");
281: nameTF2.setColumns(20);
282: odbcLabel.setText(Options.getInstance().getResource(
283: "odbc entry"));
284: odbcTF.setText("");
285: odbcTF.setColumns(20);
286: usaernameLabel2.setText(Options.getInstance().getResource(
287: "username"));
288: usernameTF2.setText("");
289: usernameTF2.setColumns(20);
290: passwdLabel2.setText(Options.getInstance().getResource(
291: "password"));
292: passwdTF2.setOpaque(true);
293: passwdTF2.setText("");
294: passwdTF2.setColumns(20);
295: autoCommitCheckBox2.setText(Options.getInstance().getResource(
296: "auto commit"));
297: isolLabel2.setText(Options.getInstance().getResource(
298: "transaction isolation level"));
299: readonlyCheckBox.setText(Options.getInstance().getResource(
300: "read only"));
301: readonly2CheckBox.setText(Options.getInstance().getResource(
302: "read only"));
303: quotes2CheckBox.setText(Options.getInstance().getResource(
304: "add quotes"));
305: readonly1CheckBox.setText(Options.getInstance().getResource(
306: "read only"));
307: username1Label.setText(Options.getInstance().getResource(
308: "username"));
309: username1TF.setColumns(20);
310: passwd1Label.setText(Options.getInstance().getResource(
311: "password"));
312: passwd1TF.setColumns(20);
313: passwd1TF
314: .addActionListener(new ConnectionDialog_passwd1TF_actionAdapter(
315: this ));
316: catalogLabel.setText(Options.getInstance().getResource(
317: "catalog"));
318: catalog1TF.setColumns(20);
319: getContentPane().add(mainPanel);
320: mainPanel.add(centralPanel, BorderLayout.CENTER);
321: centralPanel.add(connPanel, BorderLayout.CENTER);
322: mainPanel.add(buttonsPanel, BorderLayout.SOUTH);
323: buttonsPanel.add(okButton, null);
324: buttonsPanel.add(cancelButton, null);
325: mainPanel.add(typePanel, BorderLayout.NORTH);
326: typePanel.add(connTypeLabel, new GridBagConstraints(0, 0, 1, 1,
327: 0.0, 0.0, GridBagConstraints.WEST,
328: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
329: typePanel.add(connTypeComboBox, new GridBagConstraints(1, 0, 1,
330: 1, 1.0, 0.0, GridBagConstraints.CENTER,
331: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
332: 0, 0));
333: connPanel.add("DEFAULT", defaultPanel);
334: connPanel.add("ODBC", odbcPanel);
335: odbcPanel.add(nameLabel2, new GridBagConstraints(0, 0, 1, 1,
336: 0.0, 0.0, GridBagConstraints.WEST,
337: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
338: defaultPanel.add(usernameLabel, new GridBagConstraints(0, 1, 1,
339: 1, 0.0, 0.0, GridBagConstraints.WEST,
340: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
341: connPanel.add("OTHER", otherPanel);
342: otherPanel.add(nameLabel1, new GridBagConstraints(0, 0, 1, 1,
343: 0.0, 0.0, GridBagConstraints.WEST,
344: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
345: defaultPanel.add(usernameTF, new GridBagConstraints(1, 1, 3, 1,
346: 1.0, 0.0, GridBagConstraints.WEST,
347: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
348: 0, 0));
349: defaultPanel.add(passwdLabel, new GridBagConstraints(0, 2, 1,
350: 1, 0.0, 0.0, GridBagConstraints.WEST,
351: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
352: defaultPanel.add(passwdTF, new GridBagConstraints(1, 2, 3, 1,
353: 1.0, 0.0, GridBagConstraints.WEST,
354: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
355: 0, 0));
356: defaultPanel.add(SIDLabel, new GridBagConstraints(0, 3, 1, 1,
357: 0.0, 0.0, GridBagConstraints.WEST,
358: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
359: defaultPanel.add(SIDTF, new GridBagConstraints(1, 3, 3, 1, 1.0,
360: 0.0, GridBagConstraints.WEST,
361: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
362: 0, 0));
363: defaultPanel.add(hostLabel, new GridBagConstraints(0, 4, 1, 1,
364: 0.0, 0.0, GridBagConstraints.WEST,
365: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
366: defaultPanel.add(hostTF, new GridBagConstraints(1, 4, 3, 1,
367: 1.0, 0.0, GridBagConstraints.WEST,
368: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
369: 0, 0));
370: defaultPanel.add(portLabel, new GridBagConstraints(0, 5, 1, 1,
371: 0.0, 0.0, GridBagConstraints.WEST,
372: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
373: defaultPanel.add(portTF, new GridBagConstraints(1, 5, 3, 1,
374: 0.0, 0.0, GridBagConstraints.WEST,
375: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
376: 0, 0));
377: defaultPanel.add(nameLabel, new GridBagConstraints(0, 0, 1, 1,
378: 0.0, 0.0, GridBagConstraints.WEST,
379: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
380: defaultPanel.add(nameTF, new GridBagConstraints(1, 0, 3, 1,
381: 1.0, 0.0, GridBagConstraints.WEST,
382: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
383: 0, 0));
384: defaultPanel.add(autoCommitCheckBox, new GridBagConstraints(0,
385: 6, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
386: GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
387: defaultPanel.add(isolLabel, new GridBagConstraints(2, 6, 1, 1,
388: 0.0, 0.0, GridBagConstraints.WEST,
389: GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0));
390: defaultPanel.add(isolComboBox, new GridBagConstraints(3, 6, 1,
391: 1, 1.0, 0.0, GridBagConstraints.CENTER,
392: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
393: 0, 0));
394: defaultPanel.add(readonlyCheckBox, new GridBagConstraints(0, 7,
395: 1, 1, 0.0, 1.0, GridBagConstraints.NORTHWEST,
396: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
397: otherPanel.add(nameTF1, new GridBagConstraints(1, 0, 2, 1, 1.0,
398: 0.0, GridBagConstraints.WEST,
399: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
400: 0, 0));
401: otherPanel.add(classNameLabel, new GridBagConstraints(0, 1, 1,
402: 1, 0.0, 0.0, GridBagConstraints.WEST,
403: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
404: otherPanel.add(classNameTF, new GridBagConstraints(1, 1, 2, 1,
405: 1.0, 0.0, GridBagConstraints.WEST,
406: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
407: 0, 0));
408: otherPanel.add(urlLabel, new GridBagConstraints(0, 2, 1, 1,
409: 0.0, 0.0, GridBagConstraints.WEST,
410: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
411: otherPanel.add(urlTF, new GridBagConstraints(1, 2, 2, 1, 1.0,
412: 0.0, GridBagConstraints.WEST,
413: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
414: 0, 0));
415: otherPanel.add(autoCommitCheckBox1, new GridBagConstraints(0,
416: 7, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST,
417: GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
418: odbcPanel.add(nameTF2, new GridBagConstraints(1, 0, 2, 1, 1.0,
419: 0.0, GridBagConstraints.WEST,
420: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
421: 0, 0));
422: odbcPanel.add(odbcLabel, new GridBagConstraints(0, 1, 1, 1,
423: 0.0, 0.0, GridBagConstraints.WEST,
424: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
425: odbcPanel.add(odbcTF, new GridBagConstraints(1, 1, 2, 1, 1.0,
426: 0.0, GridBagConstraints.WEST,
427: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
428: 0, 0));
429: odbcPanel.add(usaernameLabel2, new GridBagConstraints(0, 2, 1,
430: 1, 0.0, 0.0, GridBagConstraints.WEST,
431: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
432: odbcPanel.add(usernameTF2, new GridBagConstraints(1, 2, 2, 1,
433: 1.0, 0.0, GridBagConstraints.WEST,
434: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
435: 0, 0));
436: odbcPanel.add(passwdLabel2, new GridBagConstraints(0, 3, 1, 1,
437: 0.0, 0.0, GridBagConstraints.WEST,
438: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
439: odbcPanel.add(passwdTF2, new GridBagConstraints(1, 3, 2, 1,
440: 1.0, 0.0, GridBagConstraints.WEST,
441: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
442: 0, 0));
443: odbcPanel.add(autoCommitCheckBox2, new GridBagConstraints(0, 4,
444: 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST,
445: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
446: odbcPanel.add(isolLabel2, new GridBagConstraints(1, 4, 1, 2,
447: 0.0, 0.0, GridBagConstraints.NORTHWEST,
448: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
449: odbcPanel.add(isol2ComboBox, new GridBagConstraints(2, 4, 1, 2,
450: 1.0, 0.0, GridBagConstraints.NORTHWEST,
451: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
452: 0, 0));
453: odbcPanel.add(readonly2CheckBox, new GridBagConstraints(0, 5,
454: 1, 1, 0.0, 1.0, GridBagConstraints.NORTHWEST,
455: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
456: otherPanel.add(readonly1CheckBox, new GridBagConstraints(0, 8,
457: 1, 1, 0.0, 1.0, GridBagConstraints.NORTHWEST,
458: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
459: otherPanel.add(username1Label, new GridBagConstraints(0, 3, 1,
460: 1, 0.0, 0.0, GridBagConstraints.WEST,
461: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
462: otherPanel.add(username1TF, new GridBagConstraints(1, 3, 1, 1,
463: 0.0, 0.0, GridBagConstraints.WEST,
464: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
465: 0, 0));
466: otherPanel.add(passwd1Label, new GridBagConstraints(0, 4, 1, 2,
467: 0.0, 0.0, GridBagConstraints.WEST,
468: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
469: otherPanel.add(isolLabel1, new GridBagConstraints(1, 7, 1, 2,
470: 0.0, 0.0, GridBagConstraints.NORTHWEST,
471: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
472: otherPanel.add(passwd1TF, new GridBagConstraints(1, 4, 1, 1,
473: 0.0, 0.0, GridBagConstraints.WEST,
474: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
475: 0, 0));
476: otherPanel.add(catalogLabel, new GridBagConstraints(0, 6, 1, 1,
477: 0.0, 0.0, GridBagConstraints.NORTHWEST,
478: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
479: otherPanel.add(catalog1TF, new GridBagConstraints(1, 6, 1, 1,
480: 0.0, 0.0, GridBagConstraints.WEST,
481: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
482: 0, 0));
483: otherPanel.add(isolComboBox1, new GridBagConstraints(2, 7, 1,
484: 1, 1.0, 0.0, GridBagConstraints.WEST,
485: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
486: 0, 0));
487: otherPanel.add(quotes2CheckBox, new GridBagConstraints(0, 9, 1,
488: 1, 0.0, 1.0, GridBagConstraints.NORTHWEST,
489: GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
490:
491: cardLayout.show(connPanel, "DEFAULT");
492: }
493:
494: void okButton_actionPerformed(ActionEvent e) {
495: if (connTypeComboBox.getSelectedIndex() == 3) {
496: if (nameTF1.getText().length() == 0) {
497: JOptionPane.showMessageDialog(this , Options
498: .getInstance().getResource(
499: "you must specify a connection name."),
500: Options.getInstance().getResource("attention"),
501: JOptionPane.WARNING_MESSAGE);
502: return;
503: }
504: if (classNameTF.getText().length() == 0) {
505: JOptionPane.showMessageDialog(this , Options
506: .getInstance().getResource(
507: "you must specify a jdbc driver."),
508: Options.getInstance().getResource("attention"),
509: JOptionPane.WARNING_MESSAGE);
510: return;
511: }
512: if (urlTF.getText().length() == 0) {
513: JOptionPane.showMessageDialog(this , Options
514: .getInstance().getResource(
515: "you must specify a connection url."),
516: Options.getInstance().getResource("attention"),
517: JOptionPane.WARNING_MESSAGE);
518: return;
519: }
520: if (username1TF.getText().length() == 0) {
521: JOptionPane
522: .showMessageDialog(
523: this ,
524: Options
525: .getInstance()
526: .getResource(
527: "you must specify a connection username."),
528: Options.getInstance().getResource(
529: "attention"),
530: JOptionPane.WARNING_MESSAGE);
531: return;
532: }
533: /*
534: if (passwd1TF.getText().length()==0) {
535: JOptionPane.showMessageDialog(this,"E' necessario specificare la password di connessione.");
536: return;
537: }
538: */
539: c.setReadOnly(readonly1CheckBox.isSelected());
540: c.setAutoCommit(autoCommitCheckBox1.isSelected());
541: c.setClassName(classNameTF.getText());
542: c.setDbType(c.OTHER_TYPE);
543: c.setIsolationLevel(isolComboBox1.getSelectedIndex());
544: c.setName(nameTF1.getText());
545: c.setUrl(urlTF.getText());
546: c.setUsername(username1TF.getText());
547: c.setPassword(passwd1TF.getText());
548: c.setCatalog(catalog1TF.getText());
549: c.setQuotes(quotes2CheckBox.isSelected());
550: } else if (connTypeComboBox.getSelectedIndex() == 2) {
551: if (nameTF2.getText().length() == 0) {
552: JOptionPane.showMessageDialog(this , Options
553: .getInstance().getResource(
554: "you must specify a connection name."),
555: Options.getInstance().getResource("attention"),
556: JOptionPane.WARNING_MESSAGE);
557: return;
558: }
559: /*
560: if (usernameTF2.getText().length()==0) {
561: JOptionPane.showMessageDialog(this,"E' necessario specificare lo username di connessione.");
562: return;
563: }
564: */
565: /*
566: if (passwdTF2.getText().length()==0) {
567: JOptionPane.showMessageDialog(this,"E' necessario specificare la password di connessione.");
568: return;
569: }
570: */
571: if (odbcTF.getText().length() == 0) {
572: JOptionPane.showMessageDialog(this , Options
573: .getInstance().getResource(
574: "you must specify an odbc entry."),
575: Options.getInstance().getResource("attention"),
576: JOptionPane.WARNING_MESSAGE);
577: return;
578: }
579: c.setReadOnly(readonly2CheckBox.isSelected());
580: c.setAutoCommit(autoCommitCheckBox2.isSelected());
581: c.setClassName(c.getClassName(connTypeComboBox
582: .getSelectedIndex()));
583: c.setDbType(c.ODBC_TYPE);
584: c.setIsolationLevel(isol2ComboBox.getSelectedIndex());
585: c.setName(nameTF2.getText());
586: c.setUrl(c.getUrl(connTypeComboBox.getSelectedIndex(), "",
587: "", odbcTF.getText()));
588: c.setUsername(usernameTF2.getText());
589: c.setPassword(passwdTF2.getText());
590: c.setCatalog("");
591: } else {
592: if (nameTF.getText().length() == 0) {
593: JOptionPane.showMessageDialog(this , Options
594: .getInstance().getResource(
595: "you must specify a connection name."),
596: Options.getInstance().getResource("attention"),
597: JOptionPane.WARNING_MESSAGE);
598: return;
599: }
600: if (usernameTF.getText().length() == 0) {
601: JOptionPane
602: .showMessageDialog(
603: this ,
604: Options
605: .getInstance()
606: .getResource(
607: "you must specify a connection username."),
608: Options.getInstance().getResource(
609: "attention"),
610: JOptionPane.WARNING_MESSAGE);
611: return;
612: }
613: /*
614: if (passwdTF.getText().length()==0) {
615: JOptionPane.showMessageDialog(this,"E' necessario specificare la password di connessione.");
616: return;
617: }
618: */
619: c.setReadOnly(readonlyCheckBox.isSelected());
620: c.setAutoCommit(autoCommitCheckBox.isSelected());
621: c.setClassName(c.getClassName(connTypeComboBox
622: .getSelectedIndex()));
623: c.setDbType(connTypeComboBox.getSelectedIndex());
624: c.setIsolationLevel(isolComboBox.getSelectedIndex());
625: c.setName(nameTF.getText());
626: c.setUrl(c
627: .getUrl(connTypeComboBox.getSelectedIndex(), hostTF
628: .getText(), portTF.getText(), SIDTF
629: .getText()));
630: c.setUsername(usernameTF.getText());
631: c.setPassword(passwdTF.getText());
632: if (connTypeComboBox.getSelectedIndex() == DbConnection.SQLSERVER_TYPE)
633: c.setCatalog("");
634: else
635: c.setCatalog(usernameTF.getText());
636: }
637: try {
638: parent.updateList(c, mode == EDIT);
639: setVisible(false);
640: dispose();
641: } catch (Exception ex) {
642: }
643: }
644:
645: void cancelButton_actionPerformed(ActionEvent e) {
646: setVisible(false);
647: dispose();
648: }
649:
650: void connTypeComboBox_itemStateChanged(ItemEvent e) {
651: if (connTypeComboBox.getSelectedIndex() == 3) {
652: cardLayout.show(connPanel, "OTHER");
653: } else if (connTypeComboBox.getSelectedIndex() == 2) {
654: cardLayout.show(connPanel, "ODBC");
655: } else {
656: cardLayout.show(connPanel, "DEFAULT");
657: if (mode == INSERT) {
658: if (connTypeComboBox.getSelectedIndex() == DbConnection.ORACLE_TYPE)
659: portTF.setText("1521");
660: else if (connTypeComboBox.getSelectedIndex() == DbConnection.SQLSERVER_TYPE)
661: portTF.setText("1434");
662:
663: }
664:
665: }
666: }
667:
668: void passwd1TF_actionPerformed(ActionEvent e) {
669:
670: }
671:
672: void nameTF_focusLost(FocusEvent e) {
673: nameTF.setText(nameTF.getText().replace(' ', '_'));
674: }
675:
676: void nameTF1_focusLost(FocusEvent e) {
677: nameTF1.setText(nameTF1.getText().replace(' ', '_'));
678: }
679:
680: void nameTF2_focusLost(FocusEvent e) {
681: nameTF2.setText(nameTF2.getText().replace(' ', '_'));
682: }
683:
684: }
685:
686: class ConnectionDialog_okButton_actionAdapter implements
687: java.awt.event.ActionListener {
688: ConnectionDialog adaptee;
689:
690: ConnectionDialog_okButton_actionAdapter(ConnectionDialog adaptee) {
691: this .adaptee = adaptee;
692: }
693:
694: public void actionPerformed(ActionEvent e) {
695: adaptee.okButton_actionPerformed(e);
696: }
697: }
698:
699: class ConnectionDialog_cancelButton_actionAdapter implements
700: java.awt.event.ActionListener {
701: ConnectionDialog adaptee;
702:
703: ConnectionDialog_cancelButton_actionAdapter(ConnectionDialog adaptee) {
704: this .adaptee = adaptee;
705: }
706:
707: public void actionPerformed(ActionEvent e) {
708: adaptee.cancelButton_actionPerformed(e);
709: }
710: }
711:
712: class ConnectionDialog_connTypeComboBox_itemAdapter implements
713: java.awt.event.ItemListener {
714: ConnectionDialog adaptee;
715:
716: ConnectionDialog_connTypeComboBox_itemAdapter(
717: ConnectionDialog adaptee) {
718: this .adaptee = adaptee;
719: }
720:
721: public void itemStateChanged(ItemEvent e) {
722: adaptee.connTypeComboBox_itemStateChanged(e);
723: }
724: }
725:
726: class ConnectionDialog_passwd1TF_actionAdapter implements
727: java.awt.event.ActionListener {
728: private ConnectionDialog adaptee;
729:
730: ConnectionDialog_passwd1TF_actionAdapter(ConnectionDialog adaptee) {
731: this .adaptee = adaptee;
732: }
733:
734: public void actionPerformed(ActionEvent e) {
735: adaptee.passwd1TF_actionPerformed(e);
736: }
737: }
|