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

goog.provide('org.apache.royale.jewel.beads.models.TableModel');

goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.jewel.beads.models.TableArrayListSelectionModel');
goog.require('org.apache.royale.jewel.supportClasses.table.TableColumn');
goog.require('org.apache.royale.utils.Language');



/**
 * @constructor
 * @extends {org.apache.royale.jewel.beads.models.TableArrayListSelectionModel}
 */
org.apache.royale.jewel.beads.models.TableModel = function() {
  org.apache.royale.jewel.beads.models.TableModel.base(this, 'constructor');
};
goog.inherits(org.apache.royale.jewel.beads.models.TableModel, org.apache.royale.jewel.beads.models.TableArrayListSelectionModel);


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


/**
 * @private
 * @type {Array}
 */
org.apache.royale.jewel.beads.models.TableModel.prototype.org_apache_royale_jewel_beads_models_TableModel__columns;


/**
 * @private
 * @type {Object}
 */
org.apache.royale.jewel.beads.models.TableModel.prototype.org_apache_royale_jewel_beads_models_TableModel__selectedItemProperty;


/**
 * @asprivate
 * @export
 * @return {number}
 */
org.apache.royale.jewel.beads.models.TableModel.prototype.getIndexForSelectedItemProperty = function() {
  if (!this.selectedItemProperty)
    return -1;
  var /** @type {number} */ index = 0;
  for (var /** @type {number} */ i = 0; i < this.dataProvider.length; i++) {
    for (var /** @type {number} */ j = 0; j < this.org_apache_royale_jewel_beads_models_TableModel__columns.length; j++) {
      var /** @type {org.apache.royale.jewel.supportClasses.table.TableColumn} */ column = org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_models_TableModel__columns[j], org.apache.royale.jewel.supportClasses.table.TableColumn);
      var /** @type {Object} */ test = org.apache.royale.utils.Language.as(this.dataProvider.getItemAt(i)[column.dataField], Object);
      if (this.dataProvider.getItemAt(i) == this.selectedItem && this.labelField == column.dataField) {
        return index;
      }
      index++;
    }
  }
  return -1;
};


org.apache.royale.jewel.beads.models.TableModel.prototype.get__columns = function() {
  return this.org_apache_royale_jewel_beads_models_TableModel__columns;
};


org.apache.royale.jewel.beads.models.TableModel.prototype.set__columns = function(value) {
  this.org_apache_royale_jewel_beads_models_TableModel__columns = value;
};


org.apache.royale.jewel.beads.models.TableModel.prototype.get__selectedItemProperty = function() {
  return this.org_apache_royale_jewel_beads_models_TableModel__selectedItemProperty;
};


org.apache.royale.jewel.beads.models.TableModel.prototype.set__selectedItemProperty = function(value) {
  if (this.labelField == null || this.labelField == "")
    return;
  if (value == this.org_apache_royale_jewel_beads_models_TableModel__selectedItemProperty)
    return;
  this.org_apache_royale_jewel_beads_models_TableModel__selectedItemProperty = value;
  var /** @type {number} */ n = Number(this.dataProvider.length);
  for (var /** @type {number} */ i = 0; i < n; i++) {
    if (this.dataProvider.getItemAt(i) == this.selectedItem && this.dataProvider.getItemAt(i)[this.labelField] == value) {
      this.selectedIndex = i;
      break;
    }
  }
  this.dispatchEvent(new org.apache.royale.events.Event("selectedItemPropertyChanged"));
};


Object.defineProperties(org.apache.royale.jewel.beads.models.TableModel.prototype, /** @lends {org.apache.royale.jewel.beads.models.TableModel.prototype} */ {
/**
  * @export
  * @type {Array} */
columns: {
get: org.apache.royale.jewel.beads.models.TableModel.prototype.get__columns,
set: org.apache.royale.jewel.beads.models.TableModel.prototype.set__columns},
/**
  * @export
  * @type {Object} */
selectedItemProperty: {
get: org.apache.royale.jewel.beads.models.TableModel.prototype.get__selectedItemProperty,
set: org.apache.royale.jewel.beads.models.TableModel.prototype.set__selectedItemProperty}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.beads.models.TableModel.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'columns': { type: 'Array', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.beads.models.TableModel'},
        'selectedItemProperty': { type: 'Object', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.beads.models.TableModel'}
      };
    },
    methods: function () {
      return {
        'TableModel': { type: '', declaredBy: 'org.apache.royale.jewel.beads.models.TableModel'},
        'getIndexForSelectedItemProperty': { type: 'Number', declaredBy: 'org.apache.royale.jewel.beads.models.TableModel'}
      };
    }
  };
};