Menu

Commit [r812]  Maximize  Restore  History

Completed validation

hotzst 2008-11-15

changed /plugin/src/ch/sahits/codegen/java/internal/wizards/MJCGWizardPage.java
changed /plugin/src/ch/sahits/codegen/java/internal/wizards/MJCPWizard.java
/plugin/src/ch/sahits/codegen/java/internal/wizards/MJCGWizardPage.java Diff Switch to side-by-side view
--- a/plugin/src/ch/sahits/codegen/java/internal/wizards/MJCGWizardPage.java
+++ b/plugin/src/ch/sahits/codegen/java/internal/wizards/MJCGWizardPage.java
@@ -92,7 +92,7 @@
 		createAddButtons(container);
 		initDBRadioButtons();
 		initDBProduct();
-		dialogChanged();
+		validator.validate();
 		setControl(container);
 	}
 	
@@ -243,13 +243,6 @@
 	}
 
 	/**
-	 * Ensures that both text fields are set.
-	 */
-	private void dialogChanged() {
-		// FIXME: do the validation throug a validator
-		updateStatus(null,true);
-	}
-	/**
 	 * Update the site Status
 	 * @param message Status message
 	 * @param error true if it is an error that prohibits page completion
@@ -263,29 +256,47 @@
 	}
 	
 
-
+	/**
+	 * Handle the event of database product selection
+	 * TODO: is not correctly validated if the wrong product is set and then the correct one is set
+	 */
 	@Override
 	protected void handleDBProductSelection() {
-		// TODO Auto-generated method stub
-		
+		String selectedDBProduct=comboProduct.getText();
+		setDBProduct(selectedDBProduct);
+		validator.validate();
 	}
 
 	@Override
 	protected void handleOnClickWithDBConnection(boolean selected) {
-		// TODO Auto-generated method stub
-		
+    	if (selected){
+    		// TODO set EDBGenerationCode.WITH_DB_CONNECTION
+    		initDBProduct();
+    	}
+		validator.validate();
 	}
 
 	@Override
 	protected void handleOnClickWithInputFile(boolean selected) {
-		// TODO Auto-generated method stub
-		
+    	if (selected){
+    		// TODO set EDBGenerationCode.WITH_DB_INPUT_FILE
+    		initDBProduct();
+    	}
+		validator.validate();
 	}
 
 	@Override
 	protected void handleOnClickWithoutDB(boolean selected) {
-		// TODO Auto-generated method stub
-		
+    	if (selected){
+    		// disable the db product field
+    		comboProduct.setEnabled(false);
+    		// TODO: set EDBGenerationCode.WITHOUT_DB
+     		initDBProduct();
+    	} else {
+    		// enable the db product field
+    		comboProduct.setEnabled(true);
+    	}
+		validator.validate();
 	}
 	/**
 	 * Validate if the given class works with the already defined data
@@ -369,6 +380,7 @@
 	}
 
 	
+
 	// Inner class Validator
 	class Validator implements IJavaGenerationDefinition {
 
@@ -383,11 +395,108 @@
 			// TODO Auto-generated method stub
 			
 		}
-
+		/**
+		 * Check if the selected options are valid with the registered classes in the table
+		 */
 		@Override
 		public void validate() {
-			// TODO Auto-generated method stub
-			
+			EDBGenerationCode genType = getSourceInputType();
+			if (!checkGenType(genType)){
+				updateStatus("All classes must be generated through the same database access method: "+genType);
+				return;
+			}
+			switch (genType){
+			case WITH_DB_CONNECTION:
+				if (isDbProductSet()){
+					if (!checkDBProduct(getDBProduct())){
+						return;
+					}
+				} else {
+					updateStatus("Database product is not defined");
+					return;
+				}
+				break;
+			case WITH_DB_INPUT_FILE:
+				if (isDbProductSet()){
+					if (!checkDBProduct(getDBProduct())){
+						return;
+					}
+				} else {
+					updateStatus("Database product is not defined");
+					return;
+				}
+				if (!checkInputFile()){
+					return;
+				}
+				break;
+			case WITHOUT_DB:
+				if (!checkInputFile()){
+					return;
+				}
+				break;
+			}
+			setFinished(true);
+		}
+		/**
+		 * Check whether all defined classes have the same input file set<br>
+		 * If an inconsistency is detected the error message is set.
+		 * @return true if all is well
+		 */
+		private boolean checkInputFile() {
+			String inputFile = getInputFilePath();
+			for (Iterator<GeneratedClassDelegateGenerator> iterator=tableElements.iterator();iterator.hasNext();){
+				GeneratedClassDelegateGenerator m = (GeneratedClassDelegateGenerator)iterator.next();
+				// check
+				if (!m.getInputFilePath().equals(inputFile)){
+					updateStatus("The input file of the class "+m.getClassName()+" is "+m.getInputFilePath()+". It should be: "+inputFile);
+					return false;
+				}
+			}
+			return true;
+		}
+
+		/**
+		 * Check whether all defined classes have the same database product set<br>
+		 * If an inconsistency is detected the error message is set.
+		 * @param product product vendor
+		 * @return true if all is well
+		 */
+		private boolean checkDBProduct(String product) {
+			for (Iterator<GeneratedClassDelegateGenerator> iterator=tableElements.iterator();iterator.hasNext();){
+				GeneratedClassDelegateGenerator m = (GeneratedClassDelegateGenerator)iterator.next();
+				// check
+				if (!m.getDbProduct().equals(product)){
+					updateStatus("The database product of the class "+m.getClassName()+" is "+m.getDbProduct()+". It should be: "+product);
+					return false;
+				}
+			}
+			return true;
+		}
+
+		/**
+		 * Check whether all defined classes have the same generation type<br>
+		 * If an inconsistency is detected the error message is set.
+		 * @param genType EDBGenerationCode to compare to
+		 * @return true if all classes are generated through the same data source
+		 */
+		private boolean checkGenType(EDBGenerationCode genType) {
+			for (Iterator<GeneratedClassDelegateGenerator> iterator=tableElements.iterator();iterator.hasNext();){
+				GeneratedClassDelegateGenerator m = (GeneratedClassDelegateGenerator)iterator.next();
+				// check
+				if (!EDBGenerationCode.valueOf(m.getGenerationBase()).equals(genType)){
+					updateStatus("The Generation Code of the class "+m.getClassName()+" is "+m.getGenerationBase()+". It should be "+genType);
+					return false;
+				}
+			}
+			return true;
+		}
+
+		/**
+		 * Check whether the dbProduct is set
+		 * @return true if the database product is set
+		 */
+		private boolean isDbProductSet() {
+			return getDBProduct()!=null && !getDBProduct().trim().equals("");
 		}
 		
 	}
/plugin/src/ch/sahits/codegen/java/internal/wizards/MJCPWizard.java Diff Switch to side-by-side view
--- a/plugin/src/ch/sahits/codegen/java/internal/wizards/MJCPWizard.java
+++ b/plugin/src/ch/sahits/codegen/java/internal/wizards/MJCPWizard.java
@@ -63,7 +63,10 @@
 		return true;
 	}
 
-
+	/**
+	 * Unserialize the contents of an XML defined class and update the models and ui.
+	 * TODO: not all elements (UI) are updated: database product, check selection
+	 */
 	@Override
 	public void unserialize(String fileName) {
 		  XMLSerializer parser;
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.