-qx.Class.define("org.argeo.ria.event.Command",\r
+/**\r
+ * The standard command for all actions. It registers keyboard shortcuts, centralizes \r
+ * command state, callback, etc. It is defined by command definitions that can be found \r
+ * in the CommandsManager. \r
+ */\r
+ qx.Class.define("org.argeo.ria.event.Command",\r
{\r
extend : qx.event.Command,\r
implement : [org.argeo.ria.components.ILoadStatusable],\r
\r
properties : {\r
+ /**\r
+ * Unique id of the command \r
+ */\r
id : {init:""},\r
+ /**\r
+ * Label of the command \r
+ */\r
label : {init:""},\r
+ /**\r
+ * Icon of the command \r
+ */\r
icon : {init:""},\r
+ /**\r
+ * Sub menu if needed \r
+ */\r
menu : {\r
nullable: true,\r
event : "changeMenu"\r
},\r
+ /**\r
+ * Callback associated to the submenu of the command \r
+ */\r
menuCallback : {nullable:true},\r
+ /**\r
+ * Context used when triggering menuCallback \r
+ */\r
menuContext : {nullable:true}\r
},\r
\r
+ /**\r
+ * @param id {String} Id of the command\r
+ * @param label {String} Label of the command\r
+ * @param icon {String} Icon of the command\r
+ * @param shortcut {String} Keyboard Shortcut (like alt+o, ctrl+z, etc..)\r
+ */\r
construct : function(id, label, icon, shortcut){\r
this.base(arguments, shortcut);\r
this.setId(id);\r
\r
members :\r
{\r
+ /**\r
+ * Create a Button that suits a qx.ui.menu.MenuBar linked to this command\r
+ * @return {qx.ui.menu.Button}\r
+ */\r
getMenuButton : function(){\r
var button = new qx.ui.menu.Button(\r
this.getLabel(), \r
return button;\r
},\r
\r
+ /**\r
+ * Create a Button that suits a qx.ui.toolbar.Toolbar part linked to this command.\r
+ * @return {qx.ui.toolbar.MenuButton}\r
+ */\r
getToolbarButton : function(){\r
var button;\r
if(this.getMenu()){\r
return button;\r
},\r
\r
+ /**\r
+ * Clones the command menu\r
+ * @return {qx.ui.menu.Menu}\r
+ */\r
getMenuClone : function(){\r
if(!this.menuClone){\r
this.menuClone = new qx.ui.menu.Menu();\r
return this.menuClone;\r
},\r
\r
+ /**\r
+ * Remove all existing menus and their clones.\r
+ */\r
clearMenus : function(){\r
this.getMenu().removeAll();\r
this.getMenuClone().removeAll();\r
},\r
\r
+ /**\r
+ * Add button to a given submenu.\r
+ * @param label {String} The label of the button\r
+ * @param icon {String} The icon of the button\r
+ * @param commandId {String} The associated command id.\r
+ * @param menu {qx.ui.menu.Menu} The menu to which add the button\r
+ */\r
addSubMenuButton : function(label, icon, commandId, menu){\r
var button = new qx.ui.menu.Button(label, icon);\r
button.setUserData("commandId", commandId);\r
}\r
},\r
\r
+ /**\r
+ * Triggers the menuCallback property in the right context.\r
+ * @param event {qx.event.type.Event} The firing event.\r
+ */\r
executeSubMenuCallback : function(event){\r
var button = event.getTarget();\r
var callback = this.getMenuCallback();\r
callback = qx.lang.Function.bind(callback, this.getMenuContext() || this);\r
callback(button.getUserData("commandId")); \r
}, \r
- \r
+ /**\r
+ * Adds a tooltip to a button.\r
+ * @param element {qx.ui.core.Widget} The element to which the command tooltip is added. \r
+ */\r
addTooltip : function(element){\r
if(this.getShortcut() != null){\r
element.setToolTip(new qx.ui.tooltip.ToolTip(this.getShortcut()));\r
} \r
},\r
\r
+ /**\r
+ * Implementation of the ILoadStatusable interface.\r
+ * Sets the whole command enabled if not loading and disabled if loading.\r
+ * @param status {Boolean} The loading status of the button. \r
+ */\r
setOnLoad : function(status){\r
this.setEnabled(!status);\r
}\r