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

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

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.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.jewel.beads.models.TableModel');
goog.require('org.apache.royale.jewel.supportClasses.table.TableCell');
goog.require('org.apache.royale.jewel.supportClasses.table.TableRow');
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.UpdateTableRowForArrayListData = function() {
};


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


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


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


/**
 * @protected
 * @type {org.apache.royale.jewel.beads.models.TableModel}
 */
org.apache.royale.jewel.beads.itemRenderers.UpdateTableRowForArrayListData.prototype.model;


/**
 *  finish setup
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 *  @royaleignorecoercion org.apache.royale.events.IEventDispatcher
 * @protected
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.itemRenderers.UpdateTableRowForArrayListData.prototype.initComplete = function(event) {
  this._strand.removeEventListener("initComplete", org.apache.royale.utils.Language.closure(this.initComplete, this, 'initComplete'));
  this.model = org.apache.royale.utils.Language.as(this._strand.getBeadByType(org.apache.royale.core.ISelectionModel), org.apache.royale.jewel.beads.models.TableModel);
  this.labelField = this.model.labelField;
  this.model.addEventListener("dataProviderChanged", org.apache.royale.utils.Language.closure(this.dataProviderChangeHandler, this, 'dataProviderChangeHandler'));
  this.dataProviderChangeHandler(null);
};


/**
 * @private
 * @type {Object}
 */
org.apache.royale.jewel.beads.itemRenderers.UpdateTableRowForArrayListData.prototype.org_apache_royale_jewel_beads_itemRenderers_UpdateTableRowForArrayListData_dp;


/**
 * @asprivate
 * @royaleignorecoercion org.apache.royale.events.IEventDispatcher
 * @protected
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.itemRenderers.UpdateTableRowForArrayListData.prototype.dataProviderChangeHandler = function(event) {
  if (this.org_apache_royale_jewel_beads_itemRenderers_UpdateTableRowForArrayListData_dp) {
    this.org_apache_royale_jewel_beads_itemRenderers_UpdateTableRowForArrayListData_dp.removeEventListener(org.apache.royale.events.CollectionEvent.ITEM_UPDATED, org.apache.royale.utils.Language.closure(this.handleItemUpdated, this, 'handleItemUpdated'));
  }
  this.org_apache_royale_jewel_beads_itemRenderers_UpdateTableRowForArrayListData_dp = this.model.dataProvider;
  if (!this.org_apache_royale_jewel_beads_itemRenderers_UpdateTableRowForArrayListData_dp)
    return;
  this.org_apache_royale_jewel_beads_itemRenderers_UpdateTableRowForArrayListData_dp.addEventListener(org.apache.royale.events.CollectionEvent.ITEM_UPDATED, org.apache.royale.utils.Language.closure(this.handleItemUpdated, this, 'handleItemUpdated'));
};


/**
 *  Handles the itemUpdated event by updating the item.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 *  @royaleignorecoercion org.apache.royale.jewel.supportClasses.table.TableCell
 *  @royaleignorecoercion org.apache.royale.jewel.supportClasses.table.TableRow
 *  @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.UpdateTableRowForArrayListData.prototype.handleItemUpdated = function(event) {
  var /** @type {Object} */ ir;
  var /** @type {Object} */ processedRow = org.apache.royale.utils.Language.as(this.itemRendererParent, org.apache.royale.core.UIBase).getElementAt(event.index);
  var /** @type {Object} */ cell;
  var /** @type {number} */ n = processedRow.numElements;
  for (var /** @type {number} */ i = 0; i < n; i++) {
    cell = processedRow.getElementAt(i);
    ir = cell.getElementAt(0);
    this.setData(ir, event.item, event.index);
  }
  this._strand.dispatchEvent(new org.apache.royale.events.Event("layoutNeeded"));
};


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


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


org.apache.royale.jewel.beads.itemRenderers.UpdateTableRowForArrayListData.prototype.set__strand = function(value) {
  this._strand = value;
  value.addEventListener("initComplete", org.apache.royale.utils.Language.closure(this.initComplete, this, 'initComplete'));
};


org.apache.royale.jewel.beads.itemRenderers.UpdateTableRowForArrayListData.prototype.get__itemRendererParent = function() {
  if (this.org_apache_royale_jewel_beads_itemRenderers_UpdateTableRowForArrayListData__itemRendererParent == null) {
    var /** @type {org.apache.royale.html.beads.IListView} */ listView = this._strand.getBeadByType(org.apache.royale.html.beads.IListView);
    this.org_apache_royale_jewel_beads_itemRenderers_UpdateTableRowForArrayListData__itemRendererParent = listView.dataGroup;
  }
  return this.org_apache_royale_jewel_beads_itemRenderers_UpdateTableRowForArrayListData__itemRendererParent;
};


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


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



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