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

goog.provide('org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData');

goog.require('org.apache.royale.core.IDataProviderModel');
goog.require('org.apache.royale.core.IItemRendererClassFactory');
goog.require('org.apache.royale.core.IItemRendererParent');
goog.require('org.apache.royale.core.IListPresentationModel');
goog.require('org.apache.royale.core.ISelectableItemRenderer');
goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.core.SimpleCSSStyles');
goog.require('org.apache.royale.core.UIBase');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.events.EventDispatcher');
goog.require('org.apache.royale.events.IEventDispatcher');
goog.require('org.apache.royale.events.ItemRendererEvent');
goog.require('org.apache.royale.html.beads.IListView');
goog.require('org.apache.royale.html.supportClasses.DataItemRenderer');
goog.require('org.apache.royale.jewel.beads.itemRenderers.DataFieldProviderBead');
goog.require('org.apache.royale.utils.loadBeadFromValuesManager');
goog.require('org.apache.royale.core.IBead');
goog.require('org.apache.royale.core.IDataProviderItemRendererMapper');
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.events.EventDispatcher}
 * @implements {org.apache.royale.core.IBead}
 * @implements {org.apache.royale.core.IDataProviderItemRendererMapper}
 * @param {Object=} target
 */
org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData = function(target) {
  target = typeof target !== 'undefined' ? target : null;
  org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.base(this, 'constructor', target);
};
goog.inherits(org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData, org.apache.royale.events.EventDispatcher);


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


/**
 * @protected
 * @type {org.apache.royale.core.IDataProviderModel}
 */
org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.prototype.dataProviderModel;


/**
 * @protected
 * @type {org.apache.royale.jewel.beads.itemRenderers.DataFieldProviderBead}
 */
org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.prototype.dataFieldProvider;


/**
 * @protected
 * @type {string}
 */
org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.prototype.labelField;


/**
 * @protected
 * @type {string}
 */
org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.prototype.dataField;


/**
 * @private
 * @type {org.apache.royale.core.IStrand}
 */
org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.prototype.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData__strand;


/**
 * @asprivate
 * @royaleignorecoercion org.apache.royale.core.IDataProviderModel
 * @royaleignorecoercion org.apache.royale.core.IItemRendererClassFactory
 * @royaleignorecoercion org.apache.royale.html.beads.DataFieldProviderBead
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.prototype.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData_finishSetup = function(event) {
  this.dataProviderModel = this.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData__strand.getBeadByType(org.apache.royale.core.IDataProviderModel);
  this.dataProviderModel.addEventListener("dataProviderChanged", org.apache.royale.utils.Language.closure(this.dataProviderChangeHandler, this, 'dataProviderChangeHandler'));
  this.labelField = this.dataProviderModel.labelField;
  this.dataFieldProvider = org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData__strand.getBeadByType(org.apache.royale.jewel.beads.itemRenderers.DataFieldProviderBead), org.apache.royale.jewel.beads.itemRenderers.DataFieldProviderBead);
  if (this.dataFieldProvider) {
    this.dataField = this.dataFieldProvider.dataField;
  }
  if (!this.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData__itemRendererFactory)
    this.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData__itemRendererFactory = org.apache.royale.utils.loadBeadFromValuesManager(org.apache.royale.core.IItemRendererClassFactory, "iItemRendererClassFactory", this.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData__strand);
  this.dataProviderChangeHandler(null);
};


/**
 * @private
 * @type {Object}
 */
org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.prototype.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData__itemRendererFactory;


/**
 *  The org.apache.royale.core.IItemRendererParent that will
 *  parent the item renderers.
 *  
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 *  @royaleignorecoercion Array
 *  @royaleignorecoercion org.apache.royale.core.IListView
 *  @royaleignorecoercion org.apache.royale.core.IListPresentationModel
 *  @royaleignorecoercion org.apache.royale.core.UIBase
 *  @royaleignorecoercion org.apache.royale.core.ISelectableItemRenderer
 *  @royaleignorecoercion org.apache.royale.html.supportClasses.DataItemRenderer
 *  @royaleignorecoercion org.apache.royale.events.IEventDispatcher
 * @protected
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.prototype.dataProviderChangeHandler = function(event) {
  var /** @type {Array} */ dp = this.dataProviderModel.dataProvider;
  if (!dp)
    return;
  var /** @type {org.apache.royale.html.beads.IListView} */ listView = org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData__strand.getBeadByType(org.apache.royale.html.beads.IListView), org.apache.royale.html.beads.IListView);
  var /** @type {org.apache.royale.core.IItemRendererParent} */ dataGroup = listView.dataGroup;
  dataGroup.removeAllItemRenderers();
  var /** @type {Object} */ presentationModel = this.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData__strand.getBeadByType(org.apache.royale.core.IListPresentationModel);
  var /** @type {number} */ n = dp.length;
  for (var /** @type {number} */ i = 0; i < n; i++) {
    var /** @type {Object} */ ir = this.itemRendererFactory.createItemRenderer(dataGroup);
    var /** @type {Object} */ dataItemRenderer = ir;
    dataGroup.addItemRenderer(ir, false);
    ir.index = i;
    ir.labelField = this.labelField;
    if (dataItemRenderer) {
      dataItemRenderer.dataField = this.dataField;
    }
    if (presentationModel) {
      var /** @type {org.apache.royale.core.SimpleCSSStyles} */ style = new org.apache.royale.core.SimpleCSSStyles();
      style.marginBottom = presentationModel.separatorThickness;
      ir.style = style;
      ir.height = presentationModel.rowHeight;
      ir.percentWidth = 100;
    }
    ir.data = dp[i];
    var /** @type {org.apache.royale.events.ItemRendererEvent} */ newEvent = new org.apache.royale.events.ItemRendererEvent(org.apache.royale.events.ItemRendererEvent.CREATED);
    newEvent.itemRenderer = ir;
    this.dispatchEvent(newEvent);
  }
  this.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData__strand.dispatchEvent(new org.apache.royale.events.Event("itemsCreated"));
};


org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.prototype.set__strand = function(value) {
  this.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData__strand = value;
  value.addEventListener("initComplete", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData_finishSetup, this, 'finishSetup'));
};


org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.prototype.get__itemRendererFactory = function() {
  if (!this.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData__itemRendererFactory)
    this.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData__itemRendererFactory = org.apache.royale.utils.loadBeadFromValuesManager(org.apache.royale.core.IItemRendererClassFactory, "iItemRendererClassFactory", this.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData__strand);
  return this.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData__itemRendererFactory;
};


org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.prototype.set__itemRendererFactory = function(value) {
  this.org_apache_royale_jewel_beads_itemRenderers_DataItemRendererFactoryForArrayData__itemRendererFactory = value;
};


Object.defineProperties(org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.prototype, /** @lends {org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.prototype.set__strand},
/**
  * @export
  * @type {org.apache.royale.core.IItemRendererClassFactory} */
itemRendererFactory: {
get: org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.prototype.get__itemRendererFactory,
set: org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.prototype.set__itemRendererFactory}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData.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.itemRenderers.DataItemRendererFactoryForArrayData'},
        'itemRendererFactory': { type: 'org.apache.royale.core.IItemRendererClassFactory', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData'}
      };
    },
    methods: function () {
      return {
        'DataItemRendererFactoryForArrayData': { type: '', declaredBy: 'org.apache.royale.jewel.beads.itemRenderers.DataItemRendererFactoryForArrayData', parameters: function () { return [  { index: 1, type: 'Object', optional: true } ]; }}
      };
    },
    metadata: function () { return [  ]; }
  };
};