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

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

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.4
 * @constructor
 * @implements {org.apache.royale.core.IBead}
 */
org.apache.royale.jewel.beads.itemRenderers.AddListItemRendererForArrayListData = function() {
};


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


/**
 * @protected
 * @type {org.apache.royale.core.IStrand}
 */
org.apache.royale.jewel.beads.itemRenderers.AddListItemRendererForArrayListData.prototype._strand;


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


/**
 *  finish setup
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @protected
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.itemRenderers.AddListItemRendererForArrayListData.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_jewel_beads_itemRenderers_AddListItemRendererForArrayListData__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_jewel_beads_itemRenderers_AddListItemRendererForArrayListData__dataProviderModel.labelField;
  this.dataProviderModel.addEventListener("dataProviderChanged", org.apache.royale.utils.Language.closure(this.dataProviderChangeHandler, this, 'dataProviderChangeHandler'));
  this.dataProviderChangeHandler(null);
};


/**
 * @private
 * @type {org.apache.royale.events.IEventDispatcher}
 */
org.apache.royale.jewel.beads.itemRenderers.AddListItemRendererForArrayListData.prototype.org_apache_royale_jewel_beads_itemRenderers_AddListItemRendererForArrayListData_dp;


/**
 * @asprivate
 * @protected
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.itemRenderers.AddListItemRendererForArrayListData.prototype.dataProviderChangeHandler = function(event) {
  if (this.org_apache_royale_jewel_beads_itemRenderers_AddListItemRendererForArrayListData_dp) {
    this.org_apache_royale_jewel_beads_itemRenderers_AddListItemRendererForArrayListData_dp.removeEventListener(org.apache.royale.events.CollectionEvent.ITEM_ADDED, org.apache.royale.utils.Language.closure(this.handleItemAdded, this, 'handleItemAdded'));
  }
  this.org_apache_royale_jewel_beads_itemRenderers_AddListItemRendererForArrayListData_dp = org.apache.royale.utils.Language.as(this.dataProviderModel.dataProvider, org.apache.royale.events.IEventDispatcher);
  if (!this.org_apache_royale_jewel_beads_itemRenderers_AddListItemRendererForArrayListData_dp)
    return;
  this.org_apache_royale_jewel_beads_itemRenderers_AddListItemRendererForArrayListData_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.4
 *  @royaleignorecoercion org.apache.royale.core.ISelectableItemRenderer
 *  @royaleignorecoercion org.apache.royale.events.IEventDispatcher
 * @protected
 * @param {org.apache.royale.events.CollectionEvent} event
 */
org.apache.royale.jewel.beads.itemRenderers.AddListItemRendererForArrayListData.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 {Object} */ ir = this.itemRendererFactory.createItemRenderer(this.itemRendererParent);
  this.fillRenderer(event.index, event.item, ir, presentationModel);
  var /** @type {number} */ n = this.itemRendererParent.numItemRenderers;
  for (var /** @type {number} */ i = event.index; i < n; i++) {
    ir = this.itemRendererParent.getItemRendererAt(i);
    ir.index = i;
  }
  this._strand.dispatchEvent(new org.apache.royale.events.Event("layoutNeeded"));
};


/**
 * @private
 * @type {org.apache.royale.core.IDataProviderModel}
 */
org.apache.royale.jewel.beads.itemRenderers.AddListItemRendererForArrayListData.prototype.org_apache_royale_jewel_beads_itemRenderers_AddListItemRendererForArrayListData__dataProviderModel;


/**
 * @private
 * @type {org.apache.royale.core.IItemRendererParent}
 */
org.apache.royale.jewel.beads.itemRenderers.AddListItemRendererForArrayListData.prototype.org_apache_royale_jewel_beads_itemRenderers_AddListItemRendererForArrayListData__itemRendererParent;


/**
 * @private
 * @type {org.apache.royale.core.IItemRendererClassFactory}
 */
org.apache.royale.jewel.beads.itemRenderers.AddListItemRendererForArrayListData.prototype.org_apache_royale_jewel_beads_itemRenderers_AddListItemRendererForArrayListData__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.jewel.beads.itemRenderers.AddListItemRendererForArrayListData.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.jewel.beads.itemRenderers.AddListItemRendererForArrayListData.prototype.setData = function(itemRenderer, data, index) {
  itemRenderer.index = index;
  itemRenderer.data = data;
};


org.apache.royale.jewel.beads.itemRenderers.AddListItemRendererForArrayListData.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.jewel.beads.itemRenderers.AddListItemRendererForArrayListData.prototype.get__dataProviderModel = function() {
  if (this.org_apache_royale_jewel_beads_itemRenderers_AddListItemRendererForArrayListData__dataProviderModel == null) {
    this.org_apache_royale_jewel_beads_itemRenderers_AddListItemRendererForArrayListData__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_jewel_beads_itemRenderers_AddListItemRendererForArrayListData__dataProviderModel;
};


org.apache.royale.jewel.beads.itemRenderers.AddListItemRendererForArrayListData.prototype.get__itemRendererParent = function() {
  if (this.org_apache_royale_jewel_beads_itemRenderers_AddListItemRendererForArrayListData__itemRendererParent == null) {
    var /** @type {org.apache.royale.html.beads.IListView} */ view = org.apache.royale.utils.Language.as(org.apache.royale.utils.Language.as(this._strand, org.apache.royale.core.IStrandWithModelView).view, org.apache.royale.html.beads.IListView);
    this.org_apache_royale_jewel_beads_itemRenderers_AddListItemRendererForArrayListData__itemRendererParent = view.dataGroup;
  }
  return this.org_apache_royale_jewel_beads_itemRenderers_AddListItemRendererForArrayListData__itemRendererParent;
};


org.apache.royale.jewel.beads.itemRenderers.AddListItemRendererForArrayListData.prototype.get__itemRendererFactory = function() {
  if (!this.org_apache_royale_jewel_beads_itemRenderers_AddListItemRendererForArrayListData__itemRendererFactory)
    this.org_apache_royale_jewel_beads_itemRenderers_AddListItemRendererForArrayListData__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_jewel_beads_itemRenderers_AddListItemRendererForArrayListData__itemRendererFactory;
};


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


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



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