/**
 * Generated by Apache Royale Compiler from org\apache\royale\jewel\supportClasses\table\TBodyContentArea.as
 * org.apache.royale.jewel.supportClasses.table.TBodyContentArea
 *
 * @fileoverview
 *
 * @suppress {checkTypes|accessControls}
 */

goog.provide('org.apache.royale.jewel.supportClasses.table.TBodyContentArea');

goog.require('org.apache.royale.core.IItemRenderer');
goog.require('org.apache.royale.core.WrappedHTMLElement');
goog.require('org.apache.royale.events.IEventDispatcher');
goog.require('org.apache.royale.events.ItemAddedEvent');
goog.require('org.apache.royale.events.ItemRemovedEvent');
goog.require('org.apache.royale.html.supportClasses.ContainerContentArea');
goog.require('org.apache.royale.html.supportClasses.DataItemRenderer');
goog.require('org.apache.royale.html.util.addElementToWrapper');
goog.require('org.apache.royale.jewel.supportClasses.table.TableCell');
goog.require('org.apache.royale.jewel.supportClasses.table.TableRow');
goog.require('org.apache.royale.core.IItemRendererParent');
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
 * @extends {org.apache.royale.html.supportClasses.ContainerContentArea}
 * @implements {org.apache.royale.core.IItemRendererParent}
 */
org.apache.royale.jewel.supportClasses.table.TBodyContentArea = function() {
  
  this.org_apache_royale_jewel_supportClasses_table_TBodyContentArea_itemRenderers = [];
  org.apache.royale.jewel.supportClasses.table.TBodyContentArea.base(this, 'constructor');
  this.typeNames = "jewel tbody";
};
goog.inherits(org.apache.royale.jewel.supportClasses.table.TBodyContentArea, org.apache.royale.html.supportClasses.ContainerContentArea);


/**
 * Prevent renaming of class. Needed for reflection.
 */
goog.exportSymbol('org.apache.royale.jewel.supportClasses.table.TBodyContentArea', org.apache.royale.jewel.supportClasses.table.TBodyContentArea);


/**
 * @royaleignorecoercion org.apache.royale.core.WrappedHTMLElement
 * @protected
 * @override
 */
org.apache.royale.jewel.supportClasses.table.TBodyContentArea.prototype.createElement = function() {
  return org.apache.royale.html.util.addElementToWrapper(this, 'tbody');
};


/**
 * @private
 * @type {Array}
 */
org.apache.royale.jewel.supportClasses.table.TBodyContentArea.prototype.org_apache_royale_jewel_supportClasses_table_TBodyContentArea_itemRenderers;


/**
 * @copy org.apache.royale.core.IItemRendererParent#addItemRenderer()
 * @asprivate
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @export
 * @param {org.apache.royale.core.IItemRenderer} renderer
 * @param {boolean} dispatchAdded
 */
org.apache.royale.jewel.supportClasses.table.TBodyContentArea.prototype.addItemRenderer = function(renderer, dispatchAdded) {
  var /** @type {org.apache.royale.html.supportClasses.DataItemRenderer} */ r = org.apache.royale.utils.Language.as(renderer, org.apache.royale.html.supportClasses.DataItemRenderer);
  r.itemRendererParent = this.host;
  var /** @type {org.apache.royale.jewel.supportClasses.table.TableCell} */ tableCell = new org.apache.royale.jewel.supportClasses.table.TableCell();
  tableCell.addElement(r);
  var /** @type {org.apache.royale.jewel.supportClasses.table.TableRow} */ row;
  if (r.rowIndex > this.numElements - 1) {
    row = new org.apache.royale.jewel.supportClasses.table.TableRow();
    this.addElementAt(row, r.rowIndex, false);
  } else {
    row = org.apache.royale.utils.Language.as(this.getElementAt(r.rowIndex), org.apache.royale.jewel.supportClasses.table.TableRow);
  }
  row.addElement(tableCell, dispatchAdded);
  this.org_apache_royale_jewel_supportClasses_table_TBodyContentArea_itemRenderers.push(r);
  this.dispatchItemAdded(renderer);
};


/**
 * @copy org.apache.royale.core.IItemRendererParent#addItemRendererAt()
 * @asprivate
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @export
 * @param {org.apache.royale.core.IItemRenderer} renderer
 * @param {number} index
 */
org.apache.royale.jewel.supportClasses.table.TBodyContentArea.prototype.addItemRendererAt = function(renderer, index) {
  var /** @type {org.apache.royale.html.supportClasses.DataItemRenderer} */ r = org.apache.royale.utils.Language.as(renderer, org.apache.royale.html.supportClasses.DataItemRenderer);
  r.itemRendererParent = this.host;
  var /** @type {org.apache.royale.jewel.supportClasses.table.TableCell} */ tableCell = new org.apache.royale.jewel.supportClasses.table.TableCell();
  tableCell.addElement(r);
  var /** @type {org.apache.royale.jewel.supportClasses.table.TableRow} */ row;
  if (r.rowIndex > this.numElements - 1) {
    row = new org.apache.royale.jewel.supportClasses.table.TableRow();
    this.addElementAt(row, r.rowIndex, false);
  } else {
    row = org.apache.royale.utils.Language.as(this.getElementAt(r.rowIndex), org.apache.royale.jewel.supportClasses.table.TableRow);
  }
  row.addElementAt(tableCell, r.columnIndex, true);
  this.org_apache_royale_jewel_supportClasses_table_TBodyContentArea_itemRenderers.push(r);
  this.dispatchItemAdded(r);
};


/**
 * @royaleignorecoercion org.apache.royale.events.IEventDispatcher
 * @export
 * @param {org.apache.royale.core.IItemRenderer} renderer
 */
org.apache.royale.jewel.supportClasses.table.TBodyContentArea.prototype.dispatchItemAdded = function(renderer) {
  var /** @type {org.apache.royale.events.ItemAddedEvent} */ newEvent = new org.apache.royale.events.ItemAddedEvent("itemAdded");
  newEvent.item = renderer;
  this.host.dispatchEvent(newEvent);
};


/**
 * @copy org.apache.royale.core.IItemRendererParent#removeItemRenderer()
 * @asprivate
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @export
 * @param {org.apache.royale.core.IItemRenderer} renderer
 */
org.apache.royale.jewel.supportClasses.table.TBodyContentArea.prototype.removeItemRenderer = function(renderer) {
  this.org_apache_royale_jewel_supportClasses_table_TBodyContentArea_itemRenderers.splice(this.org_apache_royale_jewel_supportClasses_table_TBodyContentArea_itemRenderers.indexOf(renderer), 1);
  var /** @type {org.apache.royale.events.ItemRemovedEvent} */ newEvent = new org.apache.royale.events.ItemRemovedEvent("itemRemoved");
  newEvent.item = renderer;
  org.apache.royale.utils.Language.as(this.host, org.apache.royale.events.IEventDispatcher).dispatchEvent(newEvent);
};


/**
 * @private
 * @type {org.apache.royale.jewel.supportClasses.table.TableRow}
 */
org.apache.royale.jewel.supportClasses.table.TBodyContentArea.prototype.org_apache_royale_jewel_supportClasses_table_TBodyContentArea_processedRow;


/**
 * @copy org.apache.royale.core.IItemRendererParent#removeAllItemRenderers()
 * @asprivate
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @export
 */
org.apache.royale.jewel.supportClasses.table.TBodyContentArea.prototype.removeAllItemRenderers = function() {
  while (this.numElements > 0) {
    this.org_apache_royale_jewel_supportClasses_table_TBodyContentArea_processedRow = org.apache.royale.utils.Language.as(this.getElementAt(0), org.apache.royale.jewel.supportClasses.table.TableRow);
    while (this.org_apache_royale_jewel_supportClasses_table_TBodyContentArea_processedRow.numElements > 0) {
      var /** @type {org.apache.royale.jewel.supportClasses.table.TableCell} */ cell = org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_supportClasses_table_TBodyContentArea_processedRow.getElementAt(0), org.apache.royale.jewel.supportClasses.table.TableCell);
      var /** @type {org.apache.royale.core.IItemRenderer} */ ir = org.apache.royale.utils.Language.as(cell.getElementAt(0), org.apache.royale.core.IItemRenderer);
      this.removeItemRenderer(ir);
      cell.removeElement(ir);
      this.org_apache_royale_jewel_supportClasses_table_TBodyContentArea_processedRow.removeElement(cell);
    }
    this.removeElement(this.org_apache_royale_jewel_supportClasses_table_TBodyContentArea_processedRow);
  }
};


/**
 *  @copy org.apache.royale.core.IItemRendererParent#getItemRendererAt()
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @export
 * @param {number} index
 * @return {org.apache.royale.core.IItemRenderer}
 */
org.apache.royale.jewel.supportClasses.table.TBodyContentArea.prototype.getItemRendererAt = function(index) {
  if (index < 0 || index >= this.org_apache_royale_jewel_supportClasses_table_TBodyContentArea_itemRenderers.length)
    return null;
  return org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_supportClasses_table_TBodyContentArea_itemRenderers[index], org.apache.royale.core.IItemRenderer);
};


/**
 *  @copy org.apache.royale.core.IItemRendererParent#getItemRendererForIndex()
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @export
 * @param {number} index
 * @return {org.apache.royale.core.IItemRenderer}
 */
org.apache.royale.jewel.supportClasses.table.TBodyContentArea.prototype.getItemRendererForIndex = function(index) {
  if (index < 0 || index >= this.org_apache_royale_jewel_supportClasses_table_TBodyContentArea_itemRenderers.length)
    return null;
  return org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_supportClasses_table_TBodyContentArea_itemRenderers[index], org.apache.royale.core.IItemRenderer);
};


/**
 *  Refreshes the itemRenderers. Useful after a size change by the data group.
 *  Not used for now. This should be revised in this case
 *
 *  @copy org.apache.royale.core.IItemRendererParent#updateAllItemRenderers()
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @export
 */
org.apache.royale.jewel.supportClasses.table.TBodyContentArea.prototype.updateAllItemRenderers = function() {
  var /** @type {number} */ n = this.numElements;
  for (var /** @type {number} */ i = 0; i < n; i++) {
    var /** @type {org.apache.royale.html.supportClasses.DataItemRenderer} */ renderer = org.apache.royale.utils.Language.as(this.getItemRendererAt(i), org.apache.royale.html.supportClasses.DataItemRenderer);
    if (renderer) {
      renderer.setWidth(this.width, true);
      renderer.adjustSize();
    }
  }
};


org.apache.royale.jewel.supportClasses.table.TBodyContentArea.prototype.get__numItemRenderers = function() {
  return this.numElements;
};


Object.defineProperties(org.apache.royale.jewel.supportClasses.table.TBodyContentArea.prototype, /** @lends {org.apache.royale.jewel.supportClasses.table.TBodyContentArea.prototype} */ {
/**
  * @export
  * @type {number} */
numItemRenderers: {
get: org.apache.royale.jewel.supportClasses.table.TBodyContentArea.prototype.get__numItemRenderers}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.supportClasses.table.TBodyContentArea.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'numItemRenderers': { type: 'int', access: 'readonly', declaredBy: 'org.apache.royale.jewel.supportClasses.table.TBodyContentArea'}
      };
    },
    methods: function () {
      return {
        'TBodyContentArea': { type: '', declaredBy: 'org.apache.royale.jewel.supportClasses.table.TBodyContentArea'},
        'addItemRenderer': { type: 'void', declaredBy: 'org.apache.royale.jewel.supportClasses.table.TBodyContentArea', parameters: function () { return [  { index: 1, type: 'org.apache.royale.core.IItemRenderer', optional: false },{ index: 2, type: 'Boolean', optional: false } ]; }},
        'addItemRendererAt': { type: 'void', declaredBy: 'org.apache.royale.jewel.supportClasses.table.TBodyContentArea', parameters: function () { return [  { index: 1, type: 'org.apache.royale.core.IItemRenderer', optional: false },{ index: 2, type: 'int', optional: false } ]; }},
        'dispatchItemAdded': { type: 'void', declaredBy: 'org.apache.royale.jewel.supportClasses.table.TBodyContentArea', parameters: function () { return [  { index: 1, type: 'org.apache.royale.core.IItemRenderer', optional: false } ]; }},
        'removeItemRenderer': { type: 'void', declaredBy: 'org.apache.royale.jewel.supportClasses.table.TBodyContentArea', parameters: function () { return [  { index: 1, type: 'org.apache.royale.core.IItemRenderer', optional: false } ]; }},
        'removeAllItemRenderers': { type: 'void', declaredBy: 'org.apache.royale.jewel.supportClasses.table.TBodyContentArea'},
        'getItemRendererAt': { type: 'org.apache.royale.core.IItemRenderer', declaredBy: 'org.apache.royale.jewel.supportClasses.table.TBodyContentArea', parameters: function () { return [  { index: 1, type: 'int', optional: false } ]; }},
        'getItemRendererForIndex': { type: 'org.apache.royale.core.IItemRenderer', declaredBy: 'org.apache.royale.jewel.supportClasses.table.TBodyContentArea', parameters: function () { return [  { index: 1, type: 'int', optional: false } ]; }},
        'updateAllItemRenderers': { type: 'void', declaredBy: 'org.apache.royale.jewel.supportClasses.table.TBodyContentArea'}
      };
    }
  };
};