/**
 * This singleton is used to manager multiple instances of popups and their
 * state.
 */
qx.Class.define("nx4.webwidgets.core.PopupManager",
{
  type : "singleton",
  extend : qx.core.Object,



  /*
  *****************************************************************************
     CONSTRUCTOR
  *****************************************************************************
  */

  construct : function()
  {
    this.base(arguments);

    // Create data structure
    this.__objects = {};
  },




  /*
  *****************************************************************************
     MEMBERS
  *****************************************************************************
  */

  members :
  {
    __objects : null,


    /**
     * Registers a visible popup.
     *
     * @param obj {qx.ui.popup.Popup} The popup to register
     */
    add : function(obj)
    {
      this.__objects[obj.$$hash] = obj;
    },


    /**
     * Removes a popup from the registry
     *
     * @param obj {qx.ui.popup.Popup} The popup which was excluded
     */
    remove : function(obj)
    {
      var reg = this.__objects;
      if (reg)
      {
        delete reg[obj.$$hash];
      }
    },


    /**
     * Excludes all currently open popups.
     */
    hideAll : function()
    {
      var reg = this.__objects;
      if (reg)
      {
        for (var hash in reg)
          reg[hash].hide();
      }
    },

    getFromId : function(id)
    {
      var reg = this.__objects;
      if (reg)
        for (var hash in reg)
          if(reg[hash].getId() == id)
            return reg[hash];
    }
  },

  /*
  *****************************************************************************
     DESTRUCTOR
  *****************************************************************************
  */

  destruct : function()
  {
    this._disposeMap("__objects");
  }
});

