Class ValidationItem

java.lang.Object
org.netbeans.validation.api.ui.ValidationItem
Direct Known Subclasses:
ValidationGroup, ValidationListener

public abstract class ValidationItem extends Object
Common superclass for ValidationGroup and ValidationListener, providing a common API for forcing revalidation of the managed UI component or components, see performValidation(), and for temporarily suspending validation, see runWithValidationSuspended(java.lang.Runnable)

ValidationItems can be added to a ValidationGroup using ValidationGroup.addItem(org.netbeans.validation.api.ui.ValidationItem, boolean).

Author:
Tim Boudreau, Hugo Heden
  • Method Details

    • performValidation

      public final Problem performValidation()

      A request (to the simple-validation infrastructure) for revalidation of the component(s) managed by this ValidationListener/ValidationGroup, updating the ValidationUI as necessary.

      This method can be called by client code (i.e non-subclasses), to manually request revalidation -- a "refresh". This can be useful if custom ValidationListeners are used that rely not only on the state of the managed component, but also on outside state that the listener does not know about

      More typically, this method is called by ValidationListener subclasses to let the simple-validation infrastructure know that the user has interacted with the UI-component in a way that makes revalidation needed.

      This will initiate the validation logic (unless the validation is suspended, see runWithValidationSuspended(java.lang.Runnable): A call to ValidationListener.performValidation(org.netbeans.validation.api.Problems) will occur.

      If this results in a Problem, the ValidationUI managed by this ValidationListener (such as an error icon decorating the UI-component) will be activated, indicating the Problem to the user.

      If this ValidationListener has been added to a ValidationGroup, the latter will update its ValidationUI:s as well (unless there happens to be a more severe Problem somewhere else within that ValidationGroup)

      Returns:
      The lead problem of the ValidationItem, null if there is no Problem
    • runWithValidationSuspended

      public final void runWithValidationSuspended(Runnable run)
      Disable validation and invoke a runnable. This method is useful in UIs where a change in one component can trigger changes in another component, and you do not want validation to be triggered because a component was programmatically updated.

      For example, say you have a dialog that lets you create a new Servlet source file. As the user types the servlet name, web.xml entries are updated to match, and these are also in fields in the same dialog. Since the updated web.xml entries are being programmatically (and presumably correctly) generated, those changes should not trigger a useless validation run. Wrap such generation code in a Runnable and pass it to this method when making programmatic changes to the contents of the UI.

      The runnable is run synchronously, but no changes made to components while the runnable is running will trigger validation.

      When the last runnable exits, validateAll(null) will be called to run validation against the entire newly updated UI.

      This method is reentrant - a call to updateComponents can trigger another call to updateComponents without triggering multiple calls to validateAll() on each Runnable's exit.

      Parameters:
      run - A runnable which makes changes to the contents of one or more components in the UI which should not trigger validation