removed throwing of runtime exception since we already have a warning (#4365)
authorCherian Mathew <c.mathew@bgbm.org>
Tue, 9 Dec 2014 14:29:27 +0000 (14:29 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Tue, 9 Dec 2014 14:29:27 +0000 (14:29 +0000)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceCredentialsWizardPage.java

index 858214f8782be51b181777868754b8806bd89f11..04c9eb4b51322980ffa8363aa949d837ce3128bf 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
@@ -46,12 +46,12 @@ import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
  */
 public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage implements ModifyListener {
        private ICdmDataSource dataSource;
-       
+
        protected Text text_password;
        protected Text text_databaseName;
        protected Text text_dataSourceName;
        protected Text text_username;
-       
+
        protected Group authenticationGroup;
        protected Group locationGroup;
        protected Group nomenclaturalCodeGroup;
@@ -64,11 +64,11 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
        protected String database;
        protected String username;
        protected String password;
-       
+
        protected NomenclaturalCode nomenclaturalCode;
-       
+
        CdmDataSourceWizard.Mode mode;
-       
+
        /**
         * <p>Constructor for CdmDataSourceCredentialsWizardPage.</p>
         *
@@ -77,10 +77,10 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
        protected CdmDataSourceCredentialsWizardPage(String pageName, ICdmDataSource dataSource) {
                super(pageName);
                this.setPageComplete(false);
-               setDataSource(dataSource);              
+               setDataSource(dataSource);
                mode = CdmDataSourceWizard.Mode.CREATE;
        }
-       
+
        /**
         * <p>Constructor for CdmDataSourceCredentialsWizardPage.</p>
         *
@@ -89,23 +89,24 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
        protected CdmDataSourceCredentialsWizardPage(String pageName, ICdmDataSource dataSource, CdmDataSourceWizard.Mode mode) {
                super(pageName);
                this.setPageComplete(false);
-               
+
                this.mode = mode;
                if(mode == CdmDataSourceWizard.Mode.CLONE) {
-                       setDataSource(CdmDataSource.NewInstance(dataSource));                                           
+                       setDataSource(CdmDataSource.NewInstance(dataSource));
                } else {
-                       setDataSource(dataSource);      
+                       setDataSource(dataSource);
                }
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
         */
        /** {@inheritDoc} */
-       public void createControl(Composite parent) {
+       @Override
+    public void createControl(Composite parent) {
                this.parent = parent;
-               
-               // Create top-level composite 
+
+               // Create top-level composite
                parent.setLayout(new GridLayout());
                composite = new Composite(parent, SWT.NONE);
                composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,2,5));
@@ -132,28 +133,28 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
                if(getDataSource() == null) {
                        editDatasourceComposite.setVisible(false);
                }
-               
+
                // create a database specific form
                createDatabaseForm();
-               
+
                // create the authentication input fields
                createAuthenticationForm();
-               
+
                // create nomenclatural code combo
                createNomenclaturalCodeForm();
-               
+
                // Create composite for buttons
                Composite buttonComposite = new Composite(composite, SWT.NONE);
                buttonComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
                GridLayout buttonLayout = new GridLayout();
                buttonLayout.numColumns = 1;
                buttonComposite.setLayout(buttonLayout);
-               
+
                // Create test connection button
                Button testButton = new Button(buttonComposite, SWT.NONE);
                testButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
                testButton.setText("Test connection");
-               
+
                // Test connection when button is pressed
                testButton.addSelectionListener(new SelectionAdapter() {
                        /* (non-Javadoc)
@@ -164,11 +165,11 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
                                testDbConfiguration();
                        }
                });
-               
+
                setControl(composite);
-                               
-               init(); 
-                               
+
+               init();
+
        }
 
        /**
@@ -182,7 +183,7 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
                GridLayout authenticationLayout = new GridLayout();
                authenticationLayout.numColumns = 2;
                authenticationGroup.setLayout(authenticationLayout);
-               
+
                // Create database name label
                Label databaseNameLabel = new Label(authenticationGroup, SWT.NONE);
                databaseNameLabel.setText("Database Name:");
@@ -190,17 +191,17 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
                // Create database name input
                text_databaseName = new Text(authenticationGroup, SWT.BORDER);
                text_databaseName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-               
+
 
                // Create username label
                Label usernameLabel = new Label(authenticationGroup, SWT.NONE);
                usernameLabel.setText("User Name:");
-               
+
                // Create username input
                text_username = new Text(authenticationGroup, SWT.BORDER);
                text_username.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-               
-               
+
+
                // Create password label
                Label passwordLabel = new Label(authenticationGroup, SWT.NONE);
                passwordLabel.setText("Password:");
@@ -208,15 +209,15 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
                // Create password input
                text_password = new Text(authenticationGroup, SWT.BORDER | SWT.PASSWORD);
                text_password.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-               
+
        }
-       
+
        /**
         * Initialize text fields
         */
-       public void init() {            
+       public void init() {
                removeListeners();
-               if(getDataSource() != null){                                    
+               if(getDataSource() != null){
                        text_dataSourceName.setText(getDataSource().getName());
                        text_databaseName.setText(getDataSource().getDatabase());
                        text_username.setText(getDataSource().getUsername());
@@ -225,25 +226,25 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
                // add listeners after setting text to avoid the modify event being called
                // for the initial value
                addListeners();
-               
+
                // in the case of cloning we use the same datasource info
                // except for the name
                if(mode == CdmDataSourceWizard.Mode.CLONE) {
-                       getDataSource().setName("");                    
-                       text_dataSourceName.setText("");                        
+                       getDataSource().setName("");
+                       text_dataSourceName.setText("");
                } else {
                        name = text_dataSourceName.getText();
                }
-               
+
        }
-       
+
        private void addListeners() {
-               text_dataSourceName.addModifyListener(this);            
+               text_dataSourceName.addModifyListener(this);
                text_databaseName.addModifyListener(this);
                text_username.addModifyListener(this);
                text_password.addModifyListener(this);
        }
-       
+
        private void removeListeners() {
                text_dataSourceName.removeModifyListener(this);
                text_databaseName.removeModifyListener(this);
@@ -256,9 +257,9 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
        private void createNomenclaturalCodeForm() {
                nomenclaturalCodeGroup = new Group(composite , SWT.NONE);
                nomenclaturalCodeGroup.setLayout(new GridLayout());
-               
+
                nomenclaturalCode = dataSource != null ? dataSource.getNomenclaturalCode() : PreferencesUtil.getPreferredNomenclaturalCode();
-               
+
                for (final NomenclaturalCode code : NomenclaturalCodeHelper.getSupportedCodes()) {
                        Button button = new Button(nomenclaturalCodeGroup, SWT.RADIO);
                        button.setText(NomenclaturalCodeHelper.getDescription(code));
@@ -267,18 +268,19 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
                                button.setSelection(nomenclaturalCode.equals(code));
                        }
                        button.addSelectionListener(new SelectionAdapter() {
-                               public void widgetSelected(SelectionEvent e) {
+                               @Override
+                public void widgetSelected(SelectionEvent e) {
                                        nomenclaturalCode = (NomenclaturalCode) e.widget.getData();
                                        modifyText(null);
                                }
                        });
-               }               
+               }
        }
-       
+
        public void testDbConfiguration(){
                testDbConfiguration(false);
        }
-       
+
        /**
         * Tries to open a connection to the given dataSource. Generates a message on either
         * failure or success
@@ -292,35 +294,33 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
                                MessageDialog.openConfirm(parent.getShell(), "Connection Test successful", "Test successful!");
                        }
                } catch(SQLException e){
-                       MessageDialog.openWarning(parent.getShell(), "Connection Test unsuccessful", "Reason: " + e.getMessage() 
+                       MessageDialog.openWarning(parent.getShell(), "Connection Test unsuccessful", "Reason: " + e.getMessage()
                                        + System.getProperty("line.separator")    //we may use System.lineSeparator when migrated to Java 1.7
                                        + System.getProperty("line.separator")
                                        + "Please double check the connection fields");
-                       throw new RuntimeException(e);
                } catch (ClassNotFoundException e) {
-                       MessageDialog.openWarning(parent.getShell(), "Connection Test unsuccessful", "Reason: " + e.getMessage()                                        
+                       MessageDialog.openWarning(parent.getShell(), "Connection Test unsuccessful", "Reason: " + e.getMessage()
                                        + System.getProperty("line.separator")    //we may use System.lineSeparator when migrated to Java 1.7
                                        + System.getProperty("line.separator")
                                        + "Please double check the connection fields");
-                       throw new RuntimeException(e);
-               } 
+               }
        }
-       
+
        /**
         * Form implementation for the specific database
         */
-       public abstract void createDatabaseForm(); 
-       
+       public abstract void createDatabaseForm();
+
        /**
         * <p>updateLocation</p>
         */
        public abstract void updateLocation();
-       
+
        /**
         * <p>updateDataSource</p>
         */
        public abstract void updateDataSource();
-       
+
        /**
         * <p>checkPageComplete</p>
         */
@@ -328,18 +328,18 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
                boolean complete = false;
                if(mode == CdmDataSourceWizard.Mode.CREATE) {
                        complete = database.length() != 0;
-               } else {                        
+               } else {
                        complete = name.length() != 0 && database.length() != 0;
-               }       
+               }
                this.setPageComplete(complete);
        }
-       
 
-       
+
+
        /**
         * updates the current datasource with form values
         */
-       public void updateAuthentication(){                             
+       public void updateAuthentication(){
                database = text_databaseName.getText();
                username = text_username.getText();
                password = text_password.getText();
@@ -359,7 +359,7 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
         *
         * @param dataSource the dataSource to set
         */
-       public void setDataSource(ICdmDataSource dataSource) {          
+       public void setDataSource(ICdmDataSource dataSource) {
                this.dataSource = dataSource;
        }
 
@@ -372,11 +372,11 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
                updateDataSource();
                return dataSource;
        }
-       
-       protected ICdmDataSource getDataSource() {              
+
+       protected ICdmDataSource getDataSource() {
                return dataSource;
        }
-       
+
        /**
         * <p>getDataSourceName</p>
         *
@@ -385,19 +385,20 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
        public String getDataSourceName() {
                return name;
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.swto.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
         */
        /** {@inheritDoc} */
-       public void modifyText(ModifyEvent e) {
-               
+       @Override
+    public void modifyText(ModifyEvent e) {
+
                name = text_dataSourceName.getText();
                database = text_databaseName.getText();
 
                switch(mode) {
                case EDIT:
-                       if(name.length() == 0){                 
+                       if(name.length() == 0){
                                name = "";
                                setErrorMessage("DataSource name must not be empty.");
                                this.setPageComplete(false);
@@ -410,7 +411,7 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
                        }
                        break;
                case CLONE:
-                       if(name.length() == 0){                 
+                       if(name.length() == 0){
                                name = "";
                                setErrorMessage("DataSource name must not be empty.");
                                this.setPageComplete(false);
@@ -425,17 +426,17 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
                default:
                        break;
                }
-               
-               if(database.length() == 0){                                     
+
+               if(database.length() == 0){
                        setErrorMessage("Database name must not be empty.");
                        this.setPageComplete(false);
-               } else {                        
+               } else {
                        updateAndCheck();
-                       setErrorMessage(null);                  
-               }                       
-       }               
+                       setErrorMessage(null);
+               }
+       }
+
 
-       
        private void updateAndCheck() {
                updateLocation();
                updateAuthentication();