/*!
 * ${copyright}
 */

// Provides control sap.m.AssociativeOverflowToolbar.
sap.ui.define(['./OverflowToolbar', './OverflowToolbarRenderer', './Toolbar'],
	function (OverflowToolbar, OverflowToolbarRenderer, Toolbar) {
		"use strict";

		/**
		 * Constructor for a new AssociativeOverflowToolbar.
		 *
		 * @param {string} [sId] id for the new control, generated automatically if no id is given
		 * @param {object} [mSettings] initial settings for the new control
		 *
		 * @class
		 * AssociativeOverflowToolbar is a version of OverflowToolbar that uses an association in addition to the aggregation
		 * @extends sap.m.OverflowToolbar
		 *
		 * @author SAP SE
		 * @version ${version}
		 *
		 * @constructor
		 * @private
		 * @since 1.34
		 * @alias sap.m.AssociativeOverflowToolbar
		 */
		var AssociativeOverflowToolbar = OverflowToolbar.extend("sap.m.AssociativeOverflowToolbar", /** @lends sap.m.AssociativeOverflowToolbar.prototype */ {
			metadata: {
				associations: {
					/**
					 * The same as content, but provided in the form of an association
					 */
					content: {type: "sap.ui.core.Control", multiple: true, singularName: "content"}
				}
			},
			renderer: OverflowToolbarRenderer
		});

		AssociativeOverflowToolbar.prototype.getContent = function () {
			var associativeArrayWithIds = this.getAssociation("content") || [];
			return associativeArrayWithIds.map(function (controlId) {
				return sap.ui.getCore().byId(controlId);
			});
		};

		AssociativeOverflowToolbar.prototype.exit = function () {
			OverflowToolbar.prototype.exit.apply(this, arguments);
			return this._callToolbarMethod('destroyContent', [true]);
		};

		AssociativeOverflowToolbar.prototype.indexOfContent = function(oControl) {
			var controlIds = this.getAssociation("content") || [];
			return controlIds.indexOf(oControl.getId());
		};

		AssociativeOverflowToolbar.prototype._callToolbarMethod = function (sFuncName, aArguments) {
			switch (sFuncName) {
				case 'addContent':
					return this.addAssociation("content", aArguments[0]);
				case 'getContent':
					return this.getContent();
				case 'insertContent':
					//insertAggregation = function(sAggregationName, oObject, iIndex, bSuppressInvalidate)
					return this.addAssociation("content", aArguments[0], aArguments[3]);
				case 'removeContent':
					//removeAssociation = function(sAssociationName, vObject, bSuppressInvalidate)
					return sap.ui.getCore().byId(this.removeAssociation("content", aArguments[0], aArguments[1], aArguments[2])) || null;
				case 'destroyContent':
					var content = this.removeAllAssociation("content", aArguments[0]).map(function (controlId) {
						return sap.ui.getCore().byId(controlId);
					});
					content.forEach(function (control) {
						if (control) {
							control.destroy();
						}
					});
					return this;
				case 'removeAllContent':
					return this.removeAllAssociation("content", aArguments[0]).map(function (controlId) {
						return sap.ui.getCore().byId(controlId);
					});
				default:
					return Toolbar.prototype[sFuncName].apply(this, aArguments);
			}
		};

		return AssociativeOverflowToolbar;

	});

@@ -87,16 +87,32 @@
 define(%5B
+'sap/base/Log', 
 './Overf
@@ -178,16 +178,21 @@
 nction (
+Log, 
 Overflow
@@ -1477,32 +1477,773 @@
 );%0A%09%09%09%7D);%0A%09%09%7D;%0A%0A
+%09%09AssociativeOverflowToolbar.prototype.insertContent = function (oControl, iIndex) %7B%0A%09%09%09var sInsertedControlId = oControl.getId(),%0A%09%09%09%09aIds = this.getAssociation(%22content%22).filter(function (sId) %7B%0A%09%09%09%09%09return sId !== sInsertedControlId;%0A%09%09%09%09%7D);%0A%0A%09%09%09var i;%0A%09%09%09if (iIndex %3C 0) %7B%0A%09%09%09%09i = 0;%0A%09%09%09%7D else if (iIndex %3E aIds.length) %7B%0A%09%09%09%09i = aIds.length;%0A%09%09%09%7D else %7B%0A%09%09%09%09i = iIndex;%0A%09%09%09%7D%0A%09%09%09if (i !== iIndex) %7B%0A%09%09%09%09Log.warning(%22AssociativeOverflowToolbar.insertContent: index '%22 + iIndex + %22' out of range %5B0,%22 + aIds.length + %22%5D, forced to %22 + i);%0A%09%09%09%7D%0A%0A%09%09%09aIds.splice(i, 0, sInsertedControlId);%0A%0A%09%09%09this.removeAllAssociation(%22content%22);%0A%09%09%09aIds.forEach(function (sId) %7B%0A%09%09%09%09this.addAssociation(%22content%22, sId);%0A%09%09%09%7D, this);%0A%0A%09%09%09return this;%0A%09%09%7D;%0A%0A
 %09%09AssociativeOve
@@ -2890,138 +2890,34 @@
 %09%09%09%09
-//insertAggregation = function(sAggregationName, oObject, iIndex, bSuppressInvalidate)%0A%09%09%09%09%09return this.addAssociation(%22c
+return this.insertC
 ontent
-%22, 
+(
 aArg
@@ -2938,17 +2938,17 @@
 guments%5B
-3
+1
 %5D);%0A%09%09%09%09
@@ -2973,92 +2973,8 @@
 t':%0A
-%09%09%09%09%09//removeAssociation = function(sAssociationName, vObject, bSuppressInvalidate)%0A
 %09%09%09%09

add insertContent method