]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/event/CommandsManager.js
Use a specific renderer for status cell background management / Disable the mouse...
[gpl/argeo-slc.git] / org.argeo.slc.webapp / src / main / webapp / source / class / org / argeo / ria / event / CommandsManager.js
index 280df7578fc3d6f530e5a01375b8a0f8c2741b0d..bf6f6a3f713d25572dd1868e16ba66f89c0aaeb7 100644 (file)
@@ -1,6 +1,10 @@
 /**\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
@@ -15,6 +19,10 @@ qx.Class.define("org.argeo.ria.event.CommandsManager",
 \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
@@ -65,12 +73,18 @@ qx.Class.define("org.argeo.ria.event.CommandsManager",
                        }\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
@@ -82,6 +96,9 @@ qx.Class.define("org.argeo.ria.event.CommandsManager",
 \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
@@ -92,8 +109,7 @@ qx.Class.define("org.argeo.ria.event.CommandsManager",
                        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
@@ -101,6 +117,10 @@ qx.Class.define("org.argeo.ria.event.CommandsManager",
                                }\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
@@ -116,7 +136,11 @@ qx.Class.define("org.argeo.ria.event.CommandsManager",
                }\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
@@ -131,6 +155,10 @@ qx.Class.define("org.argeo.ria.event.CommandsManager",
                }\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
@@ -138,6 +166,10 @@ qx.Class.define("org.argeo.ria.event.CommandsManager",
                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
@@ -145,6 +177,10 @@ qx.Class.define("org.argeo.ria.event.CommandsManager",
                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
@@ -170,6 +206,11 @@ qx.Class.define("org.argeo.ria.event.CommandsManager",
                        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
@@ -180,6 +221,11 @@ qx.Class.define("org.argeo.ria.event.CommandsManager",
                        });\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
@@ -192,7 +238,11 @@ qx.Class.define("org.argeo.ria.event.CommandsManager",
                }\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
@@ -202,6 +252,10 @@ qx.Class.define("org.argeo.ria.event.CommandsManager",
                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
@@ -216,19 +270,30 @@ qx.Class.define("org.argeo.ria.event.CommandsManager",
                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