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

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

goog.require('org.apache.royale.core.IDataProviderModel');
goog.require('org.apache.royale.core.IItemRendererParent');
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.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.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.DynamicRemoveItemRendererForArrayListData = function() {
};


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


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


/**
 *  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.DynamicRemoveItemRendererForArrayListData.prototype.initComplete = function(event) {
  org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_DynamicRemoveItemRendererForArrayListData__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_DynamicRemoveItemRendererForArrayListData__dataProviderModel = org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_DynamicRemoveItemRendererForArrayListData__strand.getBeadByType(org.apache.royale.core.ISelectionModel), org.apache.royale.core.ISelectionModel);
  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.DynamicRemoveItemRendererForArrayListData.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_REMOVED, org.apache.royale.utils.Language.closure(this.handleItemRemoved, this, 'handleItemRemoved'));
};


/**
 * 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.DynamicRemoveItemRendererForArrayListData.prototype.handleItemRemoved = function(event) {
  var /** @type {org.apache.royale.core.UIBase} */ parent = org.apache.royale.utils.Language.as(this.itemRendererParent, org.apache.royale.core.UIBase);
  var /** @type {org.apache.royale.core.ISelectableItemRenderer} */ ir = org.apache.royale.utils.Language.as(parent.getElementAt(event.index), org.apache.royale.core.ISelectableItemRenderer);
  this.itemRendererParent.removeItemRenderer(ir);
  var /** @type {number} */ n = parent.numElements;
  for (var /** @type {number} */ i = event.index; i < n; i++) {
    ir = org.apache.royale.utils.Language.as(parent.getElementAt(i), org.apache.royale.core.ISelectableItemRenderer);
    ir.index = i;
  }
  org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_DynamicRemoveItemRendererForArrayListData__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.DynamicRemoveItemRendererForArrayListData.prototype.org_apache_royale_html_beads_DynamicRemoveItemRendererForArrayListData__dataProviderModel;


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


org.apache.royale.html.beads.DynamicRemoveItemRendererForArrayListData.prototype.set__strand = function(value) {
  this.org_apache_royale_html_beads_DynamicRemoveItemRendererForArrayListData__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.DynamicRemoveItemRendererForArrayListData.prototype.get__dataProviderModel = function() {
  if (this.org_apache_royale_html_beads_DynamicRemoveItemRendererForArrayListData__dataProviderModel == null) {
    this.org_apache_royale_html_beads_DynamicRemoveItemRendererForArrayListData__dataProviderModel = org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_DynamicRemoveItemRendererForArrayListData__strand.getBeadByType(org.apache.royale.core.IDataProviderModel), org.apache.royale.core.IDataProviderModel);
  }
  return this.org_apache_royale_html_beads_DynamicRemoveItemRendererForArrayListData__dataProviderModel;
};


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


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


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



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