| 1 |
package com.jidesoft.validation; |
| 2 |
|
| 3 |
import java.util.EventListener; |
| 4 |
|
| 5 |
/** |
| 6 |
* <code>Validator</code> is an interface for validating a row in table. |
| 7 |
*/ |
| 8 |
public interface RowValidator extends EventListener { |
| 9 |
|
| 10 |
/** |
| 11 |
* Validates the value in the RowValidationObject. |
| 12 |
* <p/> |
| 13 |
* The event has the row index and the JTable which is the source. The implementation of this method should validate |
| 14 |
* if the row is valid. If the row is valid, simply return ValidationResult.OK. Otherwise, constructs a |
| 15 |
* ValidationResult and provide the id and message. You can also return RowValidationResult which has an array of |
| 16 |
* invalid column indices. Usually when you validate a row, you will be able to figure out values in one or several |
| 17 |
* columns are invalid. You can pass them to RowValidationResult and return it. Listeners for the RowValidator can |
| 18 |
* decide to display some error indications to indicate which cells are invalid. |
| 19 |
* <p/> |
| 20 |
* Although <code>ValidationResult</code> allows user to specify the fail behavior such as FAIL_BEHAVIOR_REVERT, |
| 21 |
* FAIL_BEHAVIOR_RESET or FAIL_BEHAVIOR_PERSIST, in the case of RowValidator, none of the options make sense so the |
| 22 |
* fail behavior you set will be ignored. So it is better you process the error right there in the validating |
| 23 |
* method. See the code below for an example. |
| 24 |
* <code><pre> |
| 25 |
* public ValidationResult validating(RowValidationObject vo) { |
| 26 |
* boolean valid = ...; // validate the row |
| 27 |
* if (valid) { |
| 28 |
* return null; |
| 29 |
* } |
| 30 |
* else { |
| 31 |
* PortingUtils.notifyUser(); // notify the user |
| 32 |
* table.editCellAt(vo.getRowIndex(), 5); // force editing mode in case this is the invalid cell. |
| 33 |
* return new RowValidationResult(false, new int[]{5}); |
| 34 |
* } |
| 35 |
* } </pre></code> |
| 36 |
* <p/> |
| 37 |
* Please note all the RowValidators added to a JideTable will be used for to validate any rows. |
| 38 |
* |
| 39 |
* @param vo the ValidationObject |
| 40 |
* @return ValidationResult |
| 41 |
*/ |
| 42 |
ValidationResult validating(RowValidationObject vo); |
| 43 |
} |