datasource wizard was still buggy
authorn.hoffmann <n.hoffmann@localhost>
Tue, 8 Sep 2009 12:59:23 +0000 (12:59 +0000)
committern.hoffmann <n.hoffmann@localhost>
Tue, 8 Sep 2009 12:59:23 +0000 (12:59 +0000)
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceCredentialsWizardPage.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceH2WizardPage.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceMySQLWizardPage.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceSQLServerWizardPage.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceWizard.java

index e6f9f95cc013b3f500e2e43569ce6a296fcc1e38..8513a4add9922944e485d3d9b3b825bc1d67b361 100644 (file)
@@ -59,6 +59,7 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
         */
        protected CdmDataSourceCredentialsWizardPage(String pageName) {
                super(pageName);
+               this.setPageComplete(false);
        }
        
        /* (non-Javadoc)
@@ -168,6 +169,13 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
        
        public abstract void updateDataSource();
        
+       public void checkPageComplete(){
+               boolean complete = database.length() != 0;
+               complete &= username.length() != 0;
+               
+               this.setPageComplete(complete);
+       }
+       
        /**
         * Initialize text fields 
         */
@@ -228,6 +236,7 @@ public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage impl
                updateLocation();
                updateAuthentication();
                updateDataSource();
+               checkPageComplete();
        }       
        
        /**
index f18eb3e90d6d307ec22d2b6c5ef576410328ba31..d20e704d182db4fb40d9231031326f8f77b17bb5 100644 (file)
@@ -54,4 +54,12 @@ public class CdmDataSourceH2WizardPage extends CdmDataSourceCredentialsWizardPag
                                                                                                                 username, 
                                                                                                                 password));
        }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#checkPageComplete()
+        */
+       @Override
+       public void checkPageComplete() {
+               super.checkPageComplete();
+       }
 }
index e5cc029ba6aa0cfd2eb9a74438132886f1706a68..76c22f136ec2e4ecbd883d1c8333d9f6a6a1de4b 100644 (file)
@@ -19,6 +19,7 @@ import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 
 import eu.etaxonomy.cdm.database.CdmDataSource;
+import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
 import eu.etaxonomy.cdm.database.ICdmDataSource;
 
 /**
@@ -91,11 +92,13 @@ public class CdmDataSourceMySQLWizardPage extends CdmDataSourceCredentialsWizard
        public void updateLocation() {
                server = text_server.getText();
                try{
-                       port = new Integer(text_port.getText());
+                       if(! text_port.getText().equals("")){
+                               port = new Integer(text_port.getText());
+                               setErrorMessage(null);
+                       }
                }catch(NumberFormatException e){
-                       // pass
+                       setErrorMessage("Port number contains invalid characters");
                }
-
        }
 
        /* (non-Javadoc)
@@ -110,6 +113,25 @@ public class CdmDataSourceMySQLWizardPage extends CdmDataSourceCredentialsWizard
                                                                                                                                        password));
        }
        
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#checkPageComplete()
+        */
+       @Override
+       public void checkPageComplete() {
+               // check if widgets of this component are complete
+               boolean complete = server.trim().length() != 0;
+               
+               // set default port
+               if(port == 0){
+                       port = DatabaseTypeEnum.MySQL.getDefaultPort();
+               }
+               
+               setPageComplete(complete);
+               
+               // check if widgets of the extended class are complete
+               super.checkPageComplete();
+       }
+       
        /* (non-Javadoc)
         * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#init()
         */
index 5c68d20b5f61b5eee358987636eecfe86512071c..f6921178106e7dcff358065240d45e08479b35bd 100644 (file)
@@ -19,6 +19,7 @@ import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 
 import eu.etaxonomy.cdm.database.CdmDataSource;
+import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
 import eu.etaxonomy.cdm.database.ICdmDataSource;
 
 /**
@@ -91,9 +92,12 @@ public class CdmDataSourceSQLServerWizardPage extends CdmDataSourceCredentialsWi
        public void updateLocation() {
                server = text_server.getText();
                try{
-                       port = new Integer(text_port.getText());
+                       if(! text_port.getText().equals("")){
+                               port = new Integer(text_port.getText());
+                               setErrorMessage(null);
+                       }
                }catch(NumberFormatException e){
-//                     logger.warn("Error parsing port number", e);
+                       setErrorMessage("Port number contains invalid characters");
                }
        }
 
@@ -108,6 +112,25 @@ public class CdmDataSourceSQLServerWizardPage extends CdmDataSourceCredentialsWi
                                                                                                                        username,
                                                                                                                        password));
        }
+       
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#checkPageComplete()
+        */
+       @Override
+       public void checkPageComplete() {
+               // check if widgets of this component are complete
+               boolean complete = server.trim().length() != 0;
+               
+               // set default port
+               if(port == 0){
+                       port = DatabaseTypeEnum.MySQL.getDefaultPort();
+               }
+               
+               setPageComplete(complete);
+               
+               // check if widgets of the extended class are complete
+               super.checkPageComplete();
+       }
 
        /* (non-Javadoc)
         * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#init()
index fedc5ccea954b856f838737b8889e2c496be6bff..ccea5a76e24ebd110d6e90d8bc35ec814c3f6ec6 100644 (file)
@@ -25,20 +25,21 @@ import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
 public class CdmDataSourceWizard extends Wizard {
        
        private CdmDataSourceCredentialsWizardPage dataSourcePage;
-       private boolean dataSourcePageComplete = false;
 
        private CdmDataSourceTypeSelectionWizardPage dataSourceSelectionPage;
-       private boolean dataSourceSelectionPageComplete = false;
        
        private CdmPersistentDataSource dataSource;
        
        private String dataSourceName;
        
+       private boolean editMode;
+       
        /**
         * @param b
         */
        public CdmDataSourceWizard() {
                super();
+               editMode = false;
                setForcePreviousAndNextButtons(true);
                setWindowTitle("Datasource Dialog");
        }
@@ -48,10 +49,13 @@ public class CdmDataSourceWizard extends Wizard {
         */
        public CdmDataSourceWizard(CdmPersistentDataSource dataSource) {
                super();
+               if(dataSource != null){
+                       editMode = true;
+                       this.dataSource = dataSource;
+                       dataSourceName = dataSource.getName();
+               }
                setForcePreviousAndNextButtons(true);
                setWindowTitle("Datasource Dialog");
-               this.dataSource = dataSource;
-               dataSourceName = dataSource.getName();
        }
 
 
@@ -61,10 +65,7 @@ public class CdmDataSourceWizard extends Wizard {
        @Override
        public void addPages() {
 
-               if(dataSource == null){
-                       dataSourceSelectionPage = new CdmDataSourceTypeSelectionWizardPage(dataSource); 
-                       this.addPage(dataSourceSelectionPage);
-               }else{
+               if(editMode){
                        if(dataSource.getDatabaseType() == DatabaseTypeEnum.H2){
                                dataSourcePage = new CdmDataSourceH2WizardPage(dataSource);
                        }else if(dataSource.getDatabaseType() == DatabaseTypeEnum.MySQL){
@@ -73,6 +74,9 @@ public class CdmDataSourceWizard extends Wizard {
                                dataSourcePage = new CdmDataSourceSQLServerWizardPage(dataSource);
                        }
                        this.addPage(dataSourcePage);
+               }else{
+                       dataSourceSelectionPage = new CdmDataSourceTypeSelectionWizardPage(dataSource); 
+                       this.addPage(dataSourceSelectionPage);
                }
        }
 
@@ -82,27 +86,20 @@ public class CdmDataSourceWizard extends Wizard {
        @Override
        public boolean performFinish() {
                                
-               // TODO this is a little bit confusing because we do edit and create in the same wizard.
-               // maybe we want to refactor it into separate wizards
-               if(dataSourceSelectionPage != null){
-                       // a new datasource was created
+               if(editMode){
+                       ICdmDataSource dataSource = dataSourcePage.getDataSource();
+                       CdmDataSourceRepository.getDefault().update(dataSourceName, dataSource);
+                       
+                       return true;
+               }else{
                        if(dataSourceSelectionPage.getCredentialsWizardPage() != null){
                                CdmDataSourceCredentialsWizardPage credentialsWizardPage = dataSourceSelectionPage.getCredentialsWizardPage();
                                CdmDataSourceRepository.getDefault().save(dataSourceSelectionPage.getDataSourceName(), credentialsWizardPage.getDataSource());
+                               return true;
                        }else{
                                throw new IllegalStateException("Expected a datasource credentials page to exist");
                        }
-               }else if(dataSourcePage != null){
-                       // existing datasource was edited
-                       ICdmDataSource dataSource = dataSourcePage.getDataSource();
-                       CdmDataSourceRepository.getDefault().update(dataSourceName, dataSource);
-               }else{
-                       throw new IllegalStateException("Other pages expected");
                }
-                                       
-               
-               
-               return true;
        }
        
        /* (non-Javadoc)
@@ -110,11 +107,15 @@ public class CdmDataSourceWizard extends Wizard {
         */
        @Override
        public boolean canFinish() {
-                boolean result = super.canFinish();
-                result &= dataSourcePageComplete;
-                result &= dataSourceSelectionPageComplete;
-                
-                
-                return result;
+               if(editMode){
+                       return dataSourcePage.isPageComplete();
+               }else{
+                       boolean result = true;
+                       result &= dataSourceSelectionPage.isPageComplete();
+                       if(dataSourceSelectionPage.getCredentialsWizardPage() != null){
+                               result &= dataSourceSelectionPage.getCredentialsWizardPage().isPageComplete();
+                       }
+                       return result;
+               }
        }
 }