/*!
 * SAP UI development toolkit for HTML5 (SAPUI5/OpenUI5)
 * (c) Copyright 2009-2015 SAP SE or an SAP affiliate company.
 * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
 */
sap.ui.define(['jquery.sap.global'],function(q){"use strict";var C={};function t(i,I){if(!i){return null;}var o=sap.ui.getCore().byId(i);if(o&&I){o.invalidate();}return o;}function r(l,d){var s=l.getId();var o=l.__sLabeledControl;var n=d?null:l.getLabelForRendering();if(o==n){return;}if(!d){l.invalidate();}if(n){l.__sLabeledControl=n;}else{delete l.__sLabeledControl;}var a;if(o){a=C[o];if(a){a=q.grep(a,function(b){return b!=s;});if(a.length){C[o]=a;}else{delete C[o];}}}if(n){a=C[n]||[];a.push(s);C[n]=a;}t(o,true);t(n,true);}function c(o){if(!o){throw new Error("sap.ui.core.LabelEnablement cannot enrich null");}var m=o.getMetadata();if(!m.isInstanceOf("sap.ui.core.Label")){throw new Error("sap.ui.core.LabelEnablement only supports Controls with interface sap.ui.core.Label");}var l=m.getAssociation("labelFor");if(!l||l.multiple){throw new Error("sap.ui.core.LabelEnablement only supports Controls with a to-1 association 'labelFor'");}}var L={};L.writeLabelForAttribute=function(R,l){if(!l||!l.getLabelForRendering){return;}var s=l.getLabelForRendering();if(!s){return;}var o=t(s);if(o&&o.getIdForLabel){s=o.getIdForLabel();}if(s){R.writeAttributeEscaped("for",s);}};L.getReferencingLabels=function(e){var i=e?e.getId():null;if(!i){return[];}return C[i]||[];};L.enrich=function(o){c(o);o.__orig_setLabelFor=o.setLabelFor;o.setLabelFor=function(i){var a=this.__orig_setLabelFor.apply(this,arguments);r(this);return a;};o.__orig_exit=o.exit;o.exit=function(){this._sAlternativeId=null;r(this,true);if(o.__orig_exit){o.__orig_exit.apply(this,arguments);}};o.setAlternativeLabelFor=function(i){if(i instanceof sap.ui.base.ManagedObject){i=i.getId();}else if(i!=null&&typeof i!=="string"){return this;}this._sAlternativeId=i;r(this);return this;};o.getLabelForRendering=function(){return this.getLabelFor()||this._sAlternativeId;};};return L;},true);
