]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/event/CommandsManager.js
move "source" to "argeo-ria-src"
[gpl/argeo-slc.git] / org.argeo.slc.webapp / src / main / webapp / source / class / org / argeo / ria / event / CommandsManager.js
diff --git a/org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/event/CommandsManager.js b/org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/ria/event/CommandsManager.js
deleted file mode 100644 (file)
index 0f6f118..0000000
+++ /dev/null
@@ -1,322 +0,0 @@
-/**\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
-       type : "singleton",\r
-  extend : qx.core.Object,\r
-\r
-  construct : function(){\r
-       this.base(arguments);\r
-       this.setInitialDefinitions(qx.lang.Object.copy(this.getDefinitions()));\r
-       this.addListener("changedCommands", this.createCommands, this);\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
-                               label           : "Stop", \r
-                               icon            : "resource/slc/process-stop.png",\r
-                               shortcut        : "Control+s",\r
-                               enabled         : false,\r
-                               menu            : null,\r
-                               toolbar         : "list",\r
-                               callback        : function(e){},\r
-                               command         : null\r
-                       },\r
-                       /*\r
-                       "quit" : {\r
-                               label           : "Quit", \r
-                               icon            : "resource/slc/system-shutdown.png",\r
-                               shortcut        : "Control+q",\r
-                               enabled         : true,\r
-                               menu            : "File",\r
-                               toolbar         : false,\r
-                               callback        : function(e){}, \r
-                               command         : null\r
-                       },\r
-                       */\r
-                       "log" : {\r
-                               label           : "Show Console", \r
-                               icon            : "resource/slc/help-contents.png",\r
-                               shortcut        : "",\r
-                               enabled         : true,\r
-                               menu            : "Help",\r
-                               menuPosition: "last",\r
-                               toolbar         : false,\r
-                               callback        : function(e){                                          \r
-                                       org.argeo.ria.components.Logger.getInstance().toggle();\r
-                               }, \r
-                               command         : null\r
-                       },\r
-                       "help" : {\r
-                               label           : "About...", \r
-                               icon            : "resource/slc/help-about.png",\r
-                               shortcut        : "Control+h",\r
-                               enabled         : true,\r
-                               menu            : "Help",\r
-                               toolbar         : false,\r
-                               callback        : function(e){\r
-                                       var win = new org.argeo.ria.components.Modal("About SLC", null, "SLC is a product from Argeo.");\r
-                                       win.attachAndShow();\r
-                               }, \r
-                               command         : null\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
-  *****************************************************************************\r
-     MEMBERS\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
-               var defs = this.getDefinitions();\r
-               for(var key in defs){\r
-                       var definition = defs[key];\r
-                       var command;\r
-                       if(!definition.command){\r
-                               command = new org.argeo.ria.event.Command(key, definition.label, definition.icon, definition.shortcut);\r
-                               if(definition.submenu){\r
-                                       command.setMenu(definition.submenu);\r
-                                       if(definition.submenuCallback){\r
-                                               command.setMenuCallback(definition.submenuCallback);\r
-                                               command.setMenuContext((definition.callbackContext?definition.callbackContext:null));\r
-                                       }\r
-                               }\r
-                               command.setEnabled(definition.enabled);\r
-                               if(definition.toggle){\r
-                                       command.setToggle(true);\r
-                               }\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
-                       if(definition.menu){\r
-                               if(!this.menus[definition.menu]) this.menus[definition.menu] = [];\r
-                               this.menus[definition.menu].push(definition);\r
-                       }\r
-                       if(definition.toolbar){\r
-                               if(!this.toolbars[definition.toolbar]) this.toolbars[definition.toolbar] = [];\r
-                               this.toolbars[definition.toolbar].push(command);\r
-                       }\r
-               }\r
-               this.setDefinitions(defs);\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
-               if(viewSelection.getCount() > 0){\r
-                       var xmlNodes = viewSelection.getNodes();\r
-               }\r
-               for(var key in defs){\r
-                       var definition = defs[key];\r
-                       if(!definition.selectionChange) continue;\r
-                       var binded = qx.lang.Function.bind(definition.selectionChange, definition.command);\r
-                       binded(viewSelection.getViewId(), xmlNodes);\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);\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);\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
-               for(var key in this.menus){\r
-                       var menu = new qx.ui.menu.Menu();\r
-                       var button = new qx.ui.menubar.Button(key, null, menu);\r
-                       var anchorDetected = false;\r
-                       for(var i=0; i<this.menus[key].length;i++){\r
-                               var def = this.menus[key][i]; \r
-                               menu.add(def.command.getMenuButton());\r
-                               if(!anchorDetected && def.menuPosition){\r
-                                       anchorDetected = true;\r
-                                       anchors[def.menuPosition] = button;\r
-                               }\r
-                       }\r
-                       if(!anchorDetected){\r
-                               menuBar.add(button);\r
-                       }\r
-               }\r
-               // Add specific anchored buttons\r
-               if(anchors.first) menuBar.addAt(anchors.first, 0);\r
-               else if(anchors.last){\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
-                       var tPart = new qx.ui.toolbar.Part();\r
-                       toolbar.add(tPart);\r
-                       this.toolbars[key].map(function(command){\r
-                               tPart.add(command.getToolbarButton());\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
-               for(var i=0;i<commandIdsArray.length;i++){\r
-                       var definition = defs[commandIdsArray[i]];\r
-                       if(definition){\r
-                               var command = definition.command;\r
-                               contextMenu.add(command.getMenuButton());\r
-                       }\r
-               }\r
-               return contextMenu;\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
-                       if(callbackContext) definitions[key]['callbackContext'] = callbackContext;\r
-                       crtDefs[key] = definitions[key];\r
-               }\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
-               for(var key in definitions){\r
-                       if(!crtDefs[key]) continue;\r
-                       if(initDefs[key]){\r
-                               crtDefs[key] = initDefs[key];\r
-                       }else{\r
-                               delete crtDefs[key];\r
-                       }\r
-               }\r
-               this.setDefinitions(crtDefs);\r
-               this.fireEvent("changedCommands");\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
-               icon.setValue("icon");\r
-               var text = new qx.ui.menu.RadioButton("Show Text");\r
-               text.setValue("label");\r
-               var both = new qx.ui.menu.RadioButton("Show Both");\r
-               both.setValue("both");\r
-               var mgr = new qx.ui.form.RadioGroup(icon, text, both);\r
-               menu.add(icon);\r
-               menu.add(text);\r
-               menu.add(both);\r
-               mgr.setSelected(both);\r
-               toolbar.setContextMenu(menu);           \r
-               mgr.addListener("changeValue", function(e){\r
-                       this.setShow(e.getData());\r
-               }, toolbar);\r
-               \r
-       }\r
-  }\r
-});
\ No newline at end of file