Revision: 1754
          http://svn.sourceforge.net/spring-rich-c/?rev=1754&view=rev
Author:   jhoskens
Date:     2007-05-22 05:51:20 -0700 (Tue, 22 May 2007)

Log Message:
-----------
Removed mixed concern: ValidationResultsReporter should not handle Guarded 
Object.
Form.xxxGuarded provided to easily add guarded objects.

Modified Paths:
--------------
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/Form.java
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/FormModelHelper.java
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/SimpleValidationResultsReporter.java
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/ValidationResultsReporter.java

Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/Form.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/Form.java
 2007-05-22 11:54:14 UTC (rev 1753)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/Form.java
 2007-05-22 12:51:20 UTC (rev 1754)
@@ -29,60 +29,76 @@
  * @author Keith Donald
  */
 public interface Form extends ControlFactory {
-    public String getId();
+       public String getId();
 
-    public ValidatingFormModel getFormModel();
+       public ValidatingFormModel getFormModel();
 
-    public Object getFormObject();
+       public Object getFormObject();
 
-    public void setFormObject(Object formObject);
+       public void setFormObject(Object formObject);
 
-    public Object getValue(String formProperty);
+       public Object getValue(String formProperty);
 
-    public ValueModel getValueModel(String formProperty);
+       public ValueModel getValueModel(String formProperty);
 
-    public void addValidationListener(ValidationListener listener);
+       public void addValidationListener(ValidationListener listener);
 
-    public void removeValidationListener(ValidationListener listener);
+       public void removeValidationListener(ValidationListener listener);
 
-    public ValidationResultsReporter newSingleLineResultsReporter(Guarded 
guarded, Messagable messageAreaPane);
-    
-    /**
-     * @return The list of ValidationResultsReporters of this Form. 
-     */
-    public List getValidationResultsReporters();
-    
-    /**
-     * Add a ValidationResultsReporter to this Form.
-     * 
-     * @param validationResultsReporter
-     */
-    public void addValidationResultsReporter(ValidationResultsReporter 
validationResultsReporter);
-    
-    /**
-     * Remove a ValidationResultsReporter from this Form.
-     * 
-     * @param validationResultsReporter
-     */
-    public void removeValidationResultsReporter(ValidationResultsReporter 
validationResultsReporter);
-    
-    /**
-     * Add a child to this Form. Models and available ResultsReporters will be 
coupled as well.
-     *  
-     * @param form The childForm to add.
-     */
-    public void addChildForm(Form form);
-    
-    /**
-     * Remove a child from this Form. Models and available ResultsReporters 
will be decoupled as well.
-     * 
-     * @param form The childForm to remove.
-     */
-    public void removeChildForm(Form form);
+       /**
+        * Create a [EMAIL PROTECTED] SimpleValidationResultsReporter} for this 
form, sending
+        * input to the given [EMAIL PROTECTED] Messagable}.
+        * 
+        * @param messageAreaPane the message receiver used by the created
+        * resultsReporter.
+        * @return a new ResultsReporter.
+        */
+       public ValidationResultsReporter 
newSingleLineResultsReporter(Messagable messageAreaPane);
 
-    public boolean hasErrors();
+       public void addGuarded(Guarded guarded);
+       
+       public void addGuarded(Guarded guarded, int mask);
+       
+       public void removeGuarded(Guarded guarded);
+       
+       /**
+        * @return The list of ValidationResultsReporters of this Form.
+        */
+       public List getValidationResultsReporters();
 
-    public void commit();
+       /**
+        * Add a ValidationResultsReporter to this Form.
+        * 
+        * @param validationResultsReporter
+        */
+       public void addValidationResultsReporter(ValidationResultsReporter 
validationResultsReporter);
 
-    public void revert();
+       /**
+        * Remove a ValidationResultsReporter from this Form.
+        * 
+        * @param validationResultsReporter
+        */
+       public void removeValidationResultsReporter(ValidationResultsReporter 
validationResultsReporter);
+
+       /**
+        * Add a child to this Form. Models and available ResultsReporters will 
be
+        * coupled as well.
+        * 
+        * @param form The childForm to add.
+        */
+       public void addChildForm(Form form);
+
+       /**
+        * Remove a child from this Form. Models and available ResultsReporters 
will
+        * be decoupled as well.
+        * 
+        * @param form The childForm to remove.
+        */
+       public void removeChildForm(Form form);
+
+       public boolean hasErrors();
+
+       public void commit();
+
+       public void revert();
 }
\ No newline at end of file

Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/FormModelHelper.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/FormModelHelper.java
      2007-05-22 11:54:14 UTC (rev 1753)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/FormModelHelper.java
      2007-05-22 12:51:20 UTC (rev 1754)
@@ -19,10 +19,8 @@
 import org.springframework.binding.form.HierarchicalFormModel;
 import org.springframework.binding.form.ValidatingFormModel;
 import org.springframework.binding.form.support.DefaultFormModel;
-import org.springframework.binding.validation.ValidationListener;
 import org.springframework.binding.validation.support.RulesValidator;
 import org.springframework.binding.value.ValueModel;
-import org.springframework.richclient.core.Guarded;
 import org.springframework.richclient.dialog.Messagable;
 import org.springframework.rules.RulesSource;
 
@@ -142,10 +140,9 @@
         return child;
     }
 
-    public static ValidationListener 
createSingleLineResultsReporter(ValidatingFormModel formModel,
-                                                                     Guarded 
guardedComponent,
+    public static ValidationResultsReporter 
createSingleLineResultsReporter(ValidatingFormModel formModel,
                                                                      
Messagable messageReceiver) {
-        return new 
SimpleValidationResultsReporter(formModel.getValidationResults(), 
guardedComponent, messageReceiver);
+        return new 
SimpleValidationResultsReporter(formModel.getValidationResults(), 
messageReceiver);
     }
 
 

Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/SimpleValidationResultsReporter.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/SimpleValidationResultsReporter.java
      2007-05-22 11:54:14 UTC (rev 1753)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/SimpleValidationResultsReporter.java
      2007-05-22 12:51:20 UTC (rev 1754)
@@ -15,215 +15,101 @@
  */
 package org.springframework.richclient.form;
 
-import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.binding.validation.ValidationMessage;
 import org.springframework.binding.validation.ValidationResults;
 import org.springframework.binding.validation.ValidationResultsModel;
-import org.springframework.richclient.core.Guarded;
 import org.springframework.richclient.core.Message;
 import org.springframework.richclient.dialog.Messagable;
 import org.springframework.util.Assert;
 
 /**
- * An implementation of ValidationResultsReporter that reports only a single 
message from
- * the configured validation results models. If there are any errors reported 
on this or
- * any child's model, then the Guarded object will be disabled and the 
associated message
- * receiver will be given the newest message posted on the results model.
+ * An implementation of ValidationResultsReporter that reports only a single
+ * message from the configured validation results models. If there are any
+ * errors reported on this or any child's model, then the Guarded object will 
be
+ * disabled and the associated message receiver will be given the newest 
message
+ * posted on the results model.
  * 
  * @author Keith Donald
  */
 public class SimpleValidationResultsReporter implements 
ValidationResultsReporter {
-    private static final Log logger = LogFactory.getLog( 
SimpleValidationResultsReporter.class );
+       private static final Log logger = 
LogFactory.getLog(SimpleValidationResultsReporter.class);
 
-    private ValidationResultsModel resultsModel;
+       private ValidationResultsModel resultsModel;
 
-    private Guarded guarded;
+       private Messagable messageReceiver;
 
-    private Messagable messageReceiver;
+       /**
+        * Constructor.
+        * @param formModel ValidatingFormModel to monitor and report on.
+        * @param messageReceiver The receiver for validation messages.
+        */
+       public SimpleValidationResultsReporter(ValidationResultsModel 
resultsModel, Messagable messageReceiver) {
+               Assert.notNull(resultsModel, "resultsModel is required");
+               Assert.notNull(messageReceiver, "messagePane is required");
+               this.resultsModel = resultsModel;
+               this.messageReceiver = messageReceiver;
+               init();
+       }
 
-    private List children = new ArrayList();
+       private void init() {
+               resultsModel.addValidationListener(this);
 
-    private ValidationResultsReporter parent = null;
-
-    /**
-     * Constructor.
-     * @param resultsModel Validation results model to monitor and report on
-     * @param guarded The Guarded object to control
-     * @param messageReceiver The receiver for validation messages
-     */
-    public SimpleValidationResultsReporter(ValidationResultsModel 
resultsModel, Guarded guarded,
-            Messagable messageReceiver) {
-        Assert.notNull( resultsModel, "resultsModel is required" );
-        Assert.notNull( guarded, "guarded is required" );
-        Assert.notNull( messageReceiver, "messagePane is required" );
-        this.resultsModel = resultsModel;
-        this.guarded = guarded;
-        this.messageReceiver = messageReceiver;
-        init();
-    }
-    
-    private void init() {
-        resultsModel.addValidationListener( this );
-
-        // Update state based on current results model
+               // Update state based on current results model
         validationResultsChanged( null );
-    }
+       }
 
-    public void clearErrors() {
-        messageReceiver.setMessage( null );
-        guarded.setEnabled( true );
-    }
+       public void clearErrors() {
+               messageReceiver.setMessage(null);
+       }
 
-    /**
-     * Handle a change in the validation results model. Update the guarded 
object and
-     * message receiver based on our current results model state.
-     */
+       /**
+        * Handle a change in the validation results model. Update the guarded
+        * object and message receiver based on our current results model state.
+        */
     public void validationResultsChanged(ValidationResults results) {
         // If our model is clean, then we need to see if any of our children 
have errors.
         // If not, then we have our parent update since we may have siblings 
that need to
-        // report there status.
+               // report there status.
 
-        if( !resultsModel.getHasErrors() ) {
-            if( logger.isDebugEnabled() ) {
-                logger.debug( "Form has no errors to report; checking 
children." );
-            }
+               if (!resultsModel.getHasErrors()) {
+                       messageReceiver.setMessage(null);
+               }
+               else {
+                       if (logger.isDebugEnabled()) {
+                               logger.debug("Form has errors; setting error 
message.");
+                       }
+                       ValidationMessage message = 
getNewestMessage(resultsModel);
+                       messageReceiver.setMessage(message == null ? null
+                                       : new Message(message.getMessage(), 
message.getSeverity()));
+               }
+       }
 
-            boolean clean = true;
-
-            // Check children
-            for( int i = 0, count = children.size(); i < count; i++ ) {
-                ValidationResultsReporter child = (ValidationResultsReporter) 
children.get( i );
-                if( child.hasErrors() ) {
-                    clean = false;
-                    child.validationResultsChanged( null ); // Force it to 
re-report
-                    break;
-                }
-            }
-
-            // If we aren't clean, then the guarded and message receiver will 
already have
-            // been updated so there's nothing more to do. If we are clean, 
then we
-            // either hand off to our parent, or if there's no parent, then we 
can finally
-            // enable the guard and clear the message.
-
-            if( clean ) {
-                // If we have a parent, then we will leave the handling of the 
guarded and
-                // message receiver to it since it may have grand-parents, etc.
-                if( parent != null ) {
-                    if( logger.isDebugEnabled() ) {
-                        logger.debug( "Form and children are clean, handing 
off to parent." );
-                    }
-                    parent.validationResultsChanged( null );
-                } else {
-                    if( logger.isDebugEnabled() ) {
-                        logger.debug( "Reporters are all clean; enabling 
guarded component." );
-                    }
-                    messageReceiver.setMessage( null );
-                    guarded.setEnabled( true );
-                }
-            }
-        } else {
-            if( logger.isDebugEnabled() ) {
-                logger.debug( "Form has errors; disabling guarded component 
and setting error message." );
-            }
-            guarded.setEnabled( false );
-            if( resultsModel.getMessageCount() > 0 ) {
-                ValidationMessage message = getNewestMessage( resultsModel );
-                messageReceiver.setMessage( new Message( message.getMessage(), 
message.getSeverity() ) );
-            } else {
-                messageReceiver.setMessage( null );
-            }
-        }
-    }
-
-    protected ValidationMessage getNewestMessage(ValidationResults results) {
-        ValidationMessage newestMessage = null;
-        for( Iterator i = results.getMessages().iterator(); i.hasNext(); ) {
-            ValidationMessage message = (ValidationMessage) i.next();
-            if( newestMessage == null || newestMessage.getTimeStamp() < 
message.getTimeStamp() ) {
-                newestMessage = message;
-            }
-        }
-        return newestMessage;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see 
org.springframework.richclient.form.ValidationResultsReporter#hasErrors()
-     */
-    public boolean hasErrors() {
-        boolean errors = resultsModel.getHasErrors();
-
-        for( int i = 0, count = children.size(); i < count && !errors; i++ ) {
-            ValidationResultsReporter child = (ValidationResultsReporter) 
children.get( i );
-            if( child.hasErrors() ) {
-                errors = true;
-                break;
-            }
-        }
-
-        return errors;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see 
org.springframework.richclient.form.ValidationResultsReporter#addChild(org.springframework.richclient.form.ValidationResultsReporter)
-     */
-    public void addChild(ValidationResultsReporter child) {
-        children.add( child );
-        child.setParent( this );
-        validationResultsChanged( null ); // Force a re-reporting
-    }
-    
-    /**
-     * @inheritDoc
-     */
-    public void removeChild(ValidationResultsReporter child)
-    {
-        children.remove(child);
-        validationResultsChanged(null);
-    }
-    
-    /**
-     * @inheritDoc
-     */
-    public void removeParent()
-    {
-        if (getParent() != null)
-        {
-            getParent().removeChild(this);
-            setParent(null);
-        }
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public ValidationResultsReporter createChild(ValidationResultsModel 
validationResultsModel)
-    {
-        SimpleValidationResultsReporter simpleValidationResultsReporter = new 
SimpleValidationResultsReporter(validationResultsModel, this.guarded, 
this.messageReceiver);
-        addChild(simpleValidationResultsReporter);
-        return simpleValidationResultsReporter;
-    }
-    
-    /*
-     * (non-Javadoc)
-     * @see 
org.springframework.richclient.form.ValidationResultsReporter#getParent()
-     */
-    public ValidationResultsReporter getParent() {
-        return parent;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see 
org.springframework.richclient.form.ValidationResultsReporter#setParent(org.springframework.richclient.form.ValidationResultsReporter)
-     */
-    public void setParent(ValidationResultsReporter parent) {
-        this.parent = parent;
-    }
-
+       /**
+        * Search the newest message in the given resultsModel.
+        * 
+        * @param resultsModel Search this model to find the newest message.
+        * @return the newest message in this resultsModel.
+        */
+       protected ValidationMessage getNewestMessage(ValidationResults 
resultsModel) {
+               ValidationMessage newestMessage = null;
+               for (Iterator i = resultsModel.getMessages().iterator(); 
i.hasNext();) {
+                       ValidationMessage message = (ValidationMessage) 
i.next();
+                       if (newestMessage == null || 
newestMessage.getTimeStamp() < message.getTimeStamp()) {
+                               newestMessage = message;
+                       }
+               }
+               return newestMessage;
+       }
+       
+       /*
+        * (non-Javadoc)
+        * @see 
org.springframework.richclient.form.ValidationResultsReporter#hasErrors()
+        */
+       public boolean hasErrors() {
+               return resultsModel.getHasErrors();
+       }
 }

Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/ValidationResultsReporter.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/ValidationResultsReporter.java
    2007-05-22 11:54:14 UTC (rev 1753)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/ValidationResultsReporter.java
    2007-05-22 12:51:20 UTC (rev 1754)
@@ -16,8 +16,8 @@
 package org.springframework.richclient.form;
 
 import org.springframework.binding.validation.ValidationListener;
-import org.springframework.binding.validation.ValidationResultsModel;
 
+
 public interface ValidationResultsReporter extends ValidationListener {
 
     /**
@@ -26,48 +26,4 @@
      */
     public boolean hasErrors();
 
-    /**
-     * Add a child validation results reporter. The error status of the child 
will feed
-     * into the determination of the error status for this reporter. If the 
child has
-     * errors, then this object's <code>hasErrors</code> will return true. If 
the child
-     * has no errors, then return value of this object's 
<code>hasErrors</code> will
-     * depend on it's direct validation results model and the 
<code>hasErrors</code>
-     * status of any other child reporter.
-     * 
-     * @param child to add
-     */
-    public void addChild(ValidationResultsReporter child);
-    
-    /**
-     * Remove the childReporter from the children list.
-     * 
-     * @param child
-     */
-    public void removeChild(ValidationResultsReporter child);
-    
-    /**
-     * Remove this reporter's parent.
-     */
-    public void removeParent();
-
-    /**
-     * Create a child based upon this Reporter.
-     * 
-     * @param validationResultsModel The specific ResultsModel for the new 
reporter.
-     * @return A new Reporter that reacts on the given ValidationResultsModel 
and is a child of this reporter.
-     */
-    public ValidationResultsReporter createChild(ValidationResultsModel 
validationResultsModel);
-
-    /**
-     * Get the parent results reporter. If this reporter has not been added as 
a child to
-     * some other reporter, then this will return null.
-     * @return parent reporter or null
-     */
-    public ValidationResultsReporter getParent();
-
-    /**
-     * Set the parent reporter.
-     * @param parent New parent reporter
-     */
-    public void setParent(ValidationResultsReporter parent);
 }
\ No newline at end of file


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
spring-rich-c-cvs mailing list
spring-rich-c-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs

Reply via email to