/**\r
- * @author Charles\r
+ * The main controller (in a standard MVC point of view) of the application. It is a singleton\r
+ * thus can be called by any part of the application.\r
+ * This will wire all the commands that can be defined dynamically by any IView, and add their\r
+ * corresponding buttons to the application menubar and toolbars.\r
* \r
+ * @author Charles du Jeu\r
*/\r
qx.Class.define("org.argeo.ria.event.CommandsManager",\r
{\r
\r
properties : \r
{\r
+ /**\r
+ * Commands definitions\r
+ * @see org.argeo.ria.event.Command for the definition Map details. \r
+ */\r
definitions : {\r
init : {\r
"stop" : {\r
}\r
}\r
},\r
+ /**\r
+ * For internal use \r
+ */\r
initialDefinitions : {\r
init : {}\r
}\r
},\r
\r
events : {\r
+ /**\r
+ * Triggered when the whole commands list is changed.\r
+ */\r
"changedCommands" : "qx.event.type.Event"\r
},\r
\r
\r
members :\r
{\r
+ /**\r
+ * Creates all the objects (if they are not already existing) from the definitions maps.\r
+ */\r
createCommands : function(){\r
this.menus = {};\r
this.toolbars = {};\r
if(!definition.command){\r
command = new org.argeo.ria.event.Command(key, definition.label, definition.icon, definition.shortcut);\r
if(definition.submenu){\r
- var menu = new qx.ui.menu.Menu();\r
- command.setMenu(menu);\r
+ command.setMenu(definition.submenu);\r
if(definition.submenuCallback){\r
command.setMenuCallback(definition.submenuCallback);\r
command.setMenuContext((definition.callbackContext?definition.callbackContext:null));\r
}\r
command.setEnabled(definition.enabled);\r
command.addListener("execute", definition.callback, (definition.callbackContext?definition.callbackContext:this));\r
+ if(definition.init){\r
+ var binded = qx.lang.Function.bind(definition.init, command);\r
+ binded();\r
+ }\r
definition.command = command;\r
}else{\r
command = definition.command;\r
}\r
this.setDefinitions(defs);\r
},\r
- \r
+ \r
+ /**\r
+ * Refresh the current commands status depending on the viewSelection.\r
+ * @param viewSelection {org.argeo.ria.components.ViewSelection} The current ViewSelection\r
+ */\r
refreshCommands : function(viewSelection){\r
var defs = this.getDefinitions();\r
var xmlNodes = null;\r
}\r
},\r
\r
+ /**\r
+ * Record a menubar for the application\r
+ * @param menuBar {qx.ui.menubar.MenuBar} The application menubar\r
+ */\r
registerMenuBar : function(menuBar){\r
this.addListener("changedCommands", function(){\r
this.createMenuButtons(menuBar);\r
this.createMenuButtons(menuBar);\r
},\r
\r
+ /**\r
+ * Record a toolbar for the application\r
+ * @param toolBar {qx.ui.toolbar.ToolBar} The application toolbar\r
+ */\r
registerToolBar : function(toolBar){\r
this.addListener("changedCommands", function(){\r
this.createToolbarParts(toolBar);\r
this.createToolbarParts(toolBar);\r
}, \r
\r
+ /**\r
+ * Creates the real buttons and add them to the passed menuBar. \r
+ * @param menuBar {qx.ui.menubar.MenuBar} The application menubar\r
+ */\r
createMenuButtons : function(menuBar){\r
menuBar.removeAll();\r
var anchors = {};\r
menuBar.add(anchors.last);\r
}\r
},\r
+ \r
+ /**\r
+ * Creates the real buttons and add them to the passed toolbar. \r
+ * @param toolbar {qx.ui.toolbar.ToolBar} The application toolbar\r
+ */\r
createToolbarParts : function(toolbar){\r
toolbar.removeAll();\r
for(var key in this.toolbars){\r
});\r
}\r
},\r
+ /**\r
+ * Creates a context menu from an array of commands ids.\r
+ * @param commandIdsArray {Array} An array of string\r
+ * @return {qx.ui.menu.Menu}\r
+ */\r
createMenuFromIds : function(commandIdsArray){\r
var defs = this.getDefinitions();\r
var contextMenu = new qx.ui.menu.Menu();\r
}\r
return contextMenu;\r
},\r
- \r
+ /**\r
+ * Add a new set of commands definitions\r
+ * @param definitions {Map} a set of commands definitions.\r
+ * @param callbackContext {qx.ui.core.Object} The context used inside the commands callbacks.\r
+ */\r
addCommands : function(definitions, callbackContext){\r
var crtDefs = this.getDefinitions(); \r
for(var key in definitions){\r
this.setDefinitions(crtDefs);\r
this.fireEvent("changedCommands");\r
},\r
+ /**\r
+ * Removes a whole set of commands by their definitions maps.\r
+ * @param definitions {Map} a set of commands definitions\r
+ */\r
removeCommands : function(definitions){\r
var crtDefs = this.getDefinitions();\r
var initDefs = this.getInitialDefinitions();\r
this.setDefinitions(crtDefs);\r
this.fireEvent("changedCommands");\r
},\r
- \r
+ /**\r
+ * Executes a command by its id.\r
+ * @param commandId {String} The command id.\r
+ */\r
executeCommand : function(commandId){\r
var defs = this.getDefinitions();\r
if(defs[commandId] && defs[commandId].command.getEnabled()){\r
defs[commandId].command.execute();\r
}\r
},\r
+ /**\r
+ * Retrieves a command by its id.\r
+ * @param commandId {String} The command id.\r
+ */\r
getCommandById : function(commandId){\r
var defs = this.getDefinitions();\r
if(defs[commandId] && defs[commandId].command){\r
return defs[commandId].command;\r
} \r
},\r
+ /**\r
+ * Add a standard context menu to a toolbar for button look and feel (show icon, text, both).\r
+ * @param toolbar {qx.ui.toolbar.ToolBar} The toolbar\r
+ */\r
addToolbarContextMenu : function(toolbar){\r
var menu = new qx.ui.menu.Menu();\r
var icon = new qx.ui.menu.RadioButton("Show Icons");\r