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

goog.provide('org.apache.royale.jewel.beads.views.DropDownListView');

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.events.Event');
goog.require('org.apache.royale.html.beads.DataContainerView');
goog.require('org.apache.royale.html.elements.Select');
goog.require('org.apache.royale.jewel.DropDownList');
goog.require('org.apache.royale.jewel.beads.models.IDropDownListModel');
goog.require('org.apache.royale.utils.Language');



/**
 * @constructor
 * @extends {org.apache.royale.html.beads.DataContainerView}
 */
org.apache.royale.jewel.beads.views.DropDownListView = function() {
  org.apache.royale.jewel.beads.views.DropDownListView.base(this, 'constructor');
};
goog.inherits(org.apache.royale.jewel.beads.views.DropDownListView, org.apache.royale.html.beads.DataContainerView);


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


/**
 * @private
 * @type {org.apache.royale.jewel.DropDownList}
 */
org.apache.royale.jewel.beads.views.DropDownListView.prototype.org_apache_royale_jewel_beads_views_DropDownListView_dropDownList;


/**
 * @export
 * @type {string}
 */
org.apache.royale.jewel.beads.views.DropDownListView.prototype.prompt = "";


/**
 * @protected
 * @override
 */
org.apache.royale.jewel.beads.views.DropDownListView.prototype.dataProviderChangeHandler = function(event) {
  org.apache.royale.jewel.beads.views.DropDownListView.superClass_.dataProviderChangeHandler.apply(this, [ event] );
  this.org_apache_royale_jewel_beads_views_DropDownListView_changedSelection();
};


/**
 * @asprivate
 * @royaleignorecoercion org.apache.royale.core.ISelectionModel
 * @protected
 * @override
 */
org.apache.royale.jewel.beads.views.DropDownListView.prototype.handleInitComplete = function(event) {
  this.org_apache_royale_jewel_beads_views_DropDownListView_model = this._strand.getBeadByType(org.apache.royale.core.ISelectionModel);
  this.org_apache_royale_jewel_beads_views_DropDownListView_model.addEventListener("selectedIndexChanged", org.apache.royale.utils.Language.closure(this.selectionChangeHandler, this, 'selectionChangeHandler'));
  org.apache.royale.jewel.beads.views.DropDownListView.superClass_.handleInitComplete.apply(this, [ event] );
};


/**
 * @protected
 * @type {number}
 */
org.apache.royale.jewel.beads.views.DropDownListView.prototype.lastSelectedIndex = -1;


/**
 * @asprivate
 * @royaleignorecoercion org.apache.royale.core.ISelectableItemRenderer
 * @royaleignorecoercion org.apache.royale.jewel.beads.models.IDropDownListModel
 * @protected
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.views.DropDownListView.prototype.selectionChangeHandler = function(event) {
  var /** @type {Object} */ ir;
  if (this.lastSelectedIndex != -1) {
    ir = this.dataGroup.getItemRendererAt(this.lastSelectedIndex);
  }
  if (ir)
    ir.selected = false;
  var /** @type {number} */ newIndex = this.org_apache_royale_jewel_beads_views_DropDownListView_model.selectedIndex;
  if (org.apache.royale.utils.Language.is(this.org_apache_royale_jewel_beads_views_DropDownListView_model, org.apache.royale.jewel.beads.models.IDropDownListModel)) {
    newIndex += this.org_apache_royale_jewel_beads_views_DropDownListView_model.offset;
  }
  ir = this.dataGroup.getItemRendererAt(newIndex);
  if (ir)
    ir.selected = true;
  this.lastSelectedIndex = newIndex;
};


/**
 * @protected
 * @override
 */
org.apache.royale.jewel.beads.views.DropDownListView.prototype.itemsCreatedHandler = function(event) {
  org.apache.royale.jewel.beads.views.DropDownListView.superClass_.itemsCreatedHandler.apply(this, [ event] );
  this.org_apache_royale_jewel_beads_views_DropDownListView_changedSelection();
};


/**
 * @private
 * @type {org.apache.royale.core.ISelectionModel}
 */
org.apache.royale.jewel.beads.views.DropDownListView.prototype.org_apache_royale_jewel_beads_views_DropDownListView_model;


/**
 * @private
 */
org.apache.royale.jewel.beads.views.DropDownListView.prototype.org_apache_royale_jewel_beads_views_DropDownListView_changedSelection = function() {
  this.org_apache_royale_jewel_beads_views_DropDownListView_model = org.apache.royale.utils.Language.as(this.dataModel, org.apache.royale.core.ISelectionModel);
  this.org_apache_royale_jewel_beads_views_DropDownListView_dropDownList.selectedIndex = this.org_apache_royale_jewel_beads_views_DropDownListView_model.selectedIndex;
  this.org_apache_royale_jewel_beads_views_DropDownListView_dropDownList.selectedItem = this.org_apache_royale_jewel_beads_views_DropDownListView_model.selectedItem;
};


org.apache.royale.jewel.beads.views.DropDownListView.prototype.set__strand = function(value) {
  org.apache.royale.jewel.beads.views.DropDownListView.superClass_.set__strand.apply(this, [ value] );
  this.org_apache_royale_jewel_beads_views_DropDownListView_dropDownList = org.apache.royale.utils.Language.as(value, org.apache.royale.jewel.DropDownList);
  this.org_apache_royale_jewel_beads_views_DropDownListView_dropDownList.dropDown = new org.apache.royale.html.elements.Select();
  var /** @type {string} */ name = "dropDownList" + Math.random();
  this.org_apache_royale_jewel_beads_views_DropDownListView_dropDownList.dropDown.element.name = name;
  this.org_apache_royale_jewel_beads_views_DropDownListView_dropDownList.addElement(this.org_apache_royale_jewel_beads_views_DropDownListView_dropDownList.dropDown);
};


Object.defineProperties(org.apache.royale.jewel.beads.views.DropDownListView.prototype, /** @lends {org.apache.royale.jewel.beads.views.DropDownListView.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.jewel.beads.views.DropDownListView.prototype.set__strand}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.beads.views.DropDownListView.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {
      return {
        'prompt': { type: 'String'}
      };
    },
    accessors: function () {
      return {
        'strand': { type: 'org.apache.royale.core.IStrand', access: 'writeonly', declaredBy: 'org.apache.royale.jewel.beads.views.DropDownListView'}
      };
    },
    methods: function () {
      return {
        'DropDownListView': { type: '', declaredBy: 'org.apache.royale.jewel.beads.views.DropDownListView'}
      };
    }
  };
};