Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / AbstractPlugin.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.AbstractPlugin
17  * @extends Object
18  *
19  * <p>The AbstractPlugin class is the base class from which user-implemented plugins should inherit.</p>
20  * <p>This class defines the essential API of plugins as used by Components by defining the following methods:</p>
21  * <ul>
22  * <li><code>init</code> : The plugin initialization method which the owning Component calls at Component initialization
23  * time.<div class="sub-desc"><p>The Component passes itself as the sole parameter.</p><p>Subclasses should set up bidirectional
24  * links between the plugin and its client Component here.</p></div></li>
25  * <li><code>destroy</code> : The plugin cleanup method which the owning Component calls at Component destruction time.<div class="sub-desc">Use
26  * this method to break links between the plugin and the Component and to free any allocated resources.</div></li>
27  * <li><code>enable</code> : The base implementation just sets the plugin's <code>disabled</code> flag to <code>false</code><div class="sub-desc"></div></li>
28  * <li><code>disable</code> : The base implementation just sets the plugin's <code>disabled</code> flag to <code>true</code><div class="sub-desc"></div></li>
29  * </ul>
30  */
31 Ext.define('Ext.AbstractPlugin', {
32     disabled: false,
33
34     constructor: function(config) {
35         //<debug>
36         if (!config.cmp && Ext.global.console) {
37             Ext.global.console.warn("Attempted to attach a plugin ");
38         }
39         //</debug>
40         Ext.apply(this, config);
41     },
42
43     getCmp: function() {
44         return this.cmp;
45     },
46
47     /**
48      * <p>The init method is invoked after {@link Ext.Component#initComponent initComponent} has been run for the client Component.</p>
49      * <p>The supplied implementation is empty. Subclasses should perform plugin initialization, and set up bidirectional
50      * links between the plugin and its client Component in their own implementation of this method.</p>
51      * @param {Component} client The client Component which owns this plugin.
52      * @method
53      */
54     init: Ext.emptyFn,
55
56     /**
57      * <p>The destroy method is invoked by the owning Component at the time the Component is being destroyed.</p>
58      * <p>The supplied implementation is empty. Subclasses should perform plugin cleanup in their own implementation of this method.</p>
59      * @method
60      */
61     destroy: Ext.emptyFn,
62
63     /**
64      * <p>The base implementation just sets the plugin's <code>disabled</code> flag to <code>false</code></p>
65      * <p>Plugin subclasses which need more complex processing may implement an overriding implementation.</p>
66      */
67     enable: function() {
68         this.disabled = false;
69     },
70
71     /**
72      * <p>The base implementation just sets the plugin's <code>disabled</code> flag to <code>true</code></p>
73      * <p>Plugin subclasses which need more complex processing may implement an overriding implementation.</p>
74      */
75     disable: function() {
76         this.disabled = true;
77     }
78 });