home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / AIMP2 / aimp_2.61.583.exe / $TEMP / YandexPackSetup.msi / filD41E50A3CAB5C3956B107CFACBF41AF3 < prev    next >
Text File  |  2010-07-12  |  8KB  |  229 lines

  1. XB.WindowEngine = function XBWndEngine_constructor(overlayController) {
  2.     this._eid = "WndEngine" + XB._base.genWindowEngineID();
  3.     this._logger = overlayController.application.core.Log4Moz.repository.getLogger(XB._base.loggersRoot + "." + this._eid);
  4.     this._widgetsMap = {__proto__: null};
  5.     this._overlayController = overlayController;
  6. };
  7.  
  8. XB.WindowEngine.prototype = {
  9.     constructor: XB.WindowEngine,
  10.     
  11.     navigate: function XBWndEngine_navigate(url, target, windowWidth, windowHeight, yandexAction, widgetProto) {
  12.         this._overlayController.navigate(url, target, windowWidth, windowHeight, yandexAction, widgetProto);
  13.     },
  14.     
  15.     setupWidget: function XBWndEngine_setupWidget(widgetInstance) {
  16.         this._overlayController.setupWidget(widgetInstance.id);
  17.     },
  18.     
  19.     addWidget: function XBWndEngine_addWidget(protoID, settingsMap, relativeTo, placeAfter) {
  20.         let widgetItem = this._overlayController.addWidgetItem(protoID, settingsMap, relativeTo, placeAfter);
  21.         if (widgetItem && "instanceID" in widgetItem)
  22.             this.setupWidget(widgetItem);
  23.     },
  24.     
  25.     removeWidget: function XBWndEngine_removeWidget(WIID) {
  26.         this._overlayController.removeItem(WIID);
  27.     },
  28.     
  29.     clear: function XBWndEngine_clear() {
  30.         for each (let widgetPair in this._widgetsMap) {
  31.             try {
  32.                 widgetPair.widget.finalize();
  33.             }
  34.             catch (e) {}
  35.         }
  36.         this._widgetsMap = {__proto__: null};
  37.         this._overlayController = null;
  38.     },
  39.     
  40.     hasWidget: function XBWndEngine_hasWidget(widgetIID) {
  41.         return (widgetIID in this._widgetsMap);
  42.     },
  43.     
  44.     createWidget: function XBWndEngine_createWidget(protoID, instID, settings, boundToolbarElement) {
  45.         if (!instID)
  46.             throw new Error(this._consts.ERR_INSTID_REQUIRED);
  47.         
  48.         var widget;
  49.         
  50.         if (this.hasWidget(instID)) {
  51.             this._logger.warn("Widget with this ID (" + instID + ") already exists. Will return the old one.");
  52.             widget = this.getWidget(instID);
  53.             if (settings) {
  54.                 for (let settingName in settings) {
  55.                     widget.applySetting(settingName, settings[settingName]);
  56.                 }
  57.             }
  58.         } else {
  59.             widget = this._overlayController.application.widgetLibrary.getWidgetProto(protoID)
  60.                 .createInstance(instID, this, settings);
  61.             this._widgetsMap[instID] = {widget: widget, toolbarElement: boundToolbarElement};
  62.         }
  63.         
  64.         try {
  65.             this._overlayController.guiBuilder.build(widget.prototype.srcElement, boundToolbarElement, instID);
  66.         }
  67.         catch (e) {
  68.             this._logger.error("Could not build toolbar element content. " +
  69.                                this._overlayController.application.core.Lib.misc.formatError(e));
  70.             this._logger.debug(e.stack);
  71.         }
  72.         
  73.         return widget;
  74.     },
  75.     
  76.     destroyWidget: function XBWndEngine_destroyWidget(instID, eraseSettingsIfNeeded) {
  77.         this._logger.debug("Widget " + instID + " destruction requested");
  78.         var widgetPair = this._getWidgetPair(instID);
  79.         
  80.         try {
  81.             let toolbarElement = widgetPair.toolbarElement;
  82.             toolbarElement.constructed = false;
  83.             this._overlayController.guiBuilder.cleanNode(toolbarElement);
  84.         }
  85.         catch (e) {
  86.             this._logger.error("Could not clean widget toolbar element. " +
  87.                                this._overlayController.application.core.Lib.misc.formatError(e));
  88.         }
  89.         
  90.         try {
  91.             let widget = widgetPair.widget;
  92.             if (eraseSettingsIfNeeded) {
  93.                 let widgetProto = widget.prototype;
  94.                 if (widgetProto.isUnique && widgetProto.spawnedWidgets.length == 1) {
  95.                     for each (let setting in widget.settings) {
  96.                         try {
  97.                             setting.node.erase();
  98.                         }
  99.                         catch (e) {
  100.                             this._logger.error("Could not erase widget setting. " +
  101.                                                this._overlayController.application.core.Lib.misc.formatError(e));
  102.                         }
  103.                     }
  104.                 }
  105.             }
  106.             widget.finalize();
  107.         }
  108.         finally {
  109.             delete this._widgetsMap[instID];
  110.         }
  111.     },
  112.     
  113.     getWidget: function XBWndEngine_getWidget(widgetIID) {
  114.         return this._getWidgetPair(widgetIID).widget;
  115.     },
  116.     
  117.     getToolbarElement: function XBWndEngine_getToolbarElement(widgetIID) {
  118.         return this._getWidgetPair(widgetIID).toolbarElement;
  119.     },
  120.     
  121.     getValueAsString: function XBWndEngine_getValueAsString(widgetIID, valUID) {
  122.         return this._safeGetStrNodeValue(this._getCalcNode(widgetIID, valUID));
  123.     },
  124.     
  125.     getValue: function XBWndEngine_getValue(widgetIID, valUID) {
  126.         return this._getCalcNode(widgetIID, valUID).getValue(this);
  127.     },
  128.     
  129.     perform: function XBWndEngine_perform(widgetIID, valUID, eventInfo) {
  130.         try {
  131.             var procNode = this._getCalcNode(widgetIID, valUID);
  132.         }
  133.         catch (e) {
  134.             throw new XB.WindowEngine.ENoActionHandler(e.message);
  135.         }
  136.         if ( !(procNode instanceof XB._calcNodes.ProcNode) )
  137.             throw new TypeError(XB._base.consts.ERR_PROC_NODE_EXPECTED);
  138.         
  139.         procNode.perform(eventInfo);
  140.     },
  141.     
  142.     valueNotNeeded: function XBWndEngine_valueNotNeeded(widgetIID, valUID) {
  143.         this._getCalcNode(widgetIID, valUID).unsubscribe(this);
  144.     },
  145.     
  146.     freeze: function XBWndEngine_freeze() {
  147.         
  148.     },
  149.     
  150.     melt: function XBWndEngine_melt(changedNode) {
  151.         if (!changedNode) return;
  152.         try {
  153.             this._notifyUIBuilder(changedNode);
  154.         }
  155.         catch (e) {
  156.             this._logger.error("Failed notifying UI builder. " + misc.formatError(e));
  157.             if (e.stack)
  158.                 this._logger.debug(e.stack);
  159.         }
  160.     },
  161.     
  162.     get effectiveID() {
  163.         return this.id;
  164.     },
  165.     
  166.     get id() {
  167.         return this._eid;
  168.     },
  169.     
  170.     get logger() {
  171.         return this._logger;
  172.     },
  173.     
  174.     _consts: {
  175.         ERR_INSTID_REQUIRED: "Instance ID required",
  176.         ERR_XF_NOT_FOUND: "Requested value not found",
  177.         ERR_WIDGET_NOT_FOUND: "Couldn't find widget with this ID",
  178.         ERR_WI_EXPECTED: "Widgets info array expected",
  179.         ERR_CANT_CONSTRUCT_WIDGET: "Failed creating widget"
  180.     },
  181.     _logger: null,
  182.     _eid: undefined,
  183.     _overlayController: null,
  184.     _widgetsMap: null,
  185.     
  186.     _getHumanReadableID: function XBWndEngine_getHumanReadableID() {
  187.         return this._eid;
  188.     },
  189.     
  190.     _getWidgetPair: function XBWndEngine_getWidgetPair(widgetIID) {
  191.         let widgetPair = this._widgetsMap[widgetIID];
  192.         if (!widgetPair)
  193.             throw new Error(this._consts.ERR_WIDGET_NOT_FOUND + " (" + widgetIID + ")");
  194.         return widgetPair;
  195.     },
  196.     
  197.     _getCalcNode: function XBWndEngine__getCalcNode(widgetIID, valUID) {
  198.         var calcNode =  this.getWidget(widgetIID).findReference(valUID);
  199.         if (!calcNode)
  200.             throw new Error(this._consts.ERR_XF_NOT_FOUND + " (" + [widgetIID, valUID] + ")");
  201.         return calcNode;
  202.     },
  203.     
  204.     _safeGetStrNodeValue: function XBWndEngine__safeGetStrNodeValue(node) {
  205.         var strVal = "";
  206.         try {
  207.             strVal = XB._base.runtime.xToString(node.getValue(this));
  208.         }
  209.         catch (e) {
  210.             this._logger.error("Converting value to string failed. " + misc.formatError(e) + ". Will return empty string.");
  211.         }
  212.         return strVal;
  213.     },
  214.     
  215.     _notifyUIBuilder: function XBWndEngine__notifyUIBuilder(changedNode) {
  216.         this._logger.trace("Notifying UI builder");
  217.         this._overlayController.guiBuilder.handleDataChange(changedNode.parentWidget.id,
  218.                                                             changedNode.baseID,
  219.                                                             changedNode.getValue(this));
  220.     }
  221. };
  222.  
  223. XB.WindowEngine.ENoActionHandler = function XBWE_ENoActionHandler(msg) {
  224.     this.name = "No action handler error";
  225.     this.message = msg;
  226. };
  227.  
  228. XB.WindowEngine.ENoActionHandler.prototype = new Error();
  229.