X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.webapp%2Fsrc%2Fmain%2Fwebapp%2Fargeo-ria-src%2Fclass%2Forg%2Fargeo%2Fria%2Fevent%2FCommandsManager.js;h=f4e38a4084211662b58faa004fe74c20f0398f05;hb=6ae24373b4153f19984831a5f456c18f763bf279;hp=573c11ff642fe80da8643aba2bf25336ab8689a6;hpb=c6b00aeb38c5111dbc0532d52586a92d7e127540;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.webapp/src/main/webapp/argeo-ria-src/class/org/argeo/ria/event/CommandsManager.js b/org.argeo.slc.webapp/src/main/webapp/argeo-ria-src/class/org/argeo/ria/event/CommandsManager.js index 573c11ff6..f4e38a408 100644 --- a/org.argeo.slc.webapp/src/main/webapp/argeo-ria-src/class/org/argeo/ria/event/CommandsManager.js +++ b/org.argeo.slc.webapp/src/main/webapp/argeo-ria-src/class/org/argeo/ria/event/CommandsManager.js @@ -83,6 +83,13 @@ qx.Class.define("org.argeo.ria.event.CommandsManager", initialDefinitions : { init : {}, check : "Map" + }, + /** + * Special command definitions that are shared between focusable parts. + */ + sharedDefinitions : { + init: {}, + check: "Map" } }, @@ -101,6 +108,10 @@ qx.Class.define("org.argeo.ria.event.CommandsManager", members : { + /** + * Initialize the manager with basic definitions. + * @param initDefinitions {Map} A map of commands definitions. + */ init : function(initDefinitions){ this.setDefinitions(initDefinitions); this.setInitialDefinitions(qx.lang.Object.copy(initDefinitions)); @@ -113,6 +124,7 @@ qx.Class.define("org.argeo.ria.event.CommandsManager", this.menus = {}; this.toolbars = {}; var defs = this.getDefinitions(); + var shared = this.getSharedDefinitions(); for(var key in defs){ var definition = defs[key]; var command; @@ -128,6 +140,9 @@ qx.Class.define("org.argeo.ria.event.CommandsManager", command.setEnabled(definition.enabled); if(definition.toggle){ command.setToggle(true); + if(definition.toggleInitialState){ + command.setToggleInitialState(definition.toggleInitialState); + } } this._attachListener(command, definition.callback, definition.callbackContext); if(definition.init){ @@ -137,6 +152,20 @@ qx.Class.define("org.argeo.ria.event.CommandsManager", definition.command = command; }else{ command = definition.command; + if(shared[key]){ + + for(var focusPartId in shared[key]){ + var sharedCommand = shared[key][focusPartId]; + if(sharedCommand.callback){ + var split = sharedCommand.callbackContext.split(":"); + var focusPart = split[0]; + var viewId = split[1]; + command.registerCallback(sharedCommand.callback, split[1]); + //this._attachListener(command, sharedCommand.callback, sharedCommand.callbackContext); + } + } + + } } if(definition.menu){ if(!this.menus[definition.menu]) this.menus[definition.menu] = []; @@ -156,6 +185,7 @@ qx.Class.define("org.argeo.ria.event.CommandsManager", */ refreshCommands : function(viewSelection){ var defs = this.getDefinitions(); + var shared = this.getSharedDefinitions(); var xmlNodes = null; if(viewSelection.getCount() > 0){ var xmlNodes = viewSelection.getNodes(); @@ -163,6 +193,16 @@ qx.Class.define("org.argeo.ria.event.CommandsManager", for(var key in defs){ var definition = defs[key]; if(!definition.selectionChange) continue; + if(shared[key]){ + var currentFocus = org.argeo.ria.components.ViewsManager.getInstance().getCurrentFocus(); + //this.debug(currentFocus); + if(!currentFocus) continue; + var sharedComm = shared[key][currentFocus.getViewId()]; + if(sharedComm && sharedComm.selectionChange){ + var binded = qx.lang.Function.bind(sharedComm.selectionChange, definition.command); + binded(viewSelection.getViewId(), xmlNodes); + } + } var binded = qx.lang.Function.bind(definition.selectionChange, definition.command); binded(viewSelection.getViewId(), xmlNodes); } @@ -254,13 +294,25 @@ qx.Class.define("org.argeo.ria.event.CommandsManager", /** * Add a new set of commands definitions. See the definitions property of this class. * @param definitions {Map} a set of commands definitions. - * @param callbackContext {qx.ui.core.Object} The context used inside the commands callbacks. + * @param callbackContext {qx.ui.core.Object} The context used inside the commands callbacks. + * @param focusablePartId {String} A string identifying the associated focusable part, like "view:viewId". */ - addCommands : function(definitions, callbackContext){ + addCommands : function(definitions, callbackContext, focusablePartId){ var crtDefs = this.getDefinitions(); for(var key in definitions){ if(callbackContext) definitions[key]['callbackContext'] = callbackContext; - crtDefs[key] = definitions[key]; + if(crtDefs[key] && definitions[key]['shared']){ + if(focusablePartId) { + definitions[key]['focusablePartId'] = focusablePartId; + if(!this.getSharedDefinitions()[key]){ + this.getSharedDefinitions()[key] = {}; + } + this.getSharedDefinitions()[key][focusablePartId] = definitions[key]; + } + + }else{ + crtDefs[key] = definitions[key]; + } } this.setDefinitions(crtDefs); this.fireEvent("changedCommands"); @@ -268,16 +320,23 @@ qx.Class.define("org.argeo.ria.event.CommandsManager", /** * Removes a whole set of commands by their definitions maps. * @param definitions {Map} a set of commands definitions + * @param focusablePartId {String} A string identifying the associated focusable part, like "view:viewId". */ - removeCommands : function(definitions){ + removeCommands : function(definitions, focusablePartId){ var crtDefs = this.getDefinitions(); var initDefs = this.getInitialDefinitions(); + var sharedDefs = this.getSharedDefinitions(); for(var key in definitions){ if(!crtDefs[key]) continue; if(initDefs[key]){ crtDefs[key] = initDefs[key]; }else{ - delete crtDefs[key]; + if(sharedDefs[key] && sharedDefs[key][focusablePartId]){ + crtDefs[key].command.removeCallback(focusablePartId); + delete sharedDefs[key][focusablePartId]; + }else{ + delete crtDefs[key]; + } } } this.setDefinitions(crtDefs); @@ -345,9 +404,41 @@ qx.Class.define("org.argeo.ria.event.CommandsManager", return; } if(typeof(callbackContext) == "string"){ + + var split = callbackContext.split(":"); + var focusPart = split[0]; + var viewId = split[1]; + if(command.getCallbacks()[viewId]) return; + command.registerCallback(callback, split[1]); + command.addListener("execute", function(event){ + var target = event.getTarget(); + var callbacks = target.getCallbacks(); + if(qx.lang.Object.getLength(callbacks) == 0) return; + var view = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById(viewId).getContent(); + if(qx.lang.Object.getLength(callbacks) == 1){ + var binded = qx.lang.Function.bind(callbacks[qx.lang.Object.getKeys(callbacks)[0]], view); + binded(event); + return; + } + var currentFocus = org.argeo.ria.components.ViewsManager.getInstance().getCurrentFocus(); + if(currentFocus && currentFocus.getViewId() && callbacks[currentFocus.getViewId()]){ + var currentViewId = currentFocus.getViewId(); + view = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById(currentViewId).getContent(); + var binded = qx.lang.Function.bind(callbacks[currentFocus.getViewId()], view); + binded(event); + return; + } + }); + + + /* if(callbackContext.split(":")[0] == "view"){ var viewId = callbackContext.split(":")[1]; command.addListener("execute", function(event){ + if(event.getTarget().getCheckFocusAtCallback()){ + var currentFocus = org.argeo.ria.components.ViewsManager.getInstance().getCurrentFocus(); + if(currentFocus.getViewId() != viewId) return; + } var view = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById(viewId).getContent(); var binded = qx.lang.Function.bind(callback, view); binded(event); @@ -355,6 +446,7 @@ qx.Class.define("org.argeo.ria.event.CommandsManager", }else{ command.addListener("execute", callback, callbackContext); } + */ } } }