org.netbeans.validation.api.ui
Class AbstractValidationListener<CompType extends javax.swing.JComponent,T>

java.lang.Object
  extended by javax.swing.InputVerifier
      extended by org.netbeans.validation.api.ui.ValidationListener
          extended by org.netbeans.validation.api.ui.AbstractValidationListener<CompType,T>
All Implemented Interfaces:
java.util.EventListener, Validator<T>

public abstract class AbstractValidationListener<CompType extends javax.swing.JComponent,T>
extends ValidationListener
implements Validator<T>

Convenience ValidationListener which implements Validator directly. Suitable for use when you have a single component that needs custom validation.

Author:
Tim Boudreau

Field Summary
Modifier and Type Field and Description
 
Fields inherited from class org.netbeans.validation.api.ui.ValidationListener
CLIENT_PROP_NAME
 
Constructor Summary
Constructor and Description
AbstractValidationListener(CompType comp)
          Create a new AbstractValidationListener for the single component passed here as an argument.
 
Method Summary
Modifier and Type Method and Description
protected  java.lang.String findComponentName(CompType comp)
          Get the name of the component which should be passed to validate.
protected abstract  T getModelObject(CompType comp)
          Get the model object that will be passed to validate
protected  void onValidate(CompType component, boolean validationResult)
          Called when validation runs.
protected  boolean validate(Problems problems)
          Perform the validation.
abstract  boolean validate(Problems problems, java.lang.String compName, T model)
          Validate the passed model.
 
Methods inherited from class org.netbeans.validation.api.ui.ValidationListener
nameForComponent, setComponentName, validate, verify
 
Methods inherited from class javax.swing.InputVerifier
shouldYieldFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractValidationListener

public AbstractValidationListener(CompType comp)
Create a new AbstractValidationListener for the single component passed here as an argument. If the component is not expected to live after the validator is detached, you can add this object as a listener to the component in the constructor (but remember that this means the component will reference this validator forever).

Parameters:
comp -
Method Detail

findComponentName

protected java.lang.String findComponentName(CompType comp)
Get the name of the component which should be passed to validate. The default implementation delegates to nameForComponent which will either return the client-property based name or the result of getName() on the component.

Parameters:
comp - The component
Returns:
A localized name

getModelObject

protected abstract T getModelObject(CompType comp)
Get the model object that will be passed to validate

Parameters:
comp - The component
Returns:
The model object

onValidate

protected void onValidate(CompType component,
                          boolean validationResult)
Called when validation runs. The default implementation does nothing; some validators may want to change the visual appearance of the component to indicate an error.

Parameters:
component - The component
validationResult - The result of validation

validate

protected final boolean validate(Problems problems)
Description copied from class: ValidationListener
Perform the validation. The ValidationListener instance should have access to the component and validator and simply call the validator's validate() method with the appropriate arguments.

Typically you will not call this method yourself; rather, the infrastructure will call it. Your subclass of ValidationListener should implement some listener interface. When an interesting event occurs, call super.validate() and the rest will be taken care of.

Specified by:
validate in class ValidationListener
Parameters:
problems - A set of problems which can be added to
Returns:
true if no problems were found.

validate

public abstract boolean validate(Problems problems,
                                 java.lang.String compName,
                                 T model)
Description copied from interface: Validator
Validate the passed model. If the component is invalid, this method should add problems to the passed list.

Specified by:
validate in interface Validator<T>
Parameters:
problems - A list of problems.
compName - The name of the component in question (may be null in some cases)
model - The model in question
Returns:
true if no problems were found during validation