commit extjs-2.2.1
[extjs.git] / source / widgets / menu / Adapter.js
1 /*\r
2  * Ext JS Library 2.2.1\r
3  * Copyright(c) 2006-2009, Ext JS, LLC.\r
4  * licensing@extjs.com\r
5  * \r
6  * http://extjs.com/license\r
7  */\r
8 \r
9 /**\r
10  * @class Ext.menu.Adapter\r
11  * @extends Ext.menu.BaseItem\r
12  * A base utility class that adapts a non-menu component so that it can be wrapped by a menu item and added to a menu.\r
13  * It provides basic rendering, activation management and enable/disable logic required to work in menus.\r
14  * @constructor\r
15  * Creates a new Adapter\r
16  * @param {Ext.Component} component The component being adapted to render into a menu\r
17  * @param {Object} config Configuration options\r
18  */\r
19 Ext.menu.Adapter = function(component, config){\r
20     Ext.menu.Adapter.superclass.constructor.call(this, config);\r
21     this.component = component;\r
22 };\r
23 Ext.extend(Ext.menu.Adapter, Ext.menu.BaseItem, {\r
24     // private\r
25     canActivate : true,\r
26 \r
27     // private\r
28     onRender : function(container, position){\r
29         this.component.render(container);\r
30         this.el = this.component.getEl();\r
31     },\r
32 \r
33     // private\r
34     activate : function(){\r
35         if(this.disabled){\r
36             return false;\r
37         }\r
38         this.component.focus();\r
39         this.fireEvent("activate", this);\r
40         return true;\r
41     },\r
42 \r
43     // private\r
44     deactivate : function(){\r
45         this.fireEvent("deactivate", this);\r
46     },\r
47 \r
48     // private\r
49     disable : function(){\r
50         this.component.disable();\r
51         Ext.menu.Adapter.superclass.disable.call(this);\r
52     },\r
53 \r
54     // private\r
55     enable : function(){\r
56         this.component.enable();\r
57         Ext.menu.Adapter.superclass.enable.call(this);\r
58     }\r
59 });