org.netbeans.validation.api.ui
Class ValidationListener

java.lang.Object
  extended by javax.swing.InputVerifier
      extended by org.netbeans.validation.api.ui.ValidationListener
All Implemented Interfaces:
java.util.EventListener
Direct Known Subclasses:
AbstractValidationListener

public abstract class ValidationListener
extends javax.swing.InputVerifier
implements java.util.EventListener

Abstract base class for listeners which listen on some component, and which are added to a ValidationGroup. Implement whatever listener interface is necessary, add it as a listener to the component(s) it should listen to, and then pass it to ValidationGroup.add().

Note that one validation listener may not belong to more than one ValidationGroup.

When an event that should trigger validation occurs, call the validate() method.

Author:
Tim Boudreau

Field Summary
static java.lang.String CLIENT_PROP_NAME
          Client property which can be set to provide a component's name for use in validation messages.
 
Constructor Summary
ValidationListener()
           
 
Method Summary
static java.lang.String nameForComponent(javax.swing.JComponent jc)
          Get a string name for a component using the following strategy: Check jc.getClientProperty(CLIENT_PROP_NAME) If that returned null, call jc.getName()
static void setComponentName(javax.swing.JComponent comp, java.lang.String localizedName)
           
protected  boolean validate()
          Perform the validation logic, triggering a call to Validate(Problems).
protected abstract  boolean validate(Problems problems)
          Perform the validation.
 boolean verify(javax.swing.JComponent input)
          Implementation of InputVerifier.
 
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
 

Field Detail

CLIENT_PROP_NAME

public static final java.lang.String CLIENT_PROP_NAME
Client property which can be set to provide a component's name for use in validation messages. If not set, the component's getName() method is used.

See Also:
Constant Field Values
Constructor Detail

ValidationListener

public ValidationListener()
Method Detail

validate

protected abstract boolean validate(Problems problems)
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.

Parameters:
problems - A set of problems which can be added to
Returns:
true if no problems were found.

validate

protected final boolean validate()
Perform the validation logic, triggering a call to Validate(Problems).

Returns:
true if a problem was found with the component this object validates (but not if a triggered call to ValidationGroup cause a problem to be set).

verify

public final boolean verify(javax.swing.JComponent input)
Implementation of InputVerifier. Simply returns validate().

Specified by:
verify in class javax.swing.InputVerifier
Parameters:
input - The component
Returns:
true if there are no problems with this component

nameForComponent

public static java.lang.String nameForComponent(javax.swing.JComponent jc)
Get a string name for a component using the following strategy:
  1. Check jc.getClientProperty(CLIENT_PROP_NAME)
  2. If that returned null, call jc.getName()

Parameters:
jc - The component
Returns:
its name, if any, or null

setComponentName

public static void setComponentName(javax.swing.JComponent comp,
                                    java.lang.String localizedName)