display warning when user install a not supported driver predefined-connection-188901
authorJiri Rechtacek <jrechtacek@netbeans.org>
Mon, 11 Oct 2010 23:23:48 +0200
branchpredefined-connection-188901
changeset 1829178b5e770f2aa1
parent 182916 cb4aac242e23
child 182918 8fa6553ac40e
display warning when user install a not supported driver
db/src/org/netbeans/modules/db/explorer/dlg/AddConnectionWizard.java
db/src/org/netbeans/modules/db/explorer/dlg/AddDriverDialog.java
db/src/org/netbeans/modules/db/explorer/dlg/Bundle.properties
     1.1 --- a/db/src/org/netbeans/modules/db/explorer/dlg/AddConnectionWizard.java	Mon Oct 11 16:39:27 2010 +0200
     1.2 +++ b/db/src/org/netbeans/modules/db/explorer/dlg/AddConnectionWizard.java	Mon Oct 11 23:23:48 2010 +0200
     1.3 @@ -47,9 +47,11 @@
     1.4  import java.sql.SQLException;
     1.5  import java.text.MessageFormat;
     1.6  import java.util.Collection;
     1.7 -import java.util.Collections;
     1.8 +import java.util.HashSet;
     1.9  import java.util.List;
    1.10  import java.util.NoSuchElementException;
    1.11 +import java.util.Set;
    1.12 +import java.util.StringTokenizer;
    1.13  import java.util.logging.Level;
    1.14  import java.util.logging.Logger;
    1.15  import javax.swing.event.ChangeListener;
    1.16 @@ -76,7 +78,8 @@
    1.17      
    1.18      private String driverName;
    1.19      private String downloadFrom;
    1.20 -    private String driverFileName;
    1.21 +    private final Set<String> allPrivilegedFileNames = new HashSet<String>();
    1.22 +    private String privilegedFileName;
    1.23      private String[] steps;
    1.24      private WizardDescriptor.Panel<AddConnectionWizard>[] panels;
    1.25      private int index;
    1.26 @@ -149,7 +152,7 @@
    1.27                  if (jars != null && jars.length > 0) {
    1.28                          FileObject jarFO = URLMapper.findFileObject(jars[0]);
    1.29                          if (jarFO != null && jarFO.isValid()) {
    1.30 -                            this.driverFileName = jarFO.getNameExt();
    1.31 +                            this.allPrivilegedFileNames.add(jarFO.getNameExt());
    1.32                              this.jdbcDriver = drv;
    1.33                              this.increase = true;
    1.34                          }
    1.35 @@ -305,11 +308,12 @@
    1.36          return downloadFrom;
    1.37      }
    1.38  
    1.39 -    Collection<String> getSupportedNames() {
    1.40 -        if (this.driverFileName == null) {
    1.41 -            return Collections.emptyList();
    1.42 -        }
    1.43 -        return Collections.singleton(this.driverFileName);
    1.44 +    Collection<String> getAllPrivilegedNames() {
    1.45 +        return this.allPrivilegedFileNames;
    1.46 +    }
    1.47 +
    1.48 +    String getPrivilegedName() {
    1.49 +        return this.privilegedFileName;
    1.50      }
    1.51  
    1.52      @Override
    1.53 @@ -352,7 +356,12 @@
    1.54                  this.pwd = NbBundle.getMessage(AddConnectionWizard.class, "OracleSamplePassword"); // NOI18N
    1.55                  this.defaultSchema = NbBundle.getMessage(AddConnectionWizard.class, "OracleSampleSchema"); // NOI18N
    1.56                  this.downloadFrom = NbBundle.getMessage(AddConnectionWizard.class, "oracle.from"); // NOI18N
    1.57 -                this.driverFileName = NbBundle.getMessage(AddConnectionWizard.class, "oracle.driver.name"); // NOI18N
    1.58 +                this.allPrivilegedFileNames.clear();
    1.59 +                this.privilegedFileName = NbBundle.getMessage(AddConnectionWizard.class, "oracle.driver.name"); // NOI18N
    1.60 +                StringTokenizer st = new StringTokenizer(NbBundle.getMessage(AddConnectionWizard.class, "oracle.driver.name.prefix"), ","); // NOI18N
    1.61 +                while (st.hasMoreTokens()) {
    1.62 +                    this.allPrivilegedFileNames.add(st.nextToken().trim());
    1.63 +                }
    1.64              } else if (driverName.contains("MySQL")) { // NOI18N
    1.65                  this.driverDN = NbBundle.getMessage(AddConnectionWizard.class, "MySQLDriverDisplayName"); // NOI18N
    1.66                  this.driverClass = NbBundle.getMessage(AddConnectionWizard.class, "MySQLDriverClass"); // NOI18N
    1.67 @@ -361,7 +370,12 @@
    1.68                  this.pwd = password == null ? NbBundle.getMessage(AddConnectionWizard.class, "MySQLSamplePassword") : password; // NOI18N
    1.69                  this.defaultSchema = NbBundle.getMessage(AddConnectionWizard.class, "MySQLSampleSchema"); // NOI18N
    1.70                  this.downloadFrom = NbBundle.getMessage(AddConnectionWizard.class, "mysql.from"); // NOI18N
    1.71 -                this.driverFileName = NbBundle.getMessage(AddConnectionWizard.class, "mysql.driver.name"); // NOI18N
    1.72 +                this.allPrivilegedFileNames.clear();
    1.73 +                this.privilegedFileName = NbBundle.getMessage(AddConnectionWizard.class, "mysql.driver.name"); // NOI18N
    1.74 +                StringTokenizer st = new StringTokenizer(NbBundle.getMessage(AddConnectionWizard.class, "mysql.driver.name.prefix"), ","); // NOI18N
    1.75 +                while (st.hasMoreTokens()) {
    1.76 +                    this.allPrivilegedFileNames.add(st.nextToken().trim());
    1.77 +                }
    1.78              } else {
    1.79                  // others
    1.80                  this.driverClass = driverClass;
    1.81 @@ -371,7 +385,8 @@
    1.82                  this.defaultSchema = ""; // NOI18N
    1.83                  this.downloadFrom = null;
    1.84                  this.driverDN = null;
    1.85 -                this.driverFileName = null;
    1.86 +                this.privilegedFileName = ""; // NOI18N
    1.87 +                this.allPrivilegedFileNames.clear();
    1.88              }
    1.89          }
    1.90      }
     2.1 --- a/db/src/org/netbeans/modules/db/explorer/dlg/AddDriverDialog.java	Mon Oct 11 16:39:27 2010 +0200
     2.2 +++ b/db/src/org/netbeans/modules/db/explorer/dlg/AddDriverDialog.java	Mon Oct 11 23:23:48 2010 +0200
     2.3 @@ -427,7 +427,7 @@
     2.4  
     2.5          File[] selectedFiles = fileChooserBuilder.showMultiOpenDialog();
     2.6          if (selectedFiles != null) {
     2.7 -            for (File file : selectedFiles) {
     2.8 +            for (final File file : selectedFiles) {
     2.9                  if (file.isFile()) {
    2.10                      if (dlm.contains(file.toString())) {
    2.11                          // file already added
    2.12 @@ -447,6 +447,31 @@
    2.13                                  file.getAbsolutePath() +
    2.14                                  ": can not convert to URL", exc);
    2.15                      }
    2.16 +                    if (wd != null) {
    2.17 +                        boolean privileged = wd.getAllPrivilegedNames().isEmpty();
    2.18 +                        for (String name : wd.getAllPrivilegedNames()) {
    2.19 +                            if (file.getName().startsWith(name)) {
    2.20 +                                privileged = true;
    2.21 +                                break;
    2.22 +                            }
    2.23 +                        }
    2.24 +                        if (privileged) {
    2.25 +                            SwingUtilities.invokeLater(new Runnable() {
    2.26 +                                @Override
    2.27 +                                public void run() {
    2.28 +                                    notifyUser(null, false);
    2.29 +                                }
    2.30 +                            });
    2.31 +                        } else {
    2.32 +                            SwingUtilities.invokeLater(new Runnable() {
    2.33 +                                @Override
    2.34 +                                public void run() {
    2.35 +                                    notifyUser(NbBundle.getMessage(AddDriverDialog.class, "AddDriverDialog_NotPrivilegedDriver", // NOI18N
    2.36 +                                            file.getName(), wd.getPrivilegedName()), true);
    2.37 +                                }
    2.38 +                            });
    2.39 +                        }
    2.40 +                    }
    2.41                  }
    2.42              }
    2.43              findDriverClass();
    2.44 @@ -663,9 +688,17 @@
    2.45                  }
    2.46              }
    2.47          }
    2.48 +        notifyUser(message, false);
    2.49 +    }
    2.50 +
    2.51 +    private void notifyUser(String message, boolean isWarning) {
    2.52          if (descriptor != null) {
    2.53              if (message != null) {
    2.54 -                descriptor.getNotificationLineSupport().setInformationMessage(message);
    2.55 +                if (isWarning) {
    2.56 +                    descriptor.getNotificationLineSupport().setWarningMessage(message);
    2.57 +                } else {
    2.58 +                    descriptor.getNotificationLineSupport().setInformationMessage(message);
    2.59 +                }
    2.60                  descriptor.setValid(false);
    2.61              } else {
    2.62                  descriptor.getNotificationLineSupport().clearMessages();
    2.63 @@ -673,12 +706,16 @@
    2.64              }
    2.65          } else if (wd != null) {
    2.66              if (message != null) {
    2.67 -                wd.getNotificationLineSupport().setInformationMessage(message);
    2.68 +                if (isWarning) {
    2.69 +                    wd.getNotificationLineSupport().setWarningMessage(message);
    2.70 +                } else {
    2.71 +                    wd.getNotificationLineSupport().setInformationMessage(message);
    2.72 +                }
    2.73              } else {
    2.74                  wd.getNotificationLineSupport().clearMessages();
    2.75              }
    2.76          } else {
    2.77 -            Logger.getLogger(AddDriverDialog.class.getName()).log(Level.INFO, "DialogDescriptor or wizard is not set, message: " + message);
    2.78 +            Logger.getLogger(AddDriverDialog.class.getName()).log(Level.INFO, "DialogDescriptor or wizard is not set, cannot display message: " + message);
    2.79          }
    2.80      }
    2.81  
     3.1 --- a/db/src/org/netbeans/modules/db/explorer/dlg/Bundle.properties	Mon Oct 11 16:39:27 2010 +0200
     3.2 +++ b/db/src/org/netbeans/modules/db/explorer/dlg/Bundle.properties	Mon Oct 11 23:23:48 2010 +0200
     3.3 @@ -334,8 +334,10 @@
     3.4  ChoosingSchemaPanel.Name=Choose Database Schema
     3.5  oracle.from=http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html
     3.6  mysql.from=http://dev.mysql.com/downloads/connector/j/
     3.7 +oracle.driver.name.prefix=ojdbc6.jar, ojdbc6_g.jar, ojdbc6dms.jar
     3.8 +mysql.driver.name.prefix=mysql-connector-java
     3.9  oracle.driver.name=ojdbc6.jar
    3.10 -mysql.driver.name=mysql-connector-java-5.1.6-bin.jar
    3.11 +mysql.driver.name=mysql-connector-java-5.1.13-bin.jar
    3.12  ChoosingDriverInterUI.locateDriver=Select {0} driver
    3.13  ChoosingDriverInterUI.errorMessage.DriverNotFound=Specify location of {0} driver.
    3.14  PredefinedWizard.WizardTitle=New Connection Wizard
    3.15 @@ -378,3 +380,4 @@
    3.16  ChoosingDriverUI.lDrivers.text=&Driver:
    3.17  NewConnectionPanel.ConnectionPassed=Connection created.
    3.18  AddDriverDownloadMissingFile=<html>Driver File is missing. Download from <a href="{0}">{0}</a>.</html>
    3.19 +AddDriverDialog_NotPrivilegedDriver=Selected {0} might cause unexpected problems. Use preferred {1}.