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

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

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


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


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


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


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


/**
 *  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.AddTableRowForArrayListData.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.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 {org.apache.royale.events.IEventDispatcher}
 */
org.apache.royale.jewel.beads.itemRenderers.AddTableRowForArrayListData.prototype.org_apache_royale_jewel_beads_itemRenderers_AddTableRowForArrayListData_dp;


/**
 * @asprivate
 * @protected
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.itemRenderers.AddTableRowForArrayListData.prototype.dataProviderChangeHandler = function(event) {
  if (this.org_apache_royale_jewel_beads_itemRenderers_AddTableRowForArrayListData_dp) {
    this.org_apache_royale_jewel_beads_itemRenderers_AddTableRowForArrayListData_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_AddTableRowForArrayListData_dp = org.apache.royale.utils.Language.as(this.model.dataProvider, org.apache.royale.events.IEventDispatcher);
  if (!this.org_apache_royale_jewel_beads_itemRenderers_AddTableRowForArrayListData_dp)
    return;
  this.org_apache_royale_jewel_beads_itemRenderers_AddTableRowForArrayListData_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
 * @protected
 * @param {org.apache.royale.events.CollectionEvent} event
 */
org.apache.royale.jewel.beads.itemRenderers.AddTableRowForArrayListData.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.jewel.supportClasses.table.TableColumn} */ column;
  var /** @type {org.apache.royale.jewel.itemRenderers.TableItemRenderer} */ ir;
  var /** @type {number} */ index = event.index * this.model.columns.length;
  for (var /** @type {number} */ j = 0; j < this.model.columns.length; j++) {
    column = org.apache.royale.utils.Language.as(this.model.columns[j], org.apache.royale.jewel.supportClasses.table.TableColumn);
    if (column.itemRenderer != null) {
      ir = org.apache.royale.utils.Language.as(column.itemRenderer.newInstance(), org.apache.royale.jewel.itemRenderers.TableItemRenderer);
    } else {
      ir = org.apache.royale.utils.Language.as(this.itemRendererFactory.createItemRenderer(this.itemRendererParent), org.apache.royale.jewel.itemRenderers.TableItemRenderer);
    }
    this.labelField = column.dataField;
    ir.dataField = this.labelField;
    ir.rowIndex = event.index;
    ir.columnIndex = j;
    this.fillRenderer(index++, event.item, ir, presentationModel);
    if (column.align != "") {
      ir.align = column.align;
    }
  }
  var /** @type {number} */ len = this.itemRendererParent.numItemRenderers;
  for (var /** @type {number} */ i = event.index; i < len; i++) {
    ir = org.apache.royale.utils.Language.as(this.itemRendererParent.getItemRendererAt(i), org.apache.royale.jewel.itemRenderers.TableItemRenderer);
    ir.index = i;
    ir.rowIndex = 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.IItemRendererParent}
 */
org.apache.royale.jewel.beads.itemRenderers.AddTableRowForArrayListData.prototype.org_apache_royale_jewel_beads_itemRenderers_AddTableRowForArrayListData__itemRendererParent;


/**
 * @private
 * @type {org.apache.royale.core.IItemRendererClassFactory}
 */
org.apache.royale.jewel.beads.itemRenderers.AddTableRowForArrayListData.prototype.org_apache_royale_jewel_beads_itemRenderers_AddTableRowForArrayListData__itemRendererFactory;


/**
 * @asprivate
 * @protected
 * @param {number} index
 * @param {Object} item
 * @param {org.apache.royale.jewel.itemRenderers.TableItemRenderer} itemRenderer
 * @param {org.apache.royale.core.IListPresentationModel} presentationModel
 */
org.apache.royale.jewel.beads.itemRenderers.AddTableRowForArrayListData.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.jewel.itemRenderers.TableItemRenderer} itemRenderer
 * @param {Object} data
 * @param {number} index
 */
org.apache.royale.jewel.beads.itemRenderers.AddTableRowForArrayListData.prototype.setData = function(itemRenderer, data, index) {
  itemRenderer.index = index;
  itemRenderer.data = data;
};


org.apache.royale.jewel.beads.itemRenderers.AddTableRowForArrayListData.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.AddTableRowForArrayListData.prototype.get__itemRendererParent = function() {
  if (this.org_apache_royale_jewel_beads_itemRenderers_AddTableRowForArrayListData__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_AddTableRowForArrayListData__itemRendererParent = view.dataGroup;
  }
  return this.org_apache_royale_jewel_beads_itemRenderers_AddTableRowForArrayListData__itemRendererParent;
};


org.apache.royale.jewel.beads.itemRenderers.AddTableRowForArrayListData.prototype.get__itemRendererFactory = function() {
  if (!this.org_apache_royale_jewel_beads_itemRenderers_AddTableRowForArrayListData__itemRendererFactory)
    this.org_apache_royale_jewel_beads_itemRenderers_AddTableRowForArrayListData__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_AddTableRowForArrayListData__itemRendererFactory;
};


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


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



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