/** * The standard command for all actions. It registers keyboard shortcuts, centralizes * command state, callback, etc. It is defined by command definitions that can be found * in the CommandsManager. */ qx.Class.define("org.argeo.ria.event.Command", { extend : qx.event.Command, implement : [org.argeo.ria.components.ILoadStatusable], properties : { /** * Unique id of the command */ id : {init:""}, /** * Label of the command */ label : {init:""}, /** * Icon of the command */ icon : {init:""}, /** * Sub menu if needed */ menu : { nullable: true, event : "changeMenu" }, /** * Callback associated to the submenu of the command */ menuCallback : {nullable:true}, /** * Context used when triggering menuCallback */ menuContext : {nullable:true} }, /** * @param id {String} Id of the command * @param label {String} Label of the command * @param icon {String} Icon of the command * @param shortcut {String} Keyboard Shortcut (like alt+o, ctrl+z, etc..) */ construct : function(id, label, icon, shortcut){ this.base(arguments, shortcut); this.setId(id); this.setLabel(label); this.setIcon(icon); }, members : { /** * Create a Button that suits a qx.ui.menu.MenuBar linked to this command * @return {qx.ui.menu.Button} */ getMenuButton : function(){ var button = new qx.ui.menu.Button( this.getLabel(), this.getIcon(), this, this.getMenu() ); this.addTooltip(button); if(this.getMenu()){ this.addListener("changeMenu", function(event){ button.setMenu(this.getMenuClone()); }, this); this.menuClones = []; } return button; }, /** * Create a Button that suits a qx.ui.toolbar.Toolbar part linked to this command. * @return {qx.ui.toolbar.MenuButton} */ getToolbarButton : function(){ var button; if(this.getMenu()){ button = new qx.ui.toolbar.MenuButton( this.getLabel(), this.getIcon(), this.getMenuClone() ); this.addListener("changeMenu", function(event){ button.setMenu(this.getMenuClone()); }, this); this.addListener("changeEnabled", function(e){ this.setEnabled(e.getData()); }, button); button.setEnabled(this.getEnabled()); }else{ button = new qx.ui.toolbar.Button( this.getLabel(), this.getIcon(), this ); } this.addTooltip(button); return button; }, /** * Clones the command menu * @return {qx.ui.menu.Menu} */ getMenuClone : function(){ var menuClone = new qx.ui.menu.Menu(); var submenus = this.getMenu(); for(var i=0;i