EADS-3135 : remove dialog: "connecting to database" shown every time
authorShanil Amarasinghe <shanil@netbeans.org>
Wed, 20 Mar 2013 09:26:49 +0530
changeset 3649e73a3750d14
parent 363 3bf19a69e02b
child 365 f78fc8ad0687
EADS-3135 : remove dialog: "connecting to database" shown every time
Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionManager.java
     1.1 --- a/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionManager.java	Tue Mar 19 15:05:21 2013 +0100
     1.2 +++ b/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseConnectionManager.java	Wed Mar 20 09:26:49 2013 +0530
     1.3 @@ -97,6 +97,7 @@
     1.4      private static final Logger logger = Logger.getLogger(DatabaseConnectionManager.class.getName());
     1.5      private static final RequestProcessor RP = new RequestProcessor(DatabaseConnectionManager.class);
     1.6      private DatabaseConnection reverseConnection;
     1.7 +    private static List<String> failedConnections = new ArrayList<String>();
     1.8  
     1.9      static {
    1.10          String tempDir = System.getProperty("java.io.tmpdir");
    1.11 @@ -352,6 +353,11 @@
    1.12          }
    1.13  
    1.14          if (!online) {
    1.15 +            if (force) {
    1.16 +                if (failedConnections.contains(templateConnection.getName())) {
    1.17 +                    failedConnections.remove(templateConnection.getName());
    1.18 +                }
    1.19 +            }
    1.20              connect(templateConnection);
    1.21          }
    1.22          if (!online) {
    1.23 @@ -463,29 +469,34 @@
    1.24                      setOnline(true);
    1.25                      usagesEnabled = isFindUsagesEnabled();
    1.26                  }
    1.27 +                if (failedConnections.contains(connection.getName())) { 
    1.28 +                    failedConnections.remove(connection.getName());
    1.29 +                }                  
    1.30                  return;
    1.31              } else {
    1.32 -                if (SwingUtilities.isEventDispatchThread()) {
    1.33 -                    try {
    1.34 -                        ConnectionManager.getDefault().showConnectionDialog(connection);
    1.35 -                    } catch (NullPointerException e) {
    1.36 -                        failed = true;
    1.37 -                    } catch (IllegalStateException e) {
    1.38 -                        failed = true;
    1.39 -                    }
    1.40 -                } else {
    1.41 -                    try {
    1.42 -                        SwingUtilities.invokeAndWait(new Runnable() {
    1.43 +                if (!failedConnections.contains(connection.getName())) {
    1.44 +                    if (SwingUtilities.isEventDispatchThread()) {
    1.45 +                        try {
    1.46 +                            ConnectionManager.getDefault().showConnectionDialog(connection);
    1.47 +                        } catch (NullPointerException e) {
    1.48 +                            failed = true;
    1.49 +                        } catch (IllegalStateException e) {
    1.50 +                            failed = true;
    1.51 +                        }
    1.52 +                    } else {
    1.53 +                        try {
    1.54 +                            SwingUtilities.invokeAndWait(new Runnable() {
    1.55  
    1.56 -                            @Override
    1.57 -                            public void run() {
    1.58 -                                ConnectionManager.getDefault().showConnectionDialog(connection);
    1.59 -                            }
    1.60 -                        });
    1.61 -                    } catch (InterruptedException e) {
    1.62 -                        failed = true;
    1.63 -                    } catch (InvocationTargetException e) {
    1.64 -                        failed = true;
    1.65 +                                @Override
    1.66 +                                public void run() {
    1.67 +                                    ConnectionManager.getDefault().showConnectionDialog(connection);
    1.68 +                                }
    1.69 +                            });
    1.70 +                        } catch (InterruptedException e) {
    1.71 +                            failed = true;
    1.72 +                        } catch (InvocationTargetException e) {
    1.73 +                            failed = true;
    1.74 +                        }
    1.75                      }
    1.76                  }
    1.77                  if ((connection.getJDBCConnection() == null || connection.getJDBCConnection().isClosed())) {
    1.78 @@ -519,7 +530,10 @@
    1.79          }
    1.80          failed = failed || !testConnection(connection);
    1.81          if (failed) {
    1.82 -            JOptionPane.showMessageDialog(null, "Can't connect to the database.");
    1.83 +            if (!failedConnections.contains(connection.getName())) {
    1.84 +               JOptionPane.showMessageDialog(null, "Can't connect to the database.");
    1.85 +               failedConnections.add(connection.getName());
    1.86 +            }
    1.87          }
    1.88          if (databaseConnectionsAreEqual(connection, templateConnection)) {
    1.89              setOnline(!failed);
    1.90 @@ -527,6 +541,11 @@
    1.91                  usagesEnabled = isFindUsagesEnabled();
    1.92              }
    1.93          }
    1.94 +        if (!failed) {
    1.95 +           if (failedConnections.contains(connection.getName())) { 
    1.96 +               failedConnections.remove(connection.getName());
    1.97 +           }
    1.98 +        }
    1.99      }
   1.100  
   1.101      public boolean hasConnection() {