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

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

goog.require('org.apache.royale.core.IBeadLayout');
goog.require('org.apache.royale.core.IChild');
goog.require('org.apache.royale.core.IContainerBaseStrandChildrenHost');
goog.require('org.apache.royale.core.ILayoutView');
goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.core.IViewport');
goog.require('org.apache.royale.core.UIBase');
goog.require('org.apache.royale.core.ValuesManager');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.html.beads.GroupView');
goog.require('org.apache.royale.jewel.FormItem');
goog.require('org.apache.royale.jewel.Label');
goog.require('org.apache.royale.jewel.beads.controls.TextAlign');
goog.require('org.apache.royale.jewel.beads.layouts.VerticalLayout');
goog.require('org.apache.royale.jewel.beads.models.FormItemModel');
goog.require('org.apache.royale.jewel.supportClasses.formitem.FormItemLayoutProxy');
goog.require('org.apache.royale.core.IBeadView');
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.beads.GroupView}
 * @implements {org.apache.royale.core.IBeadView}
 */
org.apache.royale.jewel.beads.views.FormItemView = function() {
  org.apache.royale.jewel.beads.views.FormItemView.base(this, 'constructor');
};
goog.inherits(org.apache.royale.jewel.beads.views.FormItemView, org.apache.royale.html.beads.GroupView);


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


/**
 * @protected
 * @type {org.apache.royale.jewel.FormItem}
 */
org.apache.royale.jewel.beads.views.FormItemView.prototype.formItem;


/**
 * @private
 * @type {org.apache.royale.core.UIBase}
 */
org.apache.royale.jewel.beads.views.FormItemView.prototype.org_apache_royale_jewel_beads_views_FormItemView__contentArea;


/**
 * @private
 * @type {org.apache.royale.jewel.beads.models.FormItemModel}
 */
org.apache.royale.jewel.beads.views.FormItemView.prototype.org_apache_royale_jewel_beads_views_FormItemView_model;


/**
 * @private
 * @type {org.apache.royale.jewel.Label}
 */
org.apache.royale.jewel.beads.views.FormItemView.prototype.org_apache_royale_jewel_beads_views_FormItemView_textLabel;


/**
 * @private
 * @type {org.apache.royale.jewel.beads.controls.TextAlign}
 */
org.apache.royale.jewel.beads.views.FormItemView.prototype.org_apache_royale_jewel_beads_views_FormItemView_textLabelAlign;


/**
 * @private
 * @type {org.apache.royale.jewel.Label}
 */
org.apache.royale.jewel.beads.views.FormItemView.prototype.org_apache_royale_jewel_beads_views_FormItemView_requiredLabel;


/**
 * 
 * @export
 * @param {string=} labelText
 * @return {org.apache.royale.jewel.Label}
 */
org.apache.royale.jewel.beads.views.FormItemView.prototype.createLabel = function(labelText) {
  labelText = typeof labelText !== 'undefined' ? labelText : null;
  var /** @type {org.apache.royale.jewel.Label} */ l = new org.apache.royale.jewel.Label();
  if (labelText != null)
    l.text = labelText;
  return l;
};


/**
 * @protected
 */
org.apache.royale.jewel.beads.views.FormItemView.prototype.setupContentAreaLayout = function() {
  var /** @type {org.apache.royale.jewel.beads.layouts.VerticalLayout} */ defaultContentAreaLayout = new org.apache.royale.jewel.beads.layouts.VerticalLayout();
  defaultContentAreaLayout.gap = 3;
  defaultContentAreaLayout.itemsHorizontalAlign = "itemsCenter";
  this.contentArea.addBead(defaultContentAreaLayout);
};


/**
 * @protected
 */
org.apache.royale.jewel.beads.views.FormItemView.prototype.setupLayout = function() {
  
};


/**
 * @private
 * @type {org.apache.royale.jewel.supportClasses.formitem.FormItemLayoutProxy}
 */
org.apache.royale.jewel.beads.views.FormItemView.prototype.org_apache_royale_jewel_beads_views_FormItemView__formItemLayoutProxy;


/**
 * @protected
 * @override
 */
org.apache.royale.jewel.beads.views.FormItemView.prototype.completeSetup = function() {
  org.apache.royale.jewel.beads.views.FormItemView.superClass_.completeSetup.apply(this);
  this.performLayout(null);
};


/**
 * @protected
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.views.FormItemView.prototype.handleSizeChange = function(event) {
  this.org_apache_royale_jewel_beads_views_FormItemView__contentArea.percentWidth = 100;
  this.performLayout(event);
};


/**
 * @private
 * @type {boolean}
 */
org.apache.royale.jewel.beads.views.FormItemView.prototype.org_apache_royale_jewel_beads_views_FormItemView_sawInitComplete;


/**
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.views.FormItemView.prototype.org_apache_royale_jewel_beads_views_FormItemView_handleChildrenAdded = function(event) {
  if (this.org_apache_royale_jewel_beads_views_FormItemView_sawInitComplete || ((this.formItem.isHeightSizedToContent() || !isNaN(this.formItem.explicitHeight)) && (this.formItem.isWidthSizedToContent() || !isNaN(this.formItem.explicitWidth)))) {
    this.org_apache_royale_jewel_beads_views_FormItemView__contentArea.dispatchEvent(new org.apache.royale.events.Event("layoutNeeded"));
    this.performLayout(event);
  }
};


org.apache.royale.jewel.beads.views.FormItemView.prototype.get__contentArea = function() {
  return this.org_apache_royale_jewel_beads_views_FormItemView__contentArea;
};


org.apache.royale.jewel.beads.views.FormItemView.prototype.set__contentArea = function(value) {
  this.org_apache_royale_jewel_beads_views_FormItemView__contentArea = value;
};


org.apache.royale.jewel.beads.views.FormItemView.prototype.set__strand = function(value) {
  org.apache.royale.jewel.beads.views.FormItemView.superClass_.set__strand.apply(this, [ value] );
  this.formItem = org.apache.royale.utils.Language.as(value, org.apache.royale.jewel.FormItem);
  this.org_apache_royale_jewel_beads_views_FormItemView_model = org.apache.royale.utils.Language.as(this._strand.getBeadByType(org.apache.royale.jewel.beads.models.FormItemModel), org.apache.royale.jewel.beads.models.FormItemModel);
  var /** @type {Array} */ beads = this.formItem.beads;
  var /** @type {org.apache.royale.core.IBeadLayout} */ transferLayoutBead;
  var /** @type {org.apache.royale.core.IViewport} */ transferViewportBead;
  if (this.formItem.beads != null) {
    for (var /** @type {number} */ i = this.formItem.beads.length - 1; i >= 0; i--) {
      if (org.apache.royale.utils.Language.is(this.formItem.beads[i], org.apache.royale.core.IBeadLayout)) {
        transferLayoutBead = this.formItem.beads[i];
        this.formItem.beads.splice(i, 1);
      } else if (org.apache.royale.utils.Language.is(this.formItem.beads[i], org.apache.royale.core.IViewport)) {
        transferViewportBead = this.formItem.beads[i];
        this.formItem.beads.splice(i, 1);
      }
    }
  }
  if (!this.org_apache_royale_jewel_beads_views_FormItemView__contentArea) {
    var /** @type {Object} */ cls = org.apache.royale.core.ValuesManager["valuesImpl"].getValue(this._strand, "iFormItemContentArea");
    this.org_apache_royale_jewel_beads_views_FormItemView__contentArea = new cls();
    if (transferLayoutBead)
      this.org_apache_royale_jewel_beads_views_FormItemView__contentArea.addBead(transferLayoutBead);
    else
      this.setupContentAreaLayout();
    if (transferViewportBead)
      this.org_apache_royale_jewel_beads_views_FormItemView__contentArea.addBead(transferViewportBead);
  }
  
  if (this.org_apache_royale_jewel_beads_views_FormItemView_textLabel == null) {
    this.org_apache_royale_jewel_beads_views_FormItemView_textLabel = this.createLabel(this.org_apache_royale_jewel_beads_views_FormItemView_model.text);
    this.org_apache_royale_jewel_beads_views_FormItemView_textLabel.multiline = true;
    this.org_apache_royale_jewel_beads_views_FormItemView_textLabel.className = "formlabel";
  }
  if (this.org_apache_royale_jewel_beads_views_FormItemView_textLabel != null && this.org_apache_royale_jewel_beads_views_FormItemView_textLabel.parent == null) {
    org.apache.royale.utils.Language.as(this._strand, org.apache.royale.core.IContainerBaseStrandChildrenHost).$addElement(this.org_apache_royale_jewel_beads_views_FormItemView_textLabel);
    this.org_apache_royale_jewel_beads_views_FormItemView_textLabelAlign = new org.apache.royale.jewel.beads.controls.TextAlign();
    this.org_apache_royale_jewel_beads_views_FormItemView_textLabelAlign.align = this.org_apache_royale_jewel_beads_views_FormItemView_model.labelAlign;
    this.org_apache_royale_jewel_beads_views_FormItemView_textLabel.addBead(this.org_apache_royale_jewel_beads_views_FormItemView_textLabelAlign);
  }
  if (this.org_apache_royale_jewel_beads_views_FormItemView_requiredLabel == null) {
    var /** @type {string} */ ast = this.org_apache_royale_jewel_beads_views_FormItemView_model.required ? "*" : "";
    this.org_apache_royale_jewel_beads_views_FormItemView_requiredLabel = this.createLabel(ast);
    this.org_apache_royale_jewel_beads_views_FormItemView_requiredLabel.className = "required";
  }
  if (this.org_apache_royale_jewel_beads_views_FormItemView_requiredLabel != null && this.org_apache_royale_jewel_beads_views_FormItemView_requiredLabel.parent == null) {
    org.apache.royale.utils.Language.as(this._strand, org.apache.royale.core.IContainerBaseStrandChildrenHost).$addElement(this.org_apache_royale_jewel_beads_views_FormItemView_requiredLabel);
  }
  if (this.contentArea.parent == null) {
    org.apache.royale.utils.Language.as(this._strand, org.apache.royale.core.IContainerBaseStrandChildrenHost).$addElement(this.contentArea);
  }
  this.setupLayout();
};


org.apache.royale.jewel.beads.views.FormItemView.prototype.get__contentView = function() {
  if (this.org_apache_royale_jewel_beads_views_FormItemView__formItemLayoutProxy == null) {
    this.org_apache_royale_jewel_beads_views_FormItemView__formItemLayoutProxy = new org.apache.royale.jewel.supportClasses.formitem.FormItemLayoutProxy(this._strand);
  }
  return this.org_apache_royale_jewel_beads_views_FormItemView__formItemLayoutProxy;
};


Object.defineProperties(org.apache.royale.jewel.beads.views.FormItemView.prototype, /** @lends {org.apache.royale.jewel.beads.views.FormItemView.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.UIBase} */
contentArea: {
get: org.apache.royale.jewel.beads.views.FormItemView.prototype.get__contentArea,
set: org.apache.royale.jewel.beads.views.FormItemView.prototype.set__contentArea},
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.jewel.beads.views.FormItemView.prototype.set__strand},
/**
  * @export
  * @type {org.apache.royale.core.ILayoutView} */
contentView: {
get: org.apache.royale.jewel.beads.views.FormItemView.prototype.get__contentView}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.beads.views.FormItemView.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'contentArea': { type: 'org.apache.royale.core.UIBase', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.beads.views.FormItemView'},
        'strand': { type: 'org.apache.royale.core.IStrand', access: 'writeonly', declaredBy: 'org.apache.royale.jewel.beads.views.FormItemView'},
        'contentView': { type: 'org.apache.royale.core.ILayoutView', access: 'readonly', declaredBy: 'org.apache.royale.jewel.beads.views.FormItemView'}
      };
    },
    methods: function () {
      return {
        'FormItemView': { type: '', declaredBy: 'org.apache.royale.jewel.beads.views.FormItemView'},
        'createLabel': { type: 'org.apache.royale.jewel.Label', declaredBy: 'org.apache.royale.jewel.beads.views.FormItemView', parameters: function () { return [  { index: 1, type: 'String', optional: true } ]; }}
      };
    }
  };
};