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

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

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.IDataProviderVirtualItemRendererMapper');
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.IDataProviderVirtualItemRendererMapper}
 * @param {Object=} target
 */
org.apache.royale.html.beads.VirtualDataItemRendererFactoryForArrayData = function(target) {
  target = typeof target !== 'undefined' ? target : null;
  
  this.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData_rendererMap = {};
  org.apache.royale.html.beads.VirtualDataItemRendererFactoryForArrayData.base(this, 'constructor', target);
};
goog.inherits(org.apache.royale.html.beads.VirtualDataItemRendererFactoryForArrayData, org.apache.royale.events.EventDispatcher);


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


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


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


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


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


/**
 * @private
 * @type {org.apache.royale.core.IStrand}
 */
org.apache.royale.html.beads.VirtualDataItemRendererFactoryForArrayData.prototype.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData__strand;


/**
 * @asprivate
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.html.beads.VirtualDataItemRendererFactoryForArrayData.prototype.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData_finishSetup = function(event) {
  this.dataProviderModel = org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData__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.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData__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_VirtualDataItemRendererFactoryForArrayData__itemRendererFactory)
    this.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData__itemRendererFactory = org.apache.royale.utils.Language.as(org.apache.royale.utils.loadBeadFromValuesManager(org.apache.royale.core.IItemRendererClassFactory, "iItemRendererClassFactory", this.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData__strand), org.apache.royale.core.IItemRendererClassFactory);
  this.dataProviderChangeHandler(null);
};


/**
 * @private
 * @type {org.apache.royale.core.IItemRendererClassFactory}
 */
org.apache.royale.html.beads.VirtualDataItemRendererFactoryForArrayData.prototype.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData__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.0
 *  @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.VirtualDataItemRendererFactoryForArrayData.prototype.dataProviderChangeHandler = function(event) {
  var /** @type {Array} */ dp = org.apache.royale.utils.Language.as(this.dataProviderModel.dataProvider, Array);
  if (!dp)
    return;
  var /** @type {Object} */ view = this.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData__strand.view;
  var /** @type {org.apache.royale.core.IItemRendererParent} */ dataGroup = view.dataGroup;
  dataGroup.removeAllItemRenderers();
};


/**
 *  Free an item renderer for a given index.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.0
 *  @royaleignorecoercion org.apache.royale.core.IStrandWithModelView
 *  @royaleignorecoercion org.apache.royale.html.beads.IListView
 * @export
 * @param {number} index
 */
org.apache.royale.html.beads.VirtualDataItemRendererFactoryForArrayData.prototype.freeItemRendererForIndex = function(index) {
  var /** @type {org.apache.royale.core.ISelectableItemRenderer} */ ir = this.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData_rendererMap[index];
  var /** @type {Object} */ view = this.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData__strand.view;
  var /** @type {org.apache.royale.core.IItemRendererParent} */ dataGroup = view.dataGroup;
  dataGroup.removeItemRenderer(ir);
  delete this.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData_rendererMap[index];
};


/**
 * @private
 * @type {Object}
 */
org.apache.royale.html.beads.VirtualDataItemRendererFactoryForArrayData.prototype.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData_rendererMap;


/**
 *  Get an item renderer for a given index.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.0
 *  @royaleignorecoercion org.apache.royale.core.IStrandWithModelView
 *  @royaleignorecoercion org.apache.royale.html.beads.IListView
 * @export
 * @param {number} index
 * @param {number} elementIndex
 * @return {org.apache.royale.core.ISelectableItemRenderer}
 */
org.apache.royale.html.beads.VirtualDataItemRendererFactoryForArrayData.prototype.getItemRendererForIndex = function(index, elementIndex) {
  var /** @type {org.apache.royale.core.ISelectableItemRenderer} */ ir = this.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData_rendererMap[index];
  if (ir)
    return ir;
  var /** @type {Array} */ dp = org.apache.royale.utils.Language.as(this.dataProviderModel.dataProvider, Array);
  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);
  var /** @type {Object} */ view = this.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData__strand.view;
  var /** @type {org.apache.royale.core.IItemRendererParent} */ dataGroup = view.dataGroup;
  dataGroup.addItemRendererAt(ir, elementIndex);
  ir.index = index;
  ir.labelField = this.labelField;
  if (dataItemRenderer) {
    dataItemRenderer.dataField = this.dataField;
  }
  this.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData_rendererMap[index] = ir;
  var /** @type {org.apache.royale.core.IListPresentationModel} */ presentationModel = org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_VirtualDataItemRendererFactoryForArrayData__strand.getBeadByType(org.apache.royale.core.IListPresentationModel), org.apache.royale.core.IListPresentationModel);
  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.data = dp[index];
  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);
  return ir;
};


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


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


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


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


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



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