added some checks to datasource wizard
authorn.hoffmann <n.hoffmann@localhost>
Fri, 4 Sep 2009 15:25:38 +0000 (15:25 +0000)
committern.hoffmann <n.hoffmann@localhost>
Fri, 4 Sep 2009 15:25:38 +0000 (15:25 +0000)
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceTypeSelectionWizardPage.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceWizard.java

index 4d7c56297e489b4600759ac16b29d43e4835da89..2a159283197b6f8a5a693bb4d37d28a2f02a6df4 100644 (file)
@@ -29,6 +29,7 @@ import org.eclipse.swt.widgets.Text;
 
 import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
 import eu.etaxonomy.cdm.database.ICdmDataSource;
+import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
 
 /**
  * @author n.hoffmann
@@ -48,6 +49,9 @@ public class CdmDataSourceTypeSelectionWizardPage extends WizardPage implements
        private Composite editDatasourceComposite;
 
 
+       private boolean dataBaseTypeSelected = false;
+       private boolean dataSourceNameSet = false;
+       
        private ICdmDataSource dataSource;
 
        private WizardPage nextPage;
@@ -69,6 +73,8 @@ public class CdmDataSourceTypeSelectionWizardPage extends WizardPage implements
         */
        public void createControl(Composite parent) {
 
+               setPageComplete(false);
+               
                // Create top-level composite 
                composite = new Composite(parent, SWT.NONE);
                GridLayout gridLayout = new GridLayout();
@@ -106,6 +112,8 @@ public class CdmDataSourceTypeSelectionWizardPage extends WizardPage implements
                                DatabaseTypeEnum type = databaseTypes.get(databaseTypeCombo.getSelectionIndex());
                                
                                addDatabasePage(type);
+                               setDataBaseTypeSelected(true);
+                               checkPageComplete();
                        }
                });
 
@@ -172,9 +180,32 @@ public class CdmDataSourceTypeSelectionWizardPage extends WizardPage implements
         * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
         */
        public void modifyText(ModifyEvent e) {
-               dataSourceName = datasourceNameText.getText();
+               String name = datasourceNameText.getText();
+               
+               if(name.length() == 0){
+                       setDataSourceNameSet(false);
+                       setErrorMessage("DataSource name must not be empty.");
+               }else if(CdmDataSourceRepository.getDefault().getDataSource(name) != null){
+                       setDataSourceNameSet(false);
+                       setErrorMessage("DataSource with the same name already exists");
+               }else{
+                       setDataSourceNameSet(true);
+                       setErrorMessage(null);
+               }
+               dataSourceName = name;
+               checkPageComplete();
        }
 
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.wizard.WizardPage#canFlipToNextPage()
+        */
+       public void checkPageComplete() {
+               boolean complete = isDataBaseTypeSelected();
+               complete &= isDataSourceNameSet();
+               
+               setPageComplete(complete);
+       }
+       
        /**
         * @return
         */
@@ -188,6 +219,34 @@ public class CdmDataSourceTypeSelectionWizardPage extends WizardPage implements
        public CdmDataSourceCredentialsWizardPage getCredentialsWizardPage() {
                return credentialsWizardPage;
        }
+
+       /**
+        * @return the dataBaseTypeSelected
+        */
+       public boolean isDataBaseTypeSelected() {
+               return dataBaseTypeSelected;
+       }
+
+       /**
+        * @param dataBaseTypeSelected the dataBaseTypeSelected to set
+        */
+       public void setDataBaseTypeSelected(boolean dataBaseTypeSelected) {
+               this.dataBaseTypeSelected = dataBaseTypeSelected;
+       }
+
+       /**
+        * @return the dataSourceNameSet
+        */
+       public boolean isDataSourceNameSet() {
+               return dataSourceNameSet;
+       }
+
+       /**
+        * @param dataSourceNameSet the dataSourceNameSet to set
+        */
+       public void setDataSourceNameSet(boolean dataSourceNameSet) {
+               this.dataSourceNameSet = dataSourceNameSet;
+       }
        
        
 }
index 907f0be79e250179c9746b59aab465d91cc2f017..fedc5ccea954b856f838737b8889e2c496be6bff 100644 (file)
@@ -25,8 +25,10 @@ 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;
        
@@ -102,4 +104,17 @@ public class CdmDataSourceWizard extends Wizard {
                
                return true;
        }
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.wizard.Wizard#canFinish()
+        */
+       @Override
+       public boolean canFinish() {
+                boolean result = super.canFinish();
+                result &= dataSourcePageComplete;
+                result &= dataSourceSelectionPageComplete;
+                
+                
+                return result;
+       }
 }