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

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

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.ISelectionModel');
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.CollectionEvent');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.events.IEventDispatcher');
goog.require('org.apache.royale.html.beads.IListView');
goog.require('org.apache.royale.utils.loadBeadFromValuesManager');
goog.require('org.apache.royale.core.IBead');
goog.require('org.apache.royale.utils.Language');



/**
 * Constructor
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.0
 * @constructor
 * @implements {org.apache.royale.core.IBead}
 */
org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData = function() {
};


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


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


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


/**
 *  finish setup
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.8
 * @protected
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData.prototype.initComplete = function(event) {
  org.apache.royale.utils.Language.as(this._strand, org.apache.royale.events.IEventDispatcher, true).removeEventListener("initComplete", org.apache.royale.utils.Language.closure(this.initComplete, this, 'initComplete'));
  this.org_apache_royale_html_beads_DynamicAddItemRendererForArrayListData__dataProviderModel = org.apache.royale.utils.Language.as(this._strand.getBeadByType(org.apache.royale.core.ISelectionModel), org.apache.royale.core.ISelectionModel);
  this.labelField = this.org_apache_royale_html_beads_DynamicAddItemRendererForArrayListData__dataProviderModel.labelField;
  this.dataProviderModel.addEventListener("dataProviderChanged", org.apache.royale.utils.Language.closure(this.dataProviderChangeHandler, this, 'dataProviderChangeHandler'));
  this.dataProviderChangeHandler(null);
};


/**
 * @asprivate
 * @protected
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData.prototype.dataProviderChangeHandler = function(event) {
  var /** @type {org.apache.royale.events.IEventDispatcher} */ dp = org.apache.royale.utils.Language.as(this.dataProviderModel.dataProvider, org.apache.royale.events.IEventDispatcher);
  if (!dp)
    return;
  dp.addEventListener(org.apache.royale.events.CollectionEvent.ITEM_ADDED, org.apache.royale.utils.Language.closure(this.handleItemAdded, this, 'handleItemAdded'));
};


/**
 * Handles the itemRemoved event by removing the item.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.0
 * @protected
 * @param {org.apache.royale.events.CollectionEvent} event
 */
org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData.prototype.handleItemAdded = function(event) {
  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 {org.apache.royale.core.ISelectableItemRenderer} */ ir = org.apache.royale.utils.Language.as(this.itemRendererFactory.createItemRenderer(this.itemRendererParent), org.apache.royale.core.ISelectableItemRenderer);
  this.fillRenderer(event.index, event.item, ir, presentationModel);
  var /** @type {org.apache.royale.core.UIBase} */ dataGroup = org.apache.royale.utils.Language.as(this.itemRendererParent, org.apache.royale.core.UIBase);
  var /** @type {number} */ n = dataGroup.numElements;
  for (var /** @type {number} */ i = event.index; i < n; i++) {
    ir = org.apache.royale.utils.Language.as(dataGroup.getElementAt(i), org.apache.royale.core.ISelectableItemRenderer);
    ir.index = i;
  }
  org.apache.royale.utils.Language.as(this._strand, org.apache.royale.events.IEventDispatcher).dispatchEvent(new org.apache.royale.events.Event("layoutNeeded"));
};


/**
 * @private
 * @type {org.apache.royale.core.IDataProviderModel}
 */
org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData.prototype.org_apache_royale_html_beads_DynamicAddItemRendererForArrayListData__dataProviderModel;


/**
 * @private
 * @type {org.apache.royale.core.IItemRendererParent}
 */
org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData.prototype.org_apache_royale_html_beads_DynamicAddItemRendererForArrayListData__itemRendererParent;


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


/**
 * @asprivate
 * @protected
 * @param {number} index
 * @param {Object} item
 * @param {org.apache.royale.core.ISelectableItemRenderer} itemRenderer
 * @param {org.apache.royale.core.IListPresentationModel} presentationModel
 */
org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData.prototype.fillRenderer = function(index, item, itemRenderer, presentationModel) {
  this.itemRendererParent.addItemRendererAt(itemRenderer, index);
  itemRenderer.labelField = this.labelField;
  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(itemRenderer, org.apache.royale.core.UIBase, true).style = style;
    org.apache.royale.utils.Language.as(itemRenderer, org.apache.royale.core.UIBase, true).height = presentationModel.rowHeight;
    org.apache.royale.utils.Language.as(itemRenderer, org.apache.royale.core.UIBase, true).percentWidth = 100;
  }
  this.setData(itemRenderer, item, index);
};


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


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


org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData.prototype.get__dataProviderModel = function() {
  if (this.org_apache_royale_html_beads_DynamicAddItemRendererForArrayListData__dataProviderModel == null) {
    this.org_apache_royale_html_beads_DynamicAddItemRendererForArrayListData__dataProviderModel = org.apache.royale.utils.Language.as(this._strand.getBeadByType(org.apache.royale.core.IDataProviderModel), org.apache.royale.core.IDataProviderModel);
  }
  return this.org_apache_royale_html_beads_DynamicAddItemRendererForArrayListData__dataProviderModel;
};


org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData.prototype.get__itemRendererParent = function() {
  if (this.org_apache_royale_html_beads_DynamicAddItemRendererForArrayListData__itemRendererParent == null) {
    var /** @type {org.apache.royale.html.beads.IListView} */ view = this._strand.view;
    this.org_apache_royale_html_beads_DynamicAddItemRendererForArrayListData__itemRendererParent = view.dataGroup;
  }
  return this.org_apache_royale_html_beads_DynamicAddItemRendererForArrayListData__itemRendererParent;
};


org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData.prototype.get__itemRendererFactory = function() {
  if (!this.org_apache_royale_html_beads_DynamicAddItemRendererForArrayListData__itemRendererFactory)
    this.org_apache_royale_html_beads_DynamicAddItemRendererForArrayListData__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_DynamicAddItemRendererForArrayListData__itemRendererFactory;
};


Object.defineProperties(org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData.prototype, /** @lends {org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData.prototype.set__strand},
/**
  * @export
  * @type {org.apache.royale.core.IDataProviderModel} */
dataProviderModel: {
get: org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData.prototype.get__dataProviderModel},
/**
  * @export
  * @type {org.apache.royale.core.IItemRendererParent} */
itemRendererParent: {
get: org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData.prototype.get__itemRendererParent},
/**
  * @export
  * @type {org.apache.royale.core.IItemRendererClassFactory} */
itemRendererFactory: {
get: org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData.prototype.get__itemRendererFactory}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData.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.DynamicAddItemRendererForArrayListData'},
        'dataProviderModel': { type: 'org.apache.royale.core.IDataProviderModel', access: 'readonly', declaredBy: 'org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData'},
        'itemRendererParent': { type: 'org.apache.royale.core.IItemRendererParent', access: 'readonly', declaredBy: 'org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData'},
        'itemRendererFactory': { type: 'org.apache.royale.core.IItemRendererClassFactory', access: 'readonly', declaredBy: 'org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData'}
      };
    },
    methods: function () {
      return {
        'DynamicAddItemRendererForArrayListData': { type: '', declaredBy: 'org.apache.royale.html.beads.DynamicAddItemRendererForArrayListData'}
      };
    }
  };
};