/**
 * Generated by Apache Royale Compiler from org\apache\royale\jewel\beads\validators\CheckBoxValidator.as
 * org.apache.royale.jewel.beads.validators.CheckBoxValidator
 *
 * @fileoverview
 *
 * @suppress {checkTypes|accessControls}
 */

goog.provide('org.apache.royale.jewel.beads.validators.CheckBoxValidator');

goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.jewel.CheckBox');
goog.require('org.apache.royale.jewel.beads.validators.Validator');
goog.require('org.apache.royale.utils.Language');



/**
 *  constructor.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @constructor
 * @extends {org.apache.royale.jewel.beads.validators.Validator}
 */
org.apache.royale.jewel.beads.validators.CheckBoxValidator = function() {
  org.apache.royale.jewel.beads.validators.CheckBoxValidator.base(this, 'constructor');
};
goog.inherits(org.apache.royale.jewel.beads.validators.CheckBoxValidator, org.apache.royale.jewel.beads.validators.Validator);


/**
 * Prevent renaming of class. Needed for reflection.
 */
goog.exportSymbol('org.apache.royale.jewel.beads.validators.CheckBoxValidator', org.apache.royale.jewel.beads.validators.CheckBoxValidator);


/**
 *  Override of the base class validate() method to validate if selected.
 * 
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @export
 * @override
 */
org.apache.royale.jewel.beads.validators.CheckBoxValidator.prototype.validate = function(event) {
  event = typeof event !== 'undefined' ? event : null;
  if (org.apache.royale.jewel.beads.validators.CheckBoxValidator.superClass_.validate.apply(this, [ event] )) {
    var /** @type {number} */ selectedCount = 0;
    var /** @type {number} */ i = this.hostComponent.numElements;
    while (--i > -1) {
      var /** @type {org.apache.royale.jewel.CheckBox} */ checkBox = org.apache.royale.utils.Language.as(this.hostComponent.getElementAt(i), org.apache.royale.jewel.CheckBox);
      if (!checkBox)
        continue;
      if (checkBox.selected)
        selectedCount++;
    }
    if (selectedCount < this.required) {
      this.createErrorTip(this.requiredFieldError);
    } else {
      this.destroyErrorTip();
    }
  }
  return !this.isError;
};


org.apache.royale.jewel.beads.validators.CheckBoxValidator.prototype.set__strand = function(value) {
  org.apache.royale.jewel.beads.validators.CheckBoxValidator.superClass_.set__strand.apply(this, [ value] );
  this.hostComponent.addEventListener(org.apache.royale.events.Event.CHANGE, org.apache.royale.utils.Language.closure(this.validate, this, 'validate'), false);
};


Object.defineProperties(org.apache.royale.jewel.beads.validators.CheckBoxValidator.prototype, /** @lends {org.apache.royale.jewel.beads.validators.CheckBoxValidator.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.jewel.beads.validators.CheckBoxValidator.prototype.set__strand}}
);


/**
 * Metadata
 *
 * @type {Object.<string, Array.<Object>>}
 */
org.apache.royale.jewel.beads.validators.CheckBoxValidator.prototype.ROYALE_CLASS_INFO = { names: [{ name: 'CheckBoxValidator', qName: 'org.apache.royale.jewel.beads.validators.CheckBoxValidator', kind: 'class' }] };



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.beads.validators.CheckBoxValidator.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'strand': { type: 'org.apache.royale.core.IStrand', access: 'writeonly', declaredBy: 'org.apache.royale.jewel.beads.validators.CheckBoxValidator'}
      };
    },
    methods: function () {
      return {
        'CheckBoxValidator': { type: '', declaredBy: 'org.apache.royale.jewel.beads.validators.CheckBoxValidator'},
        'validate': { type: 'Boolean', declaredBy: 'org.apache.royale.jewel.beads.validators.CheckBoxValidator', parameters: function () { return [  { index: 1, type: 'org.apache.royale.events.Event', optional: true } ]; }}
      };
    }
  };
};