Upgrade to ExtJS 3.3.1 - Released 11/30/2010
[extjs.git] / docs / source / AbstractManager.html
1 <html>
2 <head>
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
4   <title>The source code</title>
5     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 </head>
8 <body  onload="prettyPrint();">
9     <pre class="prettyprint lang-js">/*!
10  * Ext JS Library 3.3.1
11  * Copyright(c) 2006-2010 Sencha Inc.
12  * licensing@sencha.com
13  * http://www.sencha.com/license
14  */
15 <div id="cls-Ext.AbstractManager"></div>/**
16  * @class Ext.AbstractManager
17  * @extends Object
18  * Base Manager class - extended by ComponentMgr and PluginMgr
19  */
20 Ext.AbstractManager = Ext.extend(Object, {
21     typeName: 'type',
22     
23     constructor: function(config) {
24         Ext.apply(this, config || {});
25         
26         <div id="prop-Ext.AbstractManager-all"></div>/**
27          * Contains all of the items currently managed
28          * @property all
29          * @type Ext.util.MixedCollection
30          */
31         this.all = new Ext.util.MixedCollection();
32         
33         this.types = {};
34     },
35     
36     <div id="method-Ext.AbstractManager-get"></div>/**
37      * Returns a component by {@link Ext.Component#id id}.
38      * For additional details see {@link Ext.util.MixedCollection#get}.
39      * @param {String} id The component {@link Ext.Component#id id}
40      * @return Ext.Component The Component, <code>undefined</code> if not found, or <code>null</code> if a
41      * Class was found.
42      */
43     get : function(id){
44         return this.all.get(id);
45     },
46     
47     <div id="method-Ext.AbstractManager-register"></div>/**
48      * Registers an item to be managed
49      * @param {Mixed} item The item to register
50      */
51     register: function(item) {
52         this.all.add(item);
53     },
54     
55     <div id="method-Ext.AbstractManager-unregister"></div>/**
56      * Unregisters a component by removing it from this manager
57      * @param {Mixed} item The item to unregister
58      */
59     unregister: function(item) {
60         this.all.remove(item);        
61     },
62     
63     <div id="method-Ext.AbstractManager-registerType"></div>/**
64      * <p>Registers a new Component constructor, keyed by a new
65      * {@link Ext.Component#xtype}.</p>
66      * <p>Use this method (or its alias {@link Ext#reg Ext.reg}) to register new
67      * subclasses of {@link Ext.Component} so that lazy instantiation may be used when specifying
68      * child Components.
69      * see {@link Ext.Container#items}</p>
70      * @param {String} xtype The mnemonic string by which the Component class may be looked up.
71      * @param {Constructor} cls The new Component class.
72      */
73     registerType : function(type, cls){
74         this.types[type] = cls;
75         cls[this.typeName] = type;
76     },
77     
78     <div id="method-Ext.AbstractManager-isRegistered"></div>/**
79      * Checks if a Component type is registered.
80      * @param {Ext.Component} xtype The mnemonic string by which the Component class may be looked up
81      * @return {Boolean} Whether the type is registered.
82      */
83     isRegistered : function(type){
84         return this.types[type] !== undefined;    
85     },
86     
87     <div id="method-Ext.AbstractManager-create"></div>/**
88      * Creates and returns an instance of whatever this manager manages, based on the supplied type and config object
89      * @param {Object} config The config object
90      * @param {String} defaultType If no type is discovered in the config object, we fall back to this type
91      * @return {Mixed} The instance of whatever this manager is managing
92      */
93     create: function(config, defaultType) {
94         var type        = config[this.typeName] || config.type || defaultType,
95             Constructor = this.types[type];
96         
97         if (Constructor == undefined) {
98             throw new Error(String.format("The '{0}' type has not been registered with this manager", type));
99         }
100         
101         return new Constructor(config);
102     },
103     
104     <div id="method-Ext.AbstractManager-onAvailable"></div>/**
105      * Registers a function that will be called when a Component with the specified id is added to the manager. This will happen on instantiation.
106      * @param {String} id The component {@link Ext.Component#id id}
107      * @param {Function} fn The callback function
108      * @param {Object} scope The scope (<code>this</code> reference) in which the callback is executed. Defaults to the Component.
109      */
110     onAvailable : function(id, fn, scope){
111         var all = this.all;
112         
113         all.on("add", function(index, o){
114             if (o.id == id) {
115                 fn.call(scope || o, o);
116                 all.un("add", fn, scope);
117             }
118         });
119     }
120 });</pre>    
121 </body>
122 </html>