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

goog.provide('org.apache.royale.html.beads.DataItemRendererFactoryForArrayList');

goog.require('org.apache.royale.collections.IArrayList');
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.IStrandWithModelView');
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.DataFieldProviderBead');
goog.require('org.apache.royale.html.beads.IListView');
goog.require('org.apache.royale.html.supportClasses.DataItemRenderer');
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.0
 * @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.html.beads.DataItemRendererFactoryForArrayList = function(target) {
  target = typeof target !== 'undefined' ? target : null;
  org.apache.royale.html.beads.DataItemRendererFactoryForArrayList.base(this, 'constructor', target);
};
goog.inherits(org.apache.royale.html.beads.DataItemRendererFactoryForArrayList, org.apache.royale.events.EventDispatcher);


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


/**
 * @protected
 * @type {org.apache.royale.core.IDataProviderModel}
 */
org.apache.royale.html.beads.DataItemRendererFactoryForArrayList.prototype.dataProviderModel;


/**
 * @protected
 * @type {org.apache.royale.html.beads.DataFieldProviderBead}
 */
org.apache.royale.html.beads.DataItemRendererFactoryForArrayList.prototype.dataFieldProvider;


/**
 * @protected
 * @type {string}
 */
org.apache.royale.html.beads.DataItemRendererFactoryForArrayList.prototype.labelField;


/**
 * @protected
 * @type {string}
 */
org.apache.royale.html.beads.DataItemRendererFactoryForArrayList.prototype.dataField;


/**
 * @protected
 * @type {org.apache.royale.core.IStrand}
 */
org.apache.royale.html.beads.DataItemRendererFactoryForArrayList.prototype._strand;


/**
 * @protected
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.html.beads.DataItemRendererFactoryForArrayList.prototype.initComplete = function(event) {
  this.dataProviderModel = org.apache.royale.utils.Language.as(this._strand.getBeadByType(org.apache.royale.core.IDataProviderModel), 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._strand.getBeadByType(org.apache.royale.html.beads.DataFieldProviderBead), org.apache.royale.html.beads.DataFieldProviderBead);
  if (this.dataFieldProvider) {
    this.dataField = this.dataFieldProvider.dataField;
  }
  if (!this.org_apache_royale_html_beads_DataItemRendererFactoryForArrayList__itemRendererFactory)
    this.org_apache_royale_html_beads_DataItemRendererFactoryForArrayList__itemRendererFactory = org.apache.royale.utils.Language.as(org.apache.royale.utils.loadBeadFromValuesManager(org.apache.royale.core.IItemRendererClassFactory, "iItemRendererClassFactory", this._strand), org.apache.royale.core.IItemRendererClassFactory);
  this.dataProviderChangeHandler(null);
};


/**
 * @private
 * @type {org.apache.royale.core.IItemRendererClassFactory}
 */
org.apache.royale.html.beads.DataItemRendererFactoryForArrayList.prototype.org_apache_royale_html_beads_DataItemRendererFactoryForArrayList__itemRendererFactory;


/**
 * @asprivate
 * @protected
 * @param {org.apache.royale.core.ISelectableItemRenderer} ir
 * @param {Object} data
 * @param {number} index
 */
org.apache.royale.html.beads.DataItemRendererFactoryForArrayList.prototype.setData = function(ir, data, index) {
  ir.data = data;
  ir.index = index;
};


/**
 *  @asprivate
 *  @royaleignorecoercion org.apache.royale.core.IStrandWithModelView
 *  @royaleignorecoercion org.apache.royale.html.beads.IListView
 * @protected
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.html.beads.DataItemRendererFactoryForArrayList.prototype.dataProviderChangeHandler = function(event) {
  var /** @type {org.apache.royale.collections.IArrayList} */ dp = org.apache.royale.utils.Language.as(this.dataProviderModel.dataProvider, org.apache.royale.collections.IArrayList);
  if (!dp)
    return;
  var /** @type {Object} */ view = this._strand.view;
  var /** @type {org.apache.royale.core.IItemRendererParent} */ dataGroup = view.dataGroup;
  dataGroup.removeAllItemRenderers();
  var /** @type {org.apache.royale.core.IListPresentationModel} */ presentationModel = org.apache.royale.utils.Language.as(this._strand.getBeadByType(org.apache.royale.core.IListPresentationModel), org.apache.royale.core.IListPresentationModel);
  var /** @type {number} */ n = dp.length;
  for (var /** @type {number} */ i = 0; i < n; i++) {
    var /** @type {org.apache.royale.core.ISelectableItemRenderer} */ ir = org.apache.royale.utils.Language.as(this.itemRendererFactory.createItemRenderer(dataGroup), org.apache.royale.core.ISelectableItemRenderer);
    var /** @type {org.apache.royale.html.supportClasses.DataItemRenderer} */ dataItemRenderer = org.apache.royale.utils.Language.as(ir, org.apache.royale.html.supportClasses.DataItemRenderer);
    dataGroup.addItemRenderer(ir, false);
    if (presentationModel) {
      var /** @type {org.apache.royale.core.SimpleCSSStyles} */ style = new org.apache.royale.core.SimpleCSSStyles();
      style.marginBottom = presentationModel.separatorThickness;
      org.apache.royale.utils.Language.as(ir, org.apache.royale.core.UIBase, true).style = style;
      org.apache.royale.utils.Language.as(ir, org.apache.royale.core.UIBase, true).height = presentationModel.rowHeight;
      org.apache.royale.utils.Language.as(ir, org.apache.royale.core.UIBase, true).percentWidth = 100;
    }
    ir.labelField = this.labelField;
    if (dataItemRenderer) {
      dataItemRenderer.dataField = this.dataField;
    }
    this.setData(ir, dp.getItemAt(i), 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);
  }
  org.apache.royale.utils.Language.as(this._strand, org.apache.royale.events.IEventDispatcher, true).dispatchEvent(new org.apache.royale.events.Event("itemsCreated"));
};


org.apache.royale.html.beads.DataItemRendererFactoryForArrayList.prototype.set__strand = function(value) {
  this._strand = value;
  org.apache.royale.utils.Language.as(this._strand, org.apache.royale.events.IEventDispatcher, true).addEventListener("initComplete", org.apache.royale.utils.Language.closure(this.initComplete, this, 'initComplete'));
};


org.apache.royale.html.beads.DataItemRendererFactoryForArrayList.prototype.get__itemRendererFactory = function() {
  if (!this.org_apache_royale_html_beads_DataItemRendererFactoryForArrayList__itemRendererFactory)
    this.org_apache_royale_html_beads_DataItemRendererFactoryForArrayList__itemRendererFactory = org.apache.royale.utils.Language.as(org.apache.royale.utils.loadBeadFromValuesManager(org.apache.royale.core.IItemRendererClassFactory, "iItemRendererClassFactory", this._strand), org.apache.royale.core.IItemRendererClassFactory);
  return this.org_apache_royale_html_beads_DataItemRendererFactoryForArrayList__itemRendererFactory;
};


org.apache.royale.html.beads.DataItemRendererFactoryForArrayList.prototype.set__itemRendererFactory = function(value) {
  this.org_apache_royale_html_beads_DataItemRendererFactoryForArrayList__itemRendererFactory = value;
};


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


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



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