]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/slc/web/event/Command.js
Fixed IE build version problems, added icons on download mime types
[gpl/argeo-slc.git] / org.argeo.slc.webapp / src / main / webapp / source / class / org / argeo / slc / web / event / Command.js
1 qx.Class.define("org.argeo.slc.web.event.Command",
2 {
3 extend : qx.event.Command,
4
5 properties : {
6 id : {init:""},
7 label : {init:""},
8 icon : {init:""},
9 menu : {
10 nullable: true,
11 event : "changeMenu"
12 },
13 menuCallback : {nullable:true},
14 menuContext : {nullable:true}
15 },
16
17 construct : function(id, label, icon, shortcut){
18 this.base(arguments, shortcut);
19 this.setId(id);
20 this.setLabel(label);
21 this.setIcon(icon);
22 },
23
24 members :
25 {
26 getMenuButton : function(){
27 var button = new qx.ui.menu.Button(
28 this.getLabel(),
29 this.getIcon(),
30 this,
31 this.getMenu()
32 );
33 this.addTooltip(button);
34 if(this.getMenu()){
35 this.addListener("changeMenu", function(event){
36 this.setMenu(event.getData());
37 }, button);
38 }
39 return button;
40 },
41
42 getToolbarButton : function(){
43 var button;
44 if(this.getMenu()){
45 button = new qx.ui.toolbar.MenuButton(
46 this.getLabel(),
47 this.getIcon(),
48 this.getMenuClone()
49 );
50 this.addListener("changeMenu", function(event){
51 button.setMenu(this.getMenuClone());
52 }, this);
53 this.addListener("changeEnabled", function(e){
54 this.setEnabled(e.getData());
55 }, button);
56 button.setEnabled(this.getEnabled());
57 }else{
58 button = new qx.ui.toolbar.Button(
59 this.getLabel(),
60 this.getIcon(),
61 this
62 );
63 }
64 this.addTooltip(button);
65 return button;
66 },
67
68 getMenuClone : function(){
69 if(!this.menuClone){
70 this.menuClone = new qx.ui.menu.Menu();
71 this.menuClone.setMinWidth(110);
72 }
73 return this.menuClone;
74 },
75
76 clearMenus : function(){
77 this.getMenu().removeAll();
78 this.getMenuClone().removeAll();
79 },
80
81 addSubMenuButton : function(label, icon, commandId, menu){
82 var button = new qx.ui.menu.Button(label, icon);
83 button.setUserData("commandId", commandId);
84 button.addListener("execute", this.executeSubMenuCallback, this);
85 if(menu){
86 menu.add(button);
87 }else{
88 this.getMenu().add(button);
89 this.addSubMenuButton(label, icon, commandId, this.menuClone);
90 }
91 },
92
93 executeSubMenuCallback : function(event){
94 var button = event.getTarget();
95 var callback = this.getMenuCallback();
96 callback = qx.lang.Function.bind(callback, this.getMenuContext() || this);
97 callback(button.getUserData("commandId"));
98 },
99
100 addTooltip : function(element){
101 if(this.getShortcut() != null){
102 element.setToolTip(new qx.ui.tooltip.ToolTip(this.getShortcut()));
103 }
104 }
105
106 }
107 });