]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/argeo-ria-src/class/org/argeo/ria/event/Command.js
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
25 * Weather this command is a true/false state
27 toggle
: {init
:false},
36 * Callback associated to the submenu of the command
38 menuCallback
: {nullable
:true},
40 * Context used when triggering menuCallback
42 menuContext
: {nullable
:true}
46 * @param id {String} Id of the command
47 * @param label {String} Label of the command
48 * @param icon {String} Icon of the command
49 * @param shortcut {String} Keyboard Shortcut (like alt+o, ctrl+z, etc..)
51 construct : function(id
, label
, icon
, shortcut
){
52 this.base(arguments
, shortcut
);
62 * Create a Button that suits a qx.ui.menu.MenuBar linked to this command
63 * @return {qx.ui.menu.Button}
65 getMenuButton : function(){
67 button
= new qx
.ui
.menu
.CheckBox(this.getLabel());
68 this._registerToggleButtonListeners(button
);
70 var button
= new qx
.ui
.menu
.Button(
77 this.addListener("changeMenu", function(event
){
78 button
.setMenu(this.getMenuClone());
82 this.addTooltip(button
);
87 * Create a Button that suits a qx.ui.toolbar.Toolbar part linked to this command.
88 * @return {qx.ui.toolbar.MenuButton}
90 getToolbarButton : function(){
93 button
= new qx
.ui
.toolbar
.MenuButton(
98 this.addListener("changeMenu", function(event
){
99 button
.setMenu(this.getMenuClone());
101 this.addListener("changeEnabled", function(e
){
102 this.setEnabled(e
.getData());
104 button
.setEnabled(this.getEnabled());
105 }else if(this.getToggle()){
106 button
= new qx
.ui
.toolbar
.CheckBox(this.getLabel(), this.getIcon());
107 this._registerToggleButtonListeners(button
);
109 button
= new qx
.ui
.toolbar
.Button(
115 this.addTooltip(button
);
120 * Special tricks using UserData to enable/disable listeners to avoid loops...
121 * @param button {qx.ui.core.Widget} toolbar Checkbox or menu Checkbox button.
123 _registerToggleButtonListeners : function(button
){
124 button
.addListener("changeChecked", function(event
){
125 if(button
.getUserData("disableListener")) return;
126 this.setUserData("slc.command.toggleState", event
.getData());
127 this.setUserData("slc.command.toggleStateSource", button
);
128 this.fireEvent("execute");
130 this.addListener("execute", function(event
){
131 if(this.getUserData("slc;command.toggleStateSource") == button
) return;
132 button
.setUserData("disableListener", true);
133 button
.setChecked(this.getUserData("slc.command.toggleState"));
134 button
.setUserData("disableListener", false);
139 * Clones the command menu
140 * @return {qx.ui.menu.Menu}
142 getMenuClone : function(){
143 var menuClone
= new qx
.ui
.menu
.Menu();
144 menuClone
.setMinWidth(100);
145 var submenus
= this.getMenu();
146 if(!submenus
) return;
147 for(var i
=0;i
<submenus
.length
;i
++){
148 if(submenus
[i
].separator
){
149 menuClone
.add(new qx
.ui
.menu
.Separator());
151 var button
= new qx
.ui
.menu
.Button(submenus
[i
].label
, submenus
[i
].icon
);
152 button
.setUserData("commandId", submenus
[i
].commandId
);
153 button
.addListener("execute", this.executeSubMenuCallback
, this);
154 menuClone
.add(button
);
157 this.menuClones
.push(menuClone
);
162 * Remove all existing menus and their clones.
164 clearMenus : function(){
165 if(!this.getMenu()) return;
166 for(var i
=0;i
<this.menuClones
.length
;i
++){
167 this.menuClones
[i
].destroy();
169 this.menuClones
= [];
173 * Triggers the menuCallback property in the right context.
174 * @param event {qx.event.type.Event} The firing event.
176 executeSubMenuCallback : function(event
){
177 var button
= event
.getTarget();
178 var callback
= this.getMenuCallback();
179 callback
= qx
.lang
.Function
.bind(callback
, this.getMenuContext() || this);
180 callback(button
.getUserData("commandId"));
183 * Adds a tooltip to a button.
184 * @param element {qx.ui.core.Widget} The element to which the command tooltip is added.
186 addTooltip : function(element
){
187 if(this.getShortcut() != null){
188 element
.setToolTip(new qx
.ui
.tooltip
.ToolTip(this.getShortcut()));
193 * Implementation of the ILoadStatusable interface.
194 * Sets the whole command enabled if not loading and disabled if loading.
195 * @param status {Boolean} The loading status of the button.
197 setOnLoad : function(status
){
198 this.setEnabled(!status
);