From 926aed2c827d61c999fb1fe482d234c1504b7177 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 21 Jan 2007 20:15:06 +0000 Subject: r20937: Update to latest Finite State Machine with properly-handled blocked events (This used to be commit 98eeba919c63e58782aedde45dd9e9b3e400baf8) --- .../source/class/swat/main/AbstractModuleFsm.js | 188 ++++++++++++--------- .../swat/source/class/swat/module/ldbbrowse/Fsm.js | 26 ++- 2 files changed, 129 insertions(+), 85 deletions(-) (limited to 'webapps/swat') diff --git a/webapps/swat/source/class/swat/main/AbstractModuleFsm.js b/webapps/swat/source/class/swat/main/AbstractModuleFsm.js index 8c11c7fadf..5ff8e69f40 100644 --- a/webapps/swat/source/class/swat/main/AbstractModuleFsm.js +++ b/webapps/swat/source/class/swat/main/AbstractModuleFsm.js @@ -26,7 +26,7 @@ qx.Proto.buildFsm = function(module) "to build its custom finite state machine."); }; -qx.Proto.addAwaitRpcResultState = function(module) +qx.Proto.addAwaitRpcResultState = function(module, blockedEvents) { var fsm = module.fsm; var _this = this; @@ -47,104 +47,124 @@ qx.Proto.addAwaitRpcResultState = function(module) * "failed" (on RPC) * "execute" on swat.main.fsmUtils.abort_rpc */ - var state = new qx.util.fsm.State( - "State_AwaitRpcResult", + + var stateInfo = + { + "autoActionsBeforeOnentry" : { - "autoActionsBeforeOnentry" : - { - // The name of a function. - "setEnabled" : - [ - { - // We want to enable objects in the group - // swat.main.fsmUtils.enable_during_rpc - "parameters" : [ true ], + // The name of a function. + "setEnabled" : + [ + { + // We want to enable objects in the group + // swat.main.fsmUtils.enable_during_rpc + "parameters" : [ true ], + + // Call this.getObject().setEnabled(true) on + // state entry, for each in the group called + // "swat.main.fsmUtils.enable_during_rpc". + "groups" : [ "swat.main.fsmUtils.enable_during_rpc" ] + }, - // Call this.getObject().setEnabled(true) on - // state entry, for each in the group called - // "swat.main.fsmUtils.enable_during_rpc". - "groups" : [ "swat.main.fsmUtils.enable_during_rpc" ] - }, + { + // We want to disable objects in the group + // swat.main.fsmUtils.disable_during_rpc + "parameters" : [ false ], + + // Call this.getObject().setEnabled(false) on + // state entry, for each in the group called + // "swat.main.fsmUtils.disable_during_rpc". + "groups" : [ "swat.main.fsmUtils.disable_during_rpc" ] + } + ] + }, - { - // We want to disable objects in the group - // swat.main.fsmUtils.disable_during_rpc - "parameters" : [ false ], - - // Call this.getObject().setEnabled(false) on - // state entry, for each in the group called - // "swat.main.fsmUtils.disable_during_rpc". - "groups" : [ "swat.main.fsmUtils.disable_during_rpc" ] - } - ] - }, + "autoActionsBeforeOnexit" : + { + // The name of a function. + "setEnabled" : + [ + { + // We want to re-disable objects we had enabled, in the group + // swat.main.fsmUtils.enable_during_rpc + "parameters" : [ false ], + + // Call this.getObject().setEnabled(false) on + // state entry, for each in the group called + // "swat.main.fsmUtils.enable_during_rpc". + "groups" : [ "swat.main.fsmUtils.enable_during_rpc" ] + }, + + { + // We want to re-enable objects we had disabled, in the group + // swat.main.fsmUtils.disable_during_rpc + "parameters" : [ true ], + + // Call this.getObject().setEnabled(true) on + // state entry, for each in the group called + // "swat.main.fsmUtils.disable_during_rpc". + "groups" : [ "swat.main.fsmUtils.disable_during_rpc" ] + } + ] + }, - "autoActionsBeforeOnexit" : + "onentry" : + function(fsm, event) { - // The name of a function. - "setEnabled" : - [ - { - // We want to re-disable objects we had enabled, in the group - // swat.main.fsmUtils.enable_during_rpc - "parameters" : [ false ], + var bAuthCompleted = false; - // Call this.getObject().setEnabled(false) on - // state entry, for each in the group called - // "swat.main.fsmUtils.enable_during_rpc". - "groups" : [ "swat.main.fsmUtils.enable_during_rpc" ] - }, + // See if we just completed an authentication + if (fsm.getPreviousState() == "State_Authenticate" && + event.getType() == "complete") + { + bAuthCompleted = true; + } - { - // We want to re-enable objects we had disabled, in the group - // swat.main.fsmUtils.disable_during_rpc - "parameters" : [ true ], - - // Call this.getObject().setEnabled(true) on - // state entry, for each in the group called - // "swat.main.fsmUtils.disable_during_rpc". - "groups" : [ "swat.main.fsmUtils.disable_during_rpc" ] - } - ] + // If we didn't just complete an authentication and we're coming + // from some other state... + if (! bAuthCompleted && + fsm.getPreviousState() != "State_AwaitRpcResult") + { + // ... then push the previous state onto the state stack + fsm.pushState(false); + } }, - "onentry" : - function(fsm, event) - { - var bAuthCompleted = false; + "events" : + { + "execute" : + { + "swat.main.fsmUtils.abort_rpc" : + "Transition_AwaitRpcResult_to_AwaitRpcResult_via_button_abort" + }, - // See if we just completed an authentication - if (fsm.getPreviousState() == "State_Authenticate" && - event.getType() == "complete") - { - bAuthCompleted = true; - } + "completed" : + "Transition_AwaitRpcResult_to_PopStack_via_complete", - // If we didn't just complete an authentication and we're coming - // from some other state... - if (! bAuthCompleted && - fsm.getPreviousState() != "State_AwaitRpcResult") - { - // ... then push the previous state onto the state stack - fsm.pushState(false); - } - }, + "failed" : + qx.util.fsm.FiniteStateMachine.EventHandling.PREDICATE + } + }; - "events" : + // If there are blocked events specified... + if (blockedEvents) + { + // ... then add them to the state info events object + for (var blockedEvent in blockedEvents) + { + // Ensure it's not already there. Avoid programmer headaches. + if (stateInfo["events"][blockedEvent]) { - "execute" : - { - "swat.main.fsmUtils.abort_rpc" : - "Transition_AwaitRpcResult_to_AwaitRpcResult_via_button_abort" - }, + throw new Error("Attempt to add blocked event " + + blockedEvent + " but it is already handled"); + } - "completed" : - "Transition_AwaitRpcResult_to_PopStack_via_complete", + // Add the event. + stateInfo["events"][blockedEvent] = blockedEvents[blockedEvent]; + } + } - "failed" : - qx.util.fsm.FiniteStateMachine.EventHandling.PREDICATE - } - }); + var state = new qx.util.fsm.State( "State_AwaitRpcResult", stateInfo); fsm.addState(state); /*** Transitions that use a PREDICATE appear first ***/ diff --git a/webapps/swat/source/class/swat/module/ldbbrowse/Fsm.js b/webapps/swat/source/class/swat/module/ldbbrowse/Fsm.js index 9843fa6ee2..6d436f4aa7 100644 --- a/webapps/swat/source/class/swat/module/ldbbrowse/Fsm.js +++ b/webapps/swat/source/class/swat/module/ldbbrowse/Fsm.js @@ -377,8 +377,32 @@ qx.Proto.buildFsm = function(module) }); state.addTransition(trans); + // Create the list of events that should be blocked while we're awaiting the + // results of another RPC request + blockedEvents = + { + // If a previously unexpanded tree node is expanded, issue a request + // to retrieve its contents. + "treeOpenWhileEmpty": + { + "tree" : + qx.util.fsm.FiniteStateMachine.EventHandling.BLOCKED + }, + + // If the selection changes, issue a request to retrieve contents to + // populate the attribute/value table. + "changeSelection": + { + "tree:manager" : + qx.util.fsm.FiniteStateMachine.EventHandling.BLOCKED, + + "dbName": + qx.util.fsm.FiniteStateMachine.EventHandling.BLOCKED + } + } + // Add the AwaitRpcResult state and all of its transitions - this.addAwaitRpcResultState(module); + this.addAwaitRpcResultState(module, blockedEvents); }; -- cgit