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

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

goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.jewel.RadioButton');
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.RadioButtonValidator = function() {
  org.apache.royale.jewel.beads.validators.RadioButtonValidator.base(this, 'constructor');
};
goog.inherits(org.apache.royale.jewel.beads.validators.RadioButtonValidator, org.apache.royale.jewel.beads.validators.Validator);


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


/**
 * @private
 * @type {string}
 */
org.apache.royale.jewel.beads.validators.RadioButtonValidator.prototype.org_apache_royale_jewel_beads_validators_RadioButtonValidator__groupName;


/**
 *  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.RadioButtonValidator.prototype.validate = function(event) {
  event = typeof event !== 'undefined' ? event : null;
  if (org.apache.royale.jewel.beads.validators.RadioButtonValidator.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.RadioButton} */ rb = org.apache.royale.utils.Language.as(this.hostComponent.getElementAt(i), org.apache.royale.jewel.RadioButton);
      if (!rb)
        continue;
      if (this.groupName && rb.groupName != this.groupName)
        continue;
      if (rb.selected) {
        selectedCount++;
        break;
      }
    }
    if (selectedCount < 1) {
      this.createErrorTip(this.requiredFieldError);
    } else {
      this.destroyErrorTip();
    }
  }
  return !this.isError;
};


org.apache.royale.jewel.beads.validators.RadioButtonValidator.prototype.set__strand = function(value) {
  org.apache.royale.jewel.beads.validators.RadioButtonValidator.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);
};


org.apache.royale.jewel.beads.validators.RadioButtonValidator.prototype.get__groupName = function() {
  return this.org_apache_royale_jewel_beads_validators_RadioButtonValidator__groupName;
};


org.apache.royale.jewel.beads.validators.RadioButtonValidator.prototype.set__groupName = function(value) {
  this.org_apache_royale_jewel_beads_validators_RadioButtonValidator__groupName = value;
};


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


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.beads.validators.RadioButtonValidator.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.RadioButtonValidator'},
        'groupName': { type: 'String', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.beads.validators.RadioButtonValidator'}
      };
    },
    methods: function () {
      return {
        'RadioButtonValidator': { type: '', declaredBy: 'org.apache.royale.jewel.beads.validators.RadioButtonValidator'},
        'validate': { type: 'Boolean', declaredBy: 'org.apache.royale.jewel.beads.validators.RadioButtonValidator', parameters: function () { return [  { index: 1, type: 'org.apache.royale.events.Event', optional: true } ]; }}
      };
    }
  };
};