001: package org.dbbrowser.ui;
002:
003: import java.awt.Component;
004: import java.awt.Cursor;
005: import java.awt.GridLayout;
006: import java.awt.Image;
007: import java.awt.event.ActionEvent;
008: import java.awt.event.ActionListener;
009: import java.awt.event.MouseAdapter;
010: import java.awt.event.MouseEvent;
011: import java.io.File;
012: import java.io.IOException;
013: import java.util.ArrayList;
014: import java.util.Collections;
015: import java.util.Date;
016: import java.util.List;
017: import infrastructure.internationalization.InternationalizationManager;
018: import infrastructure.logging.Log;
019: import infrastructure.propertymanager.PropertyManager;
020: import infrastructure.propertymanager.PropertyManagementException;
021: import javax.swing.*;
022: import org.dbbrowser.DBBrowser;
023: import org.dbbrowser.db.engine.exception.DBEngineException;
024: import org.dbbrowser.drivermanager.ConnectionInfo;
025: import org.dbbrowser.drivermanager.ConnectionInfoSerializer;
026: import org.dbbrowser.drivermanager.ConnectionInfoSorter;
027: import org.dbbrowser.drivermanager.ConnectionInfos;
028: import org.dbbrowser.drivermanager.DriverManagerException;
029: import org.dbbrowser.drivermanager.DBBrowserDriverManager;
030: import org.dbbrowser.ui.helper.ConnectionInfoFileFilter;
031: import org.dbbrowser.ui.panel.connectioninformationwindow.KnownConnectionsPanel;
032: import org.dbbrowser.ui.panel.connectioninformationwindow.NewConnectionDetailsPanel;
033: import org.dbbrowser.ui.panel.connectioninformationwindow.PasswordInputWindow;
034: import org.dbbrowser.help.HelpManager;
035:
036: public class ConnectionInformationWindow implements ActionListener {
037: private static final String TITLE = InternationalizationManager
038: .getInstance().getMessage("dbbrowser-ui",
039: "dbbrowser-ui-dbbrowser-window-title-label", null);;
040:
041: private static final String CONNECT_BUTTON_LABEL = InternationalizationManager
042: .getInstance()
043: .getMessage(
044: "dbbrowser-ui",
045: "dbbrowser-ui-known-connections-panel-connect-button-label",
046: null);
047: private static final String EDIT_CONNECTION_INFO_LABEL = InternationalizationManager
048: .getInstance()
049: .getMessage(
050: "dbbrowser-ui",
051: "dbbrowser-ui-known-connections-panel-edit-connection-info-button-label",
052: null);
053: private static final String DELETE_CONNECTION_INFO_LABEL = InternationalizationManager
054: .getInstance()
055: .getMessage(
056: "dbbrowser-ui",
057: "dbbrowser-ui-known-connections-panel-delete-connection-info-button-label",
058: null);
059: private static final String SAVE_CHANGES_BUTTON_LABEL = InternationalizationManager
060: .getInstance()
061: .getMessage(
062: "dbbrowser-ui",
063: "dbbrowser-ui-new-connections-details-panel-save-changes-button-label",
064: null);
065: private static final String TEST_CONNECTION_BUTTON_LABEL = InternationalizationManager
066: .getInstance()
067: .getMessage(
068: "dbbrowser-ui",
069: "dbbrowser-ui-new-connections-details-panel-test-connection-button-label",
070: null);
071:
072: //Labels for menu
073: private static final String FILE_MENU_LABEL = InternationalizationManager
074: .getInstance().getMessage("dbbrowser-ui",
075: "dbbrowser-ui-connection-info-file-menu-label",
076: null);
077: private static final String FILE_OPEN_MENU_LABEL = InternationalizationManager
078: .getInstance()
079: .getMessage(
080: "dbbrowser-ui",
081: "dbbrowser-ui-connection-info-file-open-menu-label",
082: null);
083: private static final String HELP_MENU_LABEL = InternationalizationManager
084: .getInstance().getMessage("dbbrowser-ui",
085: "dbbrowser-ui-dbbrowser-window-help-menu-label",
086: null);
087: private static final String HELP_MENU_HELP_LABEL = InternationalizationManager
088: .getInstance()
089: .getMessage(
090: "dbbrowser-ui",
091: "dbbrowser-ui-dbbrowser-window-help-menu-help-label",
092: null);
093: private static final String HELP_MENU_COMMENTS_FEEDBACK_LABEL = InternationalizationManager
094: .getInstance()
095: .getMessage(
096: "dbbrowser-ui",
097: "dbbrowser-ui-dbbrowser-window-help-menu-comments-feedback-label",
098: null);
099: private static final String HELP_MENU_ABOUT_LABEL = InternationalizationManager
100: .getInstance()
101: .getMessage(
102: "dbbrowser-ui",
103: "dbbrowser-ui-dbbrowser-window-help-menu-about-label",
104: null);
105: private static final String MASTER_PASSWORD_INPUT_LABEL = InternationalizationManager
106: .getInstance()
107: .getMessage(
108: "dbbrowser-ui",
109: "dbbrowser-ui-known-connections-panel-enter-master-password-message",
110: null);
111:
112: private static final String fileOpenIconFileName = PropertyManager
113: .getInstance()
114: .getProperty(
115: "dbbrowser-ui-connection-info-window-file-open-icon");
116: private static final String helpIconFileName = PropertyManager
117: .getInstance().getProperty(
118: "dbbrowser-ui-dbbrowser-window-toolbar-help-icon");
119: private static final String COMMENTS_FEEDBACK_ICON_FILENAME = PropertyManager
120: .getInstance()
121: .getProperty(
122: "dbbrowser-ui-dbbrowser-window-help-comments-feedback-menu-icon");
123: private static final String aboutIconFileName = PropertyManager
124: .getInstance()
125: .getProperty(
126: "dbbrowser-ui-dbbrowser-window-help-about-menu-icon");
127: private static final String windowIconFileName = PropertyManager
128: .getInstance().getProperty(
129: "dbbrowser-ui-dbbrowser-window-icon-filename");
130: private static final String USE_MASTER_PASSWORD_TO_ENCRYPT_CONNECTION_INFO = PropertyManager
131: .getInstance()
132: .getProperty(
133: "dbbrowser-ui-connection-info-window-use-master-password");
134:
135: private Image windowIcon = (new ImageIcon(windowIconFileName))
136: .getImage();
137:
138: private JFrame connectionInformationWindow = new JFrame();
139: private JMenuBar menuBar = new JMenuBar();
140: private KnownConnectionsPanel knownConnectionsPanel = null;
141: private NewConnectionDetailsPanel newConnectionDetailsPanel = null;
142: private ConnectionInfos connectionInfos = null;
143: private DBBrowserWindow dbBrowserWindow = null;
144:
145: public ConnectionInformationWindow() {
146: loadConnectionInfo();
147: newConnectionDetailsPanel = new NewConnectionDetailsPanel(this );
148: initializeWindow();
149: addMenuBar();
150: }
151:
152: public ConnectionInformationWindow(DBBrowserWindow dbBrowserWindow) {
153: this .dbBrowserWindow = dbBrowserWindow;
154: loadConnectionInfo();
155: newConnectionDetailsPanel = new NewConnectionDetailsPanel(this );
156: initializeWindow();
157: addMenuBar();
158: }
159:
160: private void addMenuBar() {
161: //Setup help menu
162: JMenu fileMenu = new JMenu(FILE_MENU_LABEL);
163: JMenuItem fileOpenMenuHelpItem = new JMenuItem(
164: FILE_OPEN_MENU_LABEL, new ImageIcon(
165: fileOpenIconFileName));
166: fileOpenMenuHelpItem.addActionListener(this );
167: fileMenu.add(fileOpenMenuHelpItem);
168: JMenu helpMenu = new JMenu(HELP_MENU_LABEL);
169: JMenuItem helpMenuHelpItem = new JMenuItem(
170: HELP_MENU_HELP_LABEL, new ImageIcon(helpIconFileName));
171: helpMenuHelpItem.addActionListener(HelpManager.getInstance()
172: .getActionListenerForHelpEvents());
173: helpMenu.add(helpMenuHelpItem);
174: JMenuItem helpMenuCommentsFeedbackItem = new JMenuItem(
175: HELP_MENU_COMMENTS_FEEDBACK_LABEL, new ImageIcon(
176: COMMENTS_FEEDBACK_ICON_FILENAME));
177: helpMenuCommentsFeedbackItem.addActionListener(this );
178: helpMenu.add(helpMenuCommentsFeedbackItem);
179: JMenuItem helpMenuAboutItem = new JMenuItem(
180: HELP_MENU_ABOUT_LABEL, new ImageIcon(aboutIconFileName));
181: helpMenuAboutItem.addActionListener(this );
182: helpMenu.add(helpMenuAboutItem);
183:
184: //Setup the menu bar for the frame
185: this .menuBar.add(fileMenu);
186: this .menuBar.add(helpMenu);
187: this .connectionInformationWindow.setJMenuBar(this .menuBar);
188: }
189:
190: private void initializeWindow() {
191: //Set window properties
192: String formattedMessage = InternationalizationManager
193: .getInstance().getMessage("dbbrowser-ui",
194: "dbbrowser-ui-connection-info-title", null);
195: this .connectionInformationWindow.setTitle(formattedMessage);
196: this .connectionInformationWindow.setSize(800, 600);
197: this .connectionInformationWindow.setLocationRelativeTo(null);
198: this .connectionInformationWindow.setIconImage(windowIcon);
199:
200: //if there is no dbBrowserWindow window open, then exit on close
201: if (this .dbBrowserWindow == null) {
202: this .connectionInformationWindow
203: .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
204: }
205:
206: //Add the panels
207: this .connectionInformationWindow.getContentPane().setLayout(
208: new GridLayout(2, 0));
209: this .connectionInformationWindow.getContentPane().add(
210: this .newConnectionDetailsPanel);
211: }
212:
213: public void show() {
214: //Show the first time message if it has not been shown
215: String firstRunCompleted = PropertyManager.getInstance()
216: .getProperty("dbbrowser-first-run-completed");
217: if ("false".equals(firstRunCompleted)) {
218: //If the fist run was never run, run it and set it to true so it is not shown ever again
219: FirstRunMessageDialog firstRunMessageDialog = new FirstRunMessageDialog();
220: firstRunMessageDialog.show();
221: try {
222: PropertyManager.getInstance().setProperty(
223: "dbbrowser-first-run-completed", "true");
224: } catch (PropertyManagementException exc) {
225: //Ignore it
226: }
227: }
228: this .connectionInformationWindow.setVisible(true);
229: }
230:
231: public void actionPerformed(ActionEvent e) {
232: if (FILE_OPEN_MENU_LABEL.equals(e.getActionCommand())) {
233: //Present a dialog to choose connection info file
234: JFileChooser jfc = new JFileChooser();
235: jfc.setFileFilter(new ConnectionInfoFileFilter());
236: jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
237: jfc.setMultiSelectionEnabled(false);
238: jfc.setCurrentDirectory(new File("."));
239: jfc.showOpenDialog(null);
240: File selectedFile = jfc.getSelectedFile();
241:
242: //if the user has selected a file, load the connection info
243: if (selectedFile != null) {
244: //Set the property
245: try {
246: PropertyManager
247: .getInstance()
248: .setProperty(
249: "dbbrowser.connectioninfo.serialize.location",
250: selectedFile.getAbsolutePath());
251: } catch (PropertyManagementException exc) {
252: String errorMessage = InternationalizationManager
253: .getInstance()
254: .getMessage(
255: "dbbrowser-ui",
256: "dbbrowser-ui-dbbrowser-window-save-property-failed-message",
257: null);
258: JOptionPane.showMessageDialog(null, errorMessage,
259: TITLE, JOptionPane.ERROR_MESSAGE);
260: }
261:
262: //Load the connection info
263: loadConnectionInfo();
264: }
265: }
266:
267: if (CONNECT_BUTTON_LABEL.equals(e.getActionCommand())) {
268: connect();
269: }
270:
271: if (EDIT_CONNECTION_INFO_LABEL.equals(e.getActionCommand())) {
272: Integer selectedRow = this .knownConnectionsPanel
273: .getSelectedRow();
274:
275: //if the source is a row in the table
276: if (selectedRow != null) {
277: //Get the master password from user and set it
278: useMasterPassword();
279:
280: ConnectionInfo ci = (ConnectionInfo) this .connectionInfos
281: .getListOfConnectionInfos().get(
282: selectedRow.intValue());
283: newConnectionDetailsPanel.setConnectionInfo(ci,
284: this .connectionInfos.getMasterPassword());
285: } else {
286: String errorMessage = InternationalizationManager
287: .getInstance()
288: .getMessage(
289: "dbbrowser-ui",
290: "dbbrowser-ui-known-connections-panel-no-connection-selected-error-message",
291: null);
292: JOptionPane.showMessageDialog(null, errorMessage,
293: TITLE, JOptionPane.WARNING_MESSAGE);
294: }
295: }
296:
297: if (DELETE_CONNECTION_INFO_LABEL.equals(e.getActionCommand())) {
298: Integer selectedConnectionInfo = this .knownConnectionsPanel
299: .getSelectedRow();
300:
301: if (selectedConnectionInfo != null) {
302: String connectionInfoDeleteConfirmMessage = InternationalizationManager
303: .getInstance()
304: .getMessage(
305: "dbbrowser-ui",
306: "dbbrowser-ui-known-connections-panel-delete-connection-info-confirm-message",
307: null);
308: int ans = JOptionPane.showConfirmDialog(null,
309: connectionInfoDeleteConfirmMessage, TITLE,
310: JOptionPane.OK_CANCEL_OPTION);
311:
312: if (ans == 0) {
313: try {
314: this .connectionInfos.getListOfConnectionInfos()
315: .remove(
316: selectedConnectionInfo
317: .intValue());
318: ConnectionInfoSerializer
319: .serialize(this .connectionInfos
320: .getListOfConnectionInfos());
321: this .knownConnectionsPanel.update();
322: } catch (IOException exc) {
323: String errorMessage = InternationalizationManager
324: .getInstance()
325: .getMessage(
326: "dbbrowser-ui",
327: "dbbrowser-ui-known-connections-panel-exception-connectioninfo-update-failed",
328: null);
329: JOptionPane.showMessageDialog(null,
330: errorMessage, TITLE,
331: JOptionPane.ERROR_MESSAGE);
332: }
333: }
334: } else {
335: String errorMessage = InternationalizationManager
336: .getInstance()
337: .getMessage(
338: "dbbrowser-ui",
339: "dbbrowser-ui-known-connections-panel-no-connection-selected-error-message",
340: null);
341: JOptionPane.showMessageDialog(null, errorMessage,
342: TITLE, JOptionPane.WARNING_MESSAGE);
343: }
344: }
345:
346: if (TEST_CONNECTION_BUTTON_LABEL.equals(e.getActionCommand())) {
347: //Get the master password from user and set it
348: useMasterPassword();
349:
350: //Build a connection info
351: ConnectionInfo connectionInfo = this .newConnectionDetailsPanel
352: .getConnectionInfo(this .connectionInfos
353: .getMasterPassword());
354: if (connectionInfo == null) {
355: String errorMessageForMissingData = InternationalizationManager
356: .getInstance()
357: .getMessage(
358: "dbbrowser-ui",
359: "dbbrowser-ui-new-connections-details-panel-missing-data-message",
360: null);
361: JOptionPane.showMessageDialog(null,
362: errorMessageForMissingData, TITLE,
363: JOptionPane.ERROR_MESSAGE);
364: } else {
365: //Store the default cursor and show the wait cursor
366: Cursor defaultCursor = Cursor.getDefaultCursor();
367: Cursor waitCursor = Cursor
368: .getPredefinedCursor(Cursor.WAIT_CURSOR);
369: try {
370: //Change the cursor to hourglass
371: this .connectionInformationWindow
372: .setCursor(waitCursor);
373: //Call the Driver Manager to test the connection
374: DBBrowserDriverManager.getInstance().getConnection(
375: connectionInfo,
376: this .connectionInfos.getMasterPassword());
377:
378: String connectionSuccessfulMessage = InternationalizationManager
379: .getInstance()
380: .getMessage(
381: "dbbrowser-ui",
382: "dbbrowser-ui-new-connections-details-panel-test-connection-success-message",
383: null);
384: JOptionPane.showMessageDialog(null,
385: connectionSuccessfulMessage, TITLE,
386: JOptionPane.INFORMATION_MESSAGE);
387: } catch (DriverManagerException exc) {
388: String errorMessage = InternationalizationManager
389: .getInstance()
390: .getMessage(
391: "dbbrowser-ui",
392: "dbbrowser-ui-known-connections-panel-exception-connect-failed",
393: null);
394: JOptionPane.showMessageDialog(null, errorMessage
395: + " - " + exc.getMessage(), TITLE,
396: JOptionPane.ERROR_MESSAGE);
397: } finally {
398: //Change the cursor to normal cursor
399: this .connectionInformationWindow
400: .setCursor(defaultCursor);
401: }
402: }
403: }
404:
405: if (SAVE_CHANGES_BUTTON_LABEL.equals(e.getActionCommand())) {
406: //Get the master password from user and set it
407: useMasterPassword();
408:
409: ConnectionInfo connectionInfo = this .newConnectionDetailsPanel
410: .getConnectionInfo(this .connectionInfos
411: .getMasterPassword());
412: if (connectionInfo == null) {
413: String errorMessageForMissingData = InternationalizationManager
414: .getInstance()
415: .getMessage(
416: "dbbrowser-ui",
417: "dbbrowser-ui-new-connections-details-panel-missing-data-message",
418: null);
419: JOptionPane.showMessageDialog(null,
420: errorMessageForMissingData, TITLE,
421: JOptionPane.ERROR_MESSAGE);
422: } else {
423: try {
424: //If there is a connection info with the same name, overwrite it. ConnectionInfo class overrides equals method and uses name to do the comparision
425: int connectionInfoLocation = this .connectionInfos
426: .getListOfConnectionInfos().indexOf(
427: connectionInfo);
428: if (connectionInfoLocation != -1) {
429: this .connectionInfos.getListOfConnectionInfos()
430: .remove(connectionInfoLocation);
431: this .connectionInfos.getListOfConnectionInfos()
432: .add(connectionInfo);
433: } else {
434: this .connectionInfos.getListOfConnectionInfos()
435: .add(connectionInfo);
436: }
437:
438: //Update the UI and store the settings
439: ConnectionInfoSerializer
440: .serialize(this .connectionInfos
441: .getListOfConnectionInfos());
442: this .knownConnectionsPanel.update();
443: this .newConnectionDetailsPanel.clearFields();
444: } catch (IOException exc) {
445: String[] s = new String[] { exc.getMessage() };
446: String errorMessage = InternationalizationManager
447: .getInstance()
448: .getMessage(
449: "dbbrowser-ui",
450: "dbbrowser-ui-known-new-connections-panel-exception-connectioninfo-update-failed",
451: s);
452: JOptionPane.showMessageDialog(null, errorMessage,
453: TITLE, JOptionPane.ERROR_MESSAGE);
454:
455: //Select file to save to
456: JFileChooser jfc = new JFileChooser();
457: jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
458: jfc.setMultiSelectionEnabled(false);
459: jfc.setCurrentDirectory(new File("."));
460: jfc.showSaveDialog(null);
461: File file = jfc.getSelectedFile();
462:
463: //Set the property
464: try {
465: PropertyManager
466: .getInstance()
467: .setProperty(
468: "dbbrowser.connectioninfo.serialize.location",
469: file.getAbsolutePath());
470: } catch (PropertyManagementException pme) {
471: String errorMessage2 = InternationalizationManager
472: .getInstance()
473: .getMessage(
474: "dbbrowser-ui",
475: "dbbrowser-ui-dbbrowser-window-save-property-failed-message",
476: null);
477: JOptionPane.showMessageDialog(null,
478: errorMessage2, TITLE,
479: JOptionPane.ERROR_MESSAGE);
480: }
481:
482: //Update the UI and store the settings
483: try {
484: ConnectionInfoSerializer
485: .serialize(this .connectionInfos
486: .getListOfConnectionInfos());
487: this .knownConnectionsPanel.update();
488: this .newConnectionDetailsPanel.clearFields();
489: } catch (IOException ioexc) {
490: String[] s2 = new String[] { exc.getMessage() };
491: String errorMessage2 = InternationalizationManager
492: .getInstance()
493: .getMessage(
494: "dbbrowser-ui",
495: "dbbrowser-ui-known-new-connections-panel-exception-connectioninfo-update-failed",
496: s2);
497: JOptionPane.showMessageDialog(null,
498: errorMessage2, TITLE,
499: JOptionPane.ERROR_MESSAGE);
500: }
501: }
502: }
503: }
504:
505: if (HELP_MENU_ABOUT_LABEL.equals(e.getActionCommand())) {
506: AboutWindow aboutWindow = new AboutWindow();
507: aboutWindow.show();
508: }
509:
510: //Show about window
511: if (HELP_MENU_COMMENTS_FEEDBACK_LABEL.equals(e
512: .getActionCommand())) {
513: CommentsFeedbackWindow commentsFeedbackWindow = new CommentsFeedbackWindow();
514: commentsFeedbackWindow.show();
515: }
516: }
517:
518: private void useMasterPassword() {
519: //Get the master password from the user if a master password is to be used and the password has not been set
520: if ("true"
521: .equals(USE_MASTER_PASSWORD_TO_ENCRYPT_CONNECTION_INFO)
522: && (!this .connectionInfos.isPasswordSetByUser()
523: .booleanValue())) {
524: //String masterPassword = (String)JOptionPane.showInputDialog(null,MASTER_PASSWORD_INPUT_LABEL, TITLE, JOptionPane.PLAIN_MESSAGE, null, null, null);
525: PasswordInputWindow piw = new PasswordInputWindow(
526: Boolean.FALSE);
527: piw.show();
528: String masterPassword = piw.getPassword();
529: if (masterPassword != null && (!"".equals(masterPassword))) {
530: this .connectionInfos.setMasterPassword(masterPassword);
531: }
532: }
533: }
534:
535: private void loadConnectionInfo() {
536: List listOfConnectionInfo = new ArrayList();
537: //Get the connection info
538: try {
539: listOfConnectionInfo = ConnectionInfoSerializer
540: .deserialize();
541: Log.getInstance().debugMessage(
542: "Found " + listOfConnectionInfo.size()
543: + " connection info objects",
544: DBBrowser.class.getName());
545:
546: //Sort the listOfConnectionInfo by 'last used' column
547: Collections.sort(listOfConnectionInfo,
548: new ConnectionInfoSorter());
549: } catch (ClassNotFoundException exc) {
550: Log.getInstance().debugMessage("No connection info found",
551: DBBrowser.class.getName());
552: } catch (IOException exc) {
553: Log.getInstance().debugMessage("No connection info found",
554: DBBrowser.class.getName());
555: }
556:
557: this .connectionInfos = new ConnectionInfos(
558: listOfConnectionInfo, null);
559:
560: //Remove the current known connections panel
561: if (this .knownConnectionsPanel != null) {
562: this .connectionInformationWindow.getContentPane().remove(
563: this .knownConnectionsPanel);
564: }
565:
566: //Add the new known connections panel
567: knownConnectionsPanel = new KnownConnectionsPanel(
568: this .connectionInfos, this , new TableMouseListener());
569: this .connectionInformationWindow.getContentPane().add(
570: this .knownConnectionsPanel, 0);
571: this .knownConnectionsPanel.updateUI();
572: }
573:
574: private void connect() {
575: Integer selectedConnectionInfo = this .knownConnectionsPanel
576: .getSelectedRow();
577:
578: if (selectedConnectionInfo != null) {
579: ConnectionInfo connectionInfo = (ConnectionInfo) this .connectionInfos
580: .getListOfConnectionInfos().get(
581: selectedConnectionInfo.intValue());
582:
583: try {
584: //Store the default cursor and show the wait cursor
585: Cursor defaultCursor = Cursor.getDefaultCursor();
586: Cursor waitCursor = Cursor
587: .getPredefinedCursor(Cursor.WAIT_CURSOR);
588:
589: //Change the cursor to hourglass
590: try {
591: this .connectionInformationWindow
592: .setCursor(waitCursor);
593:
594: //Update the connection info
595: connectionInfo.setLastUsed(new Date());
596: ConnectionInfoSerializer
597: .serialize(this .connectionInfos
598: .getListOfConnectionInfos());
599:
600: //Show the DBBrowser window
601: if (this .dbBrowserWindow == null) {
602: dbBrowserWindow = new DBBrowserWindow();
603: }
604:
605: //Get the master password from user and set it
606: useMasterPassword();
607:
608: dbBrowserWindow.setupTabbedPane(connectionInfo,
609: this .connectionInfos.getMasterPassword());
610: } finally {
611: //Change the cursor to normal cursor
612: this .connectionInformationWindow
613: .setCursor(defaultCursor);
614: }
615:
616: dbBrowserWindow.showSQLLog();
617:
618: //Close the connection information window - this window
619: this .connectionInformationWindow.dispose();
620: this .connectionInformationWindow = null;
621: } catch (DriverManagerException exc) {
622: String errorMessage = InternationalizationManager
623: .getInstance()
624: .getMessage(
625: "dbbrowser-ui",
626: "dbbrowser-ui-known-connections-panel-exception-connect-failed",
627: null);
628: JOptionPane.showMessageDialog(null, errorMessage
629: + " - " + exc.getMessage(), TITLE,
630: JOptionPane.ERROR_MESSAGE);
631: } catch (DBEngineException exc) {
632: String errorMessage = InternationalizationManager
633: .getInstance()
634: .getMessage(
635: "dbbrowser-ui",
636: "dbbrowser-ui-known-connections-panel-exception-connect-failed",
637: null);
638: JOptionPane.showMessageDialog(null, errorMessage
639: + " - " + exc.getMessage(), TITLE,
640: JOptionPane.ERROR_MESSAGE);
641: } catch (IOException exc) {
642: String errorMessage = InternationalizationManager
643: .getInstance()
644: .getMessage(
645: "dbbrowser-ui",
646: "dbbrowser-ui-known-connections-panel-exception-connect-failed",
647: null);
648: JOptionPane.showMessageDialog(null, errorMessage
649: + " - " + exc.getMessage(), TITLE,
650: JOptionPane.ERROR_MESSAGE);
651: }
652: } else {
653: String errorMessage = InternationalizationManager
654: .getInstance()
655: .getMessage(
656: "dbbrowser-ui",
657: "dbbrowser-ui-known-connections-panel-no-connection-selected-error-message",
658: null);
659: JOptionPane.showMessageDialog(null, errorMessage, TITLE,
660: JOptionPane.WARNING_MESSAGE);
661: }
662: }
663:
664: /**
665: * Listener for double clicks
666: * @author amangat
667: */
668: private class TableMouseListener extends MouseAdapter {
669: public void mouseClicked(MouseEvent evt) {
670: if (evt.getClickCount() == 2) {
671: Component sourceComponent = evt.getComponent();
672:
673: //if the source is a jtabel, get the selected row
674: if (sourceComponent instanceof JTable) {
675: connect();
676: }
677: }
678: }
679: }
680: }
|