/**
 * Generated by Apache Royale Compiler from org\apache\royale\html\beads\controllers\DateFieldMouseController.as
 * org.apache.royale.html.beads.controllers.DateFieldMouseController
 *
 * @fileoverview
 *
 * @suppress {checkTypes|accessControls}
 */

goog.provide('org.apache.royale.html.beads.controllers.DateFieldMouseController');

goog.require('org.apache.royale.core.IDateChooserModel');
goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.core.IUIBase');
goog.require('org.apache.royale.core.UIBase');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.events.IEventDispatcher');
goog.require('org.apache.royale.events.MouseEvent');
goog.require('org.apache.royale.html.beads.DateFieldView');
goog.require('org.apache.royale.utils.Timer');
goog.require('org.apache.royale.utils.UIUtils');
goog.require('org.apache.royale.core.IBeadController');
goog.require('org.apache.royale.utils.Language');



/**
 *  constructor.
 *  
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.0
 * @constructor
 * @implements {org.apache.royale.core.IBeadController}
 */
org.apache.royale.html.beads.controllers.DateFieldMouseController = function() {
};


/**
 * Prevent renaming of class. Needed for reflection.
 */
goog.exportSymbol('org.apache.royale.html.beads.controllers.DateFieldMouseController', org.apache.royale.html.beads.controllers.DateFieldMouseController);


/**
 * @private
 * @type {org.apache.royale.core.IStrand}
 */
org.apache.royale.html.beads.controllers.DateFieldMouseController.prototype.org_apache_royale_html_beads_controllers_DateFieldMouseController__strand;


/**
 * @asprivate
 * @private
 * @param {org.apache.royale.events.MouseEvent} event
 */
org.apache.royale.html.beads.controllers.DateFieldMouseController.prototype.org_apache_royale_html_beads_controllers_DateFieldMouseController_clickHandler = function(event) {
  event.stopImmediatePropagation();
  var /** @type {org.apache.royale.html.beads.DateFieldView} */ viewBead = org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_controllers_DateFieldMouseController__strand.getBeadByType(org.apache.royale.html.beads.DateFieldView), org.apache.royale.html.beads.DateFieldView);
  viewBead.popUpVisible = true;
  org.apache.royale.utils.Language.as(viewBead.popUp, org.apache.royale.events.IEventDispatcher, true).addEventListener("change", org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_controllers_DateFieldMouseController_changeHandler, this, 'changeHandler'));
  this.org_apache_royale_html_beads_controllers_DateFieldMouseController_removeDismissHandler();
  var /** @type {org.apache.royale.utils.Timer} */ t = new org.apache.royale.utils.Timer(0.25, 1);
  t.addEventListener("timer", org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_controllers_DateFieldMouseController_addDismissHandler, this, 'addDismissHandler'));
  t.start();
};


/**
 * @asprivate
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.html.beads.controllers.DateFieldMouseController.prototype.org_apache_royale_html_beads_controllers_DateFieldMouseController_addDismissHandler = function(event) {
  var /** @type {org.apache.royale.core.UIBase} */ host = org.apache.royale.utils.Language.as(org.apache.royale.utils.UIUtils.findPopUpHost(org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_controllers_DateFieldMouseController__strand, org.apache.royale.core.UIBase)), org.apache.royale.core.UIBase);
  if (host) {
    host.addEventListener("click", org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_controllers_DateFieldMouseController_dismissHandler, this, 'dismissHandler'));
  }
};


/**
 * @asprivate
 * @private
 */
org.apache.royale.html.beads.controllers.DateFieldMouseController.prototype.org_apache_royale_html_beads_controllers_DateFieldMouseController_removeDismissHandler = function() {
  var /** @type {org.apache.royale.core.UIBase} */ host = org.apache.royale.utils.Language.as(org.apache.royale.utils.UIUtils.findPopUpHost(org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_controllers_DateFieldMouseController__strand, org.apache.royale.core.UIBase)), org.apache.royale.core.UIBase);
  if (host) {
    host.removeEventListener("click", org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_controllers_DateFieldMouseController_dismissHandler, this, 'dismissHandler'));
  }
};


/**
 * @asprivate
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.html.beads.controllers.DateFieldMouseController.prototype.org_apache_royale_html_beads_controllers_DateFieldMouseController_changeHandler = function(event) {
  event.stopImmediatePropagation();
  var /** @type {org.apache.royale.html.beads.DateFieldView} */ viewBead = org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_controllers_DateFieldMouseController__strand.getBeadByType(org.apache.royale.html.beads.DateFieldView), org.apache.royale.html.beads.DateFieldView);
  var /** @type {org.apache.royale.core.IDateChooserModel} */ model = org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_controllers_DateFieldMouseController__strand.getBeadByType(org.apache.royale.core.IDateChooserModel), org.apache.royale.core.IDateChooserModel);
  model.selectedDate = org.apache.royale.utils.Language.as(viewBead.popUp.getBeadByType(org.apache.royale.core.IDateChooserModel), org.apache.royale.core.IDateChooserModel, true).selectedDate;
  viewBead.popUpVisible = false;
  org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_controllers_DateFieldMouseController__strand, org.apache.royale.events.IEventDispatcher, true).dispatchEvent(new org.apache.royale.events.Event("change"));
  this.org_apache_royale_html_beads_controllers_DateFieldMouseController_removeDismissHandler();
};


/**
 * @asprivate
 * @private
 * @param {org.apache.royale.events.MouseEvent} event
 */
org.apache.royale.html.beads.controllers.DateFieldMouseController.prototype.org_apache_royale_html_beads_controllers_DateFieldMouseController_dismissHandler = function(event) {
  var /** @type {org.apache.royale.html.beads.DateFieldView} */ viewBead = org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_controllers_DateFieldMouseController__strand.getBeadByType(org.apache.royale.html.beads.DateFieldView), org.apache.royale.html.beads.DateFieldView);
  var /** @type {org.apache.royale.core.IUIBase} */ popup = org.apache.royale.utils.Language.as(viewBead.popUp, org.apache.royale.core.IUIBase, true);
  
  var /** @type {org.apache.royale.core.IUIBase} */ before = org.apache.royale.utils.Language.as(event.target, org.apache.royale.core.IUIBase);
  if (before) {
    while (before != null) {
      if (before == popup)
        return;
      before = org.apache.royale.utils.Language.as(before.parent, org.apache.royale.core.IUIBase);
    }
  }
  viewBead.popUpVisible = false;
  this.org_apache_royale_html_beads_controllers_DateFieldMouseController_removeDismissHandler();
};


org.apache.royale.html.beads.controllers.DateFieldMouseController.prototype.set__strand = function(value) {
  this.org_apache_royale_html_beads_controllers_DateFieldMouseController__strand = value;
  var /** @type {org.apache.royale.html.beads.DateFieldView} */ viewBead = org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_controllers_DateFieldMouseController__strand.getBeadByType(org.apache.royale.html.beads.DateFieldView), org.apache.royale.html.beads.DateFieldView);
  org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_controllers_DateFieldMouseController__strand, org.apache.royale.events.IEventDispatcher, true).addEventListener("click", org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_controllers_DateFieldMouseController_clickHandler, this, 'clickHandler'));
};


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


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.html.beads.controllers.DateFieldMouseController.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.html.beads.controllers.DateFieldMouseController'}
      };
    },
    methods: function () {
      return {
        'DateFieldMouseController': { type: '', declaredBy: 'org.apache.royale.html.beads.controllers.DateFieldMouseController'}
      };
    }
  };
};