]> 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
Add source and build version of org.argeo.slc.web.Application together with build...
[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 },
15
16 construct : function(id, label, icon, shortcut){
17 this.base(arguments, shortcut);
18 this.setId(id);
19 this.setLabel(label);
20 this.setIcon(icon);
21 },
22
23 members :
24 {
25 getMenuButton : function(){
26 var button = new qx.ui.menu.Button(
27 this.getLabel(),
28 this.getIcon(),
29 this,
30 this.getMenu()
31 );
32 this.addTooltip(button);
33 if(this.getMenu()){
34 this.addListener("changeMenu", function(event){
35 this.setMenu(event.getData());
36 }, button);
37 }
38 return button;
39 },
40
41 getToolbarButton : function(){
42 var button;
43 if(this.getMenu()){
44 button = new qx.ui.toolbar.MenuButton(
45 this.getLabel(),
46 this.getIcon(),
47 this.getMenuClone()
48 );
49 this.addListener("changeMenu", function(event){
50 button.setMenu(this.getMenuClone());
51 }, this);
52 this.addListener("changeEnabled", function(e){
53 this.setEnabled(e.getData());
54 }, button);
55 button.setEnabled(this.getEnabled());
56 }else{
57 button = new qx.ui.toolbar.Button(
58 this.getLabel(),
59 this.getIcon(),
60 this
61 );
62 }
63 this.addTooltip(button);
64 return button;
65 },
66
67 getMenuClone : function(){
68 if(!this.menuClone){
69 this.menuClone = new qx.ui.menu.Menu();
70 this.menuClone.setMinWidth(110);
71 }
72 return this.menuClone;
73 },
74
75 clearMenus : function(){
76 this.getMenu().removeAll();
77 this.getMenuClone().removeAll();
78 },
79
80 addSubMenuButton : function(label, icon, commandId, menu){
81 var button = new qx.ui.menu.Button(label);
82 button.setUserData("commandId", commandId);
83 button.addListener("execute", this.executeSubMenuCallback, this);
84 if(menu){
85 menu.add(button);
86 }else{
87 this.getMenu().add(button);
88 this.addSubMenuButton(label, icon, commandId, this.menuClone);
89 }
90 },
91
92 executeSubMenuCallback : function(event){
93 var button = event.getTarget();
94 var callback = this.getMenuCallback();
95 callback = qx.lang.Function.bind(callback, this);
96 callback(button.getUserData("commandId"));
97 },
98
99 addTooltip : function(element){
100 if(this.getShortcut() != null){
101 element.setToolTip(new qx.ui.tooltip.ToolTip(this.getShortcut()));
102 }
103 }
104
105 }
106 });