]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/event/Command.js
0026170ade614afde3cd200de47ce08ff78dd2a9
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
);
57 * Create a Button that suits a qx.ui.menu.MenuBar linked to this command
58 * @return {qx.ui.menu.Button}
60 getMenuButton : function(){
61 var button
= new qx
.ui
.menu
.Button(
67 this.addTooltip(button
);
69 this.addListener("changeMenu", function(event
){
70 this.setMenu(event
.getData());
77 * Create a Button that suits a qx.ui.toolbar.Toolbar part linked to this command.
78 * @return {qx.ui.toolbar.MenuButton}
80 getToolbarButton : function(){
83 button
= new qx
.ui
.toolbar
.MenuButton(
88 this.addListener("changeMenu", function(event
){
89 button
.setMenu(this.getMenuClone());
91 this.addListener("changeEnabled", function(e
){
92 this.setEnabled(e
.getData());
94 button
.setEnabled(this.getEnabled());
96 button
= new qx
.ui
.toolbar
.Button(
102 this.addTooltip(button
);
107 * Clones the command menu
108 * @return {qx.ui.menu.Menu}
110 getMenuClone : function(){
112 this.menuClone
= new qx
.ui
.menu
.Menu();
113 this.menuClone
.setMinWidth(110);
115 return this.menuClone
;
119 * Remove all existing menus and their clones.
121 clearMenus : function(){
122 this.getMenu().removeAll();
123 this.getMenuClone().removeAll();
127 * Add button to a given submenu.
128 * @param label {String} The label of the button
129 * @param icon {String} The icon of the button
130 * @param commandId {String} The associated command id.
131 * @param menu {qx.ui.menu.Menu} The menu to which add the button
133 addSubMenuButton : function(label
, icon
, commandId
, menu
){
134 var button
= new qx
.ui
.menu
.Button(label
, icon
);
135 button
.setUserData("commandId", commandId
);
136 button
.addListener("execute", this.executeSubMenuCallback
, this);
140 this.getMenu().add(button
);
141 this.addSubMenuButton(label
, icon
, commandId
, this.menuClone
);
146 * Triggers the menuCallback property in the right context.
147 * @param event {qx.event.type.Event} The firing event.
149 executeSubMenuCallback : function(event
){
150 var button
= event
.getTarget();
151 var callback
= this.getMenuCallback();
152 callback
= qx
.lang
.Function
.bind(callback
, this.getMenuContext() || this);
153 callback(button
.getUserData("commandId"));
156 * Adds a tooltip to a button.
157 * @param element {qx.ui.core.Widget} The element to which the command tooltip is added.
159 addTooltip : function(element
){
160 if(this.getShortcut() != null){
161 element
.setToolTip(new qx
.ui
.tooltip
.ToolTip(this.getShortcut()));
166 * Implementation of the ILoadStatusable interface.
167 * Sets the whole command enabled if not loading and disabled if loading.
168 * @param status {Boolean} The loading status of the button.
170 setOnLoad : function(status
){
171 this.setEnabled(!status
);