-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
this.setLabel(label);\r
- this.setIcon(icon); \r
+ this.setIcon(icon); \r
+ this.menuClones = [];\r
},\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
this.getIcon(), \r
this, \r
- this.getMenu()\r
+ this.getMenuClone()\r
);\r
this.addTooltip(button);\r
if(this.getMenu()){\r
this.addListener("changeMenu", function(event){\r
- this.setMenu(event.getData());\r
- }, button);\r
+ button.setMenu(this.getMenuClone());\r
+ }, this); \r
}\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
- this.menuClone.setMinWidth(110);\r
+ var menuClone = new qx.ui.menu.Menu();\r
+ var submenus = this.getMenu();\r
+ if(!submenus) return;\r
+ for(var i=0;i<submenus.length;i++){\r
+ var button = new qx.ui.menu.Button(submenus[i].label, submenus[i].icon);\r
+ button.setUserData("commandId", submenus[i].commandId);\r
+ button.addListener("execute", this.executeSubMenuCallback, this);\r
+ menuClone.add(button);\r
}\r
- return this.menuClone;\r
+ this.menuClones.push(menuClone);\r
+ return 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
- addSubMenuButton : function(label, icon, commandId, menu){\r
- var button = new qx.ui.menu.Button(label, icon);\r
- button.setUserData("commandId", commandId);\r
- button.addListener("execute", this.executeSubMenuCallback, this);\r
- if(menu){\r
- menu.add(button);\r
- }else{\r
- this.getMenu().add(button);\r
- this.addSubMenuButton(label, icon, commandId, this.menuClone);\r
+ if(!this.getMenu()) return;\r
+ for(var i=0;i<this.menuClones.length;i++){\r
+ this.menuClones[i].destroy();\r
}\r
+ this.menuClones = [];\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