]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/event/Command.js
83641c416a987c123263a93a791a464bd8a82669
2 * The standard command for all actions. It registers keyboard shortcuts, centralizes
3 * command state, callback, etc. It is defined by command definitions that can be found
4 * in the CommandsManager.
6 qx
.Class
.define("org.argeo.ria.event.Command",
8 extend
: qx
.event
.Command
,
9 implement
: [org
.argeo
.ria
.components
.ILoadStatusable
],
13 * Unique id of the command
17 * Label of the command
32 * Callback associated to the submenu of the command
34 menuCallback
: {nullable
:true},
36 * Context used when triggering menuCallback
38 menuContext
: {nullable
:true}
42 * @param id {String} Id of the command
43 * @param label {String} Label of the command
44 * @param icon {String} Icon of the command
45 * @param shortcut {String} Keyboard Shortcut (like alt+o, ctrl+z, etc..)
47 construct : function(id
, label
, icon
, shortcut
){
48 this.base(arguments
, shortcut
);
58 * Create a Button that suits a qx.ui.menu.MenuBar linked to this command
59 * @return {qx.ui.menu.Button}
61 getMenuButton : function(){
62 var button
= new qx
.ui
.menu
.Button(
68 this.addTooltip(button
);
70 this.addListener("changeMenu", function(event
){
71 button
.setMenu(this.getMenuClone());
78 * Create a Button that suits a qx.ui.toolbar.Toolbar part linked to this command.
79 * @return {qx.ui.toolbar.MenuButton}
81 getToolbarButton : function(){
84 button
= new qx
.ui
.toolbar
.MenuButton(
89 this.addListener("changeMenu", function(event
){
90 button
.setMenu(this.getMenuClone());
92 this.addListener("changeEnabled", function(e
){
93 this.setEnabled(e
.getData());
95 button
.setEnabled(this.getEnabled());
97 button
= new qx
.ui
.toolbar
.Button(
103 this.addTooltip(button
);
108 * Clones the command menu
109 * @return {qx.ui.menu.Menu}
111 getMenuClone : function(){
112 var menuClone
= new qx
.ui
.menu
.Menu();
113 var submenus
= this.getMenu();
114 if(!submenus
) return;
115 for(var i
=0;i
<submenus
.length
;i
++){
116 var button
= new qx
.ui
.menu
.Button(submenus
[i
].label
, submenus
[i
].icon
);
117 button
.setUserData("commandId", submenus
[i
].commandId
);
118 button
.addListener("execute", this.executeSubMenuCallback
, this);
119 menuClone
.add(button
);
121 this.menuClones
.push(menuClone
);
126 * Remove all existing menus and their clones.
128 clearMenus : function(){
129 if(!this.getMenu()) return;
130 for(var i
=0;i
<this.menuClones
.length
;i
++){
131 this.menuClones
[i
].destroy();
133 this.menuClones
= [];
137 * Triggers the menuCallback property in the right context.
138 * @param event {qx.event.type.Event} The firing event.
140 executeSubMenuCallback : function(event
){
141 var button
= event
.getTarget();
142 var callback
= this.getMenuCallback();
143 callback
= qx
.lang
.Function
.bind(callback
, this.getMenuContext() || this);
144 callback(button
.getUserData("commandId"));
147 * Adds a tooltip to a button.
148 * @param element {qx.ui.core.Widget} The element to which the command tooltip is added.
150 addTooltip : function(element
){
151 if(this.getShortcut() != null){
152 element
.setToolTip(new qx
.ui
.tooltip
.ToolTip(this.getShortcut()));
157 * Implementation of the ILoadStatusable interface.
158 * Sets the whole command enabled if not loading and disabled if loading.
159 * @param status {Boolean} The loading status of the button.
161 setOnLoad : function(status
){
162 this.setEnabled(!status
);