3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.com/license
8 * @class Ext.AbstractManager
10 * Base Manager class - extended by ComponentMgr and PluginMgr
12 Ext.AbstractManager = Ext.extend(Object, {
15 constructor: function(config) {
16 Ext.apply(this, config || {});
19 * Contains all of the items currently managed
21 * @type Ext.util.MixedCollection
23 this.all = new Ext.util.MixedCollection();
29 * Returns a component by {@link Ext.Component#id id}.
30 * For additional details see {@link Ext.util.MixedCollection#get}.
31 * @param {String} id The component {@link Ext.Component#id id}
32 * @return Ext.Component The Component, <code>undefined</code> if not found, or <code>null</code> if a
36 return this.all.get(id);
40 * Registers an item to be managed
41 * @param {Mixed} item The item to register
43 register: function(item) {
48 * Unregisters a component by removing it from this manager
49 * @param {Mixed} item The item to unregister
51 unregister: function(item) {
52 this.all.remove(item);
56 * <p>Registers a new Component constructor, keyed by a new
57 * {@link Ext.Component#xtype}.</p>
58 * <p>Use this method (or its alias {@link Ext#reg Ext.reg}) to register new
59 * subclasses of {@link Ext.Component} so that lazy instantiation may be used when specifying
61 * see {@link Ext.Container#items}</p>
62 * @param {String} xtype The mnemonic string by which the Component class may be looked up.
63 * @param {Constructor} cls The new Component class.
65 registerType : function(type, cls){
66 this.types[type] = cls;
67 cls[this.typeName] = type;
71 * Checks if a Component type is registered.
72 * @param {Ext.Component} xtype The mnemonic string by which the Component class may be looked up
73 * @return {Boolean} Whether the type is registered.
75 isRegistered : function(type){
76 return this.types[type] !== undefined;
80 * Creates and returns an instance of whatever this manager manages, based on the supplied type and config object
81 * @param {Object} config The config object
82 * @param {String} defaultType If no type is discovered in the config object, we fall back to this type
83 * @return {Mixed} The instance of whatever this manager is managing
85 create: function(config, defaultType) {
86 var type = config[this.typeName] || config.type || defaultType,
87 Constructor = this.types[type];
89 if (Constructor == undefined) {
90 throw new Error(String.format("The '{0}' type has not been registered with this manager", type));
93 return new Constructor(config);
97 * Registers a function that will be called when a Component with the specified id is added to the manager. This will happen on instantiation.
98 * @param {String} id The component {@link Ext.Component#id id}
99 * @param {Function} fn The callback function
100 * @param {Object} scope The scope (<code>this</code> reference) in which the callback is executed. Defaults to the Component.
102 onAvailable : function(id, fn, scope){
105 all.on("add", function(index, o){
107 fn.call(scope || o, o);
108 all.un("add", fn, scope);