diff options
author | Derrell Lipman <derrell@samba.org> | 2006-12-30 05:09:59 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:30:29 -0500 |
commit | 1170417ceeb8c49a46cda522a38eaa71c9cae30c (patch) | |
tree | dbf4c3fdcdb1af928dbd55f642ea40f00d09283a /webapps/qooxdoo-0.6.3-sdk/frontend/demo/source/html/example/Fsm_1 | |
parent | 23ccdca41670085da4486841b0d4900b4c8b02f3 (diff) | |
download | samba-1170417ceeb8c49a46cda522a38eaa71c9cae30c.tar.gz samba-1170417ceeb8c49a46cda522a38eaa71c9cae30c.tar.bz2 samba-1170417ceeb8c49a46cda522a38eaa71c9cae30c.zip |
r20414: Start to make SWAT usable by others. This is just a start...
(This used to be commit 26a34037a7ca6fbd05c5a6f7c2d5973e34bc6918)
Diffstat (limited to 'webapps/qooxdoo-0.6.3-sdk/frontend/demo/source/html/example/Fsm_1')
3 files changed, 403 insertions, 0 deletions
diff --git a/webapps/qooxdoo-0.6.3-sdk/frontend/demo/source/html/example/Fsm_1/fsm.js b/webapps/qooxdoo-0.6.3-sdk/frontend/demo/source/html/example/Fsm_1/fsm.js new file mode 100644 index 0000000000..50cdc25ccb --- /dev/null +++ b/webapps/qooxdoo-0.6.3-sdk/frontend/demo/source/html/example/Fsm_1/fsm.js @@ -0,0 +1,297 @@ +/* + * Initialize the finite state machine. + * + * This finite state machine has two states: Idle and AwaitRpcResult. + * + * In the Idle state, the Send button is enabled, the Abort button is + * disabled, and the three color bars are blue. In the AwaitRpcResult state, + * the Send button is disabled, the Abort button is enabled, and three color + * bars are red. All of these changes occur via automatic, table-driven + * function calls in autoActionsXXX() objects, not via explicit code. This + * demonstrates how groups of objects can all be manipulated together without + * having to write lots of code to do so. Just as these color blocks change + * color, numerous widgets could be disabled/hidden/etc., without writing code + * to futz with all of them. + */ +function initFsm() +{ + // Create a new finite state machine + var fsm = new qx.util.fsm.FiniteStateMachine("Fsm_1"); + + // For this simple example application, show all debug messages. + qx.Settings.setCustomOfClass( + "qx.util.fsm.FiniteStateMachine", + "debugFlags", + (qx.util.fsm.FiniteStateMachine.DebugFlags.EVENTS | + qx.util.fsm.FiniteStateMachine.DebugFlags.TRANSITIONS | + qx.util.fsm.FiniteStateMachine.DebugFlags.FUNCTION_DETAIL | + qx.util.fsm.FiniteStateMachine.DebugFlags.OBJECT_NOT_FOUND)); + + /* + * State: Idle + * + * Actions upon entry: + * button_send.setEnabled(true); + * button_abort.setEnabled(false); + * change background of objects in group "group_color_change" to blue + * + * Transition on: + * "execute" on button_send + */ + var state = new qx.util.fsm.State( + "State_Idle", + { + "autoActionsBeforeOnentry" : + { + // The name of a function. + "setEnabled" : + [ + { + // We want to enable the 'send' button + "parameters" : [ true ], + + // Call this.getObject("button_send").setEnabled(true) + "objects" : [ "button_send" ] + }, + + { + // We want to disable the 'abort' button + "parameters" : [ false ], + + // Call this.getObject("button_abort").setEnabled(false) + "objects" : [ "button_abort" ] + } + ], + + // The name of a function. + "setBackgroundColor" : + [ + { + // We want to change the atoms' background color to blue + "parameters" : + [ + // We want the color oject created when needed, not "now" + // Providing a function as a parameter allows the value to be + // determined later. + function (fsm) { return new qx.renderer.color.Color("blue"); } + ], + + // Call this.getObject(<object>).seBackgroundcolor("blue") on + // state entry, for each <object> in the group called + // "group_color_change". + "groups" : [ "group_color_change" ] + } + ] + }, + + "events" : + { + // If the send button is pressed, go to new state state where we + // will await the RPC result + "execute" : + { + "button_send" : + "Transition_Idle_to_AwaitRpcResult_via_button_send" + } + } + }); + fsm.addState(state); + + /* + * Transition: Idle to AwaitRpcResult + * + * Cause: "execute" on button_send + * + * Action: + * Issue RPC request with coalesced failure events + */ + var trans = new qx.util.fsm.Transition( + "Transition_Idle_to_AwaitRpcResult_via_button_send", + { + "nextState" : + "State_AwaitRpcResult", + + "ontransition" : + function(fsm, event) + { + var rpc = fsm.getObject("rpc"); + + rpc.setUrl(fsm.getObject("text_url").getValue()); + rpc.setServiceName(fsm.getObject("text_service").getValue()); + + var request = + rpc.callAsyncListeners(true, // coalesce failure events + fsm.getObject("text_method").getValue(), + fsm.getObject("text_message").getValue()); + fsm.addObject("request", request); + } + }); + state.addTransition(trans); + + + /* + * State: AwaitRpcResult + * + * Actions upon entry: + * button_send.setEnabled(false); + * button_abort.setEnabled(true); + * change background of objects in group "group_color_change" to red + * + * Transition on: + * "completed" (on RPC) + * "failed" (on RPC) + * "execute on button_abort + */ + var state = new qx.util.fsm.State( + "State_AwaitRpcResult", + { + "autoActionsBeforeOnentry" : + { + // The name of a function. + "setEnabled" : + [ + { + // We want to disable the 'send' button + "parameters" : [ false ], + + // Call this.getObject("send").setEnabled(false) + "objects" : [ "button_send" ] + }, + + { + // We want to enable the 'abort' button + "parameters" : [ true ], + + // Call this.getObject("abort").setEnabled(true) + "objects" : [ "button_abort" ] + } + ], + + // The name of a function. + "setBackgroundColor" : + [ + { + // We want to change the atoms' background color to red + "parameters" : + [ + // We want the color oject created when needed, not "now" + // Providing a function as a parameter allows the value to be + // determined later. + function (fsm) { return new qx.renderer.color.Color("red"); } + ], + + // Call this.getObject(<object>).seBackgroundcolor("red"), for + // each <object> in the group called "group_color_change". + "groups" : [ "group_color_change" ] + } + ] + }, + + "events" : + { + "execute" : + { + "button_abort" : + "Transition_AwaitRpcResult_to_AwaitRpcResult_via_button_abort" + }, + + "completed" : + "Transition_AwaitRpcResult_to_Idle_via_complete", + + "failed" : + "Transition_AwaitRpcResult_to_Idle_via_failed" + }, + + "onentry" : + function(fsm, state) + { + var message = fsm.getObject("text_result"); + message.setValue(""); + } + + }); + fsm.addState(state); + + /* + * Transition: AwaitRpcResult to AwaitRpcResult + * + * Cause: "execute" on button_abort + */ + var trans = new qx.util.fsm.Transition( + "Transition_AwaitRpcResult_to_AwaitRpcResult_via_button_abort", + { + "nextState" : + "State_AwaitRpcResult", + + "ontransition" : + function(fsm, event) + { + // Get the request object + var request = fsm.getObject("request"); + + // Issue an abort for the pending request + request.abort(); + + var message = fsm.getObject("text_result"); + message.setValue("Abort requested..."); + } + }); + state.addTransition(trans); + + /* + * Transition: AwaitRpcResult to Idle + * + * Cause: "complete" (on RPC) + */ + var trans = new qx.util.fsm.Transition( + "Transition_AwaitRpcResult_to_Idle_via_complete", + { + "nextState" : + "State_Idle", + + "ontransition" : + function(fsm, event) + { + var message = fsm.getObject("text_result"); + message.setValue("Got result: " + event.getData()); + + // The request has completed, so remove the object reference + fsm.removeObject("request"); + } + }); + state.addTransition(trans); + + /* + * Transition: AwaitRpcResult to Idle + * + * Cause: "failed" (on RPC) + */ + var trans = new qx.util.fsm.Transition( + "Transition_AwaitRpcResult_to_Idle_via_failed", + { + "nextState" : + "State_Idle", + + "ontransition" : + function(fsm, event) + { + var message = fsm.getObject("text_result"); + message.setValue("Got failure: " + event.getData()); + + // The request has completed, so remove the object reference + fsm.removeObject("request"); + } + }); + state.addTransition(trans); + + // Allocate an RPC object + o = new qx.io.remote.Rpc(); + o.setTimeout(10000); + o.addEventListener("completed", fsm.eventListener, fsm); + o.addEventListener("failed", fsm.eventListener, fsm); + o.addEventListener("timeout", fsm.eventListener, fsm); + o.addEventListener("aborted", fsm.eventListener, fsm); + fsm.addObject("rpc", o); + + return fsm; +} diff --git a/webapps/qooxdoo-0.6.3-sdk/frontend/demo/source/html/example/Fsm_1/gui.js b/webapps/qooxdoo-0.6.3-sdk/frontend/demo/source/html/example/Fsm_1/gui.js new file mode 100644 index 0000000000..0ba443a629 --- /dev/null +++ b/webapps/qooxdoo-0.6.3-sdk/frontend/demo/source/html/example/Fsm_1/gui.js @@ -0,0 +1,95 @@ +function initGui(fsm) +{ + var o; + var d = qx.ui.core.ClientDocument.getInstance(); + + var vLayout = new qx.ui.layout.VerticalBoxLayout(); + vLayout.setTop(40); + vLayout.setLeft(20); + vLayout.setSpacing(4); + + vLayout.add(new qx.ui.basic.Label("URL:")); + var defaultURL = qx.io.remote.Rpc.makeServerURL(); + if (defaultURL == null) + { + defaultURL = "/services/"; + } + o = new qx.ui.form.TextField(defaultURL); + vLayout.add(o); + fsm.addObject("text_url", o); + + vLayout.add(new qx.ui.basic.Label("Service:")); + o = new qx.ui.form.TextField("qooxdoo.test"); + vLayout.add(o); + fsm.addObject("text_service", o); + + vLayout.add(new qx.ui.basic.Label("Method:")); + o = new qx.ui.form.TextField("sleep"); + vLayout.add(o); + fsm.addObject("text_method", o); + + var hLayout = new qx.ui.layout.HorizontalBoxLayout(); + hLayout.setHeight("auto"); + hLayout.setVerticalChildrenAlign("middle"); + hLayout.setSpacing(4); + + o = new qx.ui.form.TextField("2"); + o.setWidth(200); + hLayout.add(o); + fsm.addObject("text_message", o); + + o = new qx.ui.form.Button("Send to server"); + o.addEventListener("execute", fsm.eventListener, fsm); + hLayout.add(o); + fsm.addObject("button_send", o); + + o = new qx.ui.form.Button("Abort"); + o.setEnabled(false); + o.addEventListener("execute", fsm.eventListener, fsm); + hLayout.add(o); + fsm.addObject("button_abort", o); + + vLayout.add(hLayout); + + vLayout.add(new qx.ui.basic.Label("Result:")); + o = new qx.ui.form.TextField(""); + o.setWidth(600); + vLayout.add(o); + fsm.addObject("text_result", o); + + var hLayout = new qx.ui.layout.HorizontalBoxLayout(); + hLayout.setHeight("auto"); + hLayout.setVerticalChildrenAlign("middle"); + hLayout.setSpacing(4); + + var o = new qx.ui.basic.Atom("Idle=blue, RPC=red"); + o.setBorder(qx.renderer.border.BorderPresets.getInstance().black); + o.setColor(new qx.renderer.color.Color("white")); + o.setWidth(200); + o.setHeight(30); + o.setPadding(4); + hLayout.add(o); + fsm.addObject("atom_1", o, "group_color_change"); + + var o = new qx.ui.basic.Atom("Idle=blue, RPC=red"); + o.setBorder(qx.renderer.border.BorderPresets.getInstance().black); + o.setColor(new qx.renderer.color.Color("white")); + o.setWidth(200); + o.setHeight(30); + o.setPadding(4); + hLayout.add(o); + fsm.addObject("atom_2", o, "group_color_change"); + + var o = new qx.ui.basic.Atom("Idle=blue, RPC=red"); + o.setBorder(qx.renderer.border.BorderPresets.getInstance().black); + o.setColor(new qx.renderer.color.Color("white")); + o.setWidth(200); + o.setHeight(30); + o.setPadding(4); + hLayout.add(o); + fsm.addObject("atom_3", o, "group_color_change"); + + vLayout.add(hLayout); + + d.add(vLayout); +} diff --git a/webapps/qooxdoo-0.6.3-sdk/frontend/demo/source/html/example/Fsm_1/main.js b/webapps/qooxdoo-0.6.3-sdk/frontend/demo/source/html/example/Fsm_1/main.js new file mode 100644 index 0000000000..56a53ac484 --- /dev/null +++ b/webapps/qooxdoo-0.6.3-sdk/frontend/demo/source/html/example/Fsm_1/main.js @@ -0,0 +1,11 @@ +qx.core.Init.getInstance().defineMain(function() +{ + // Initialize the finite state machine + fsm = initFsm(); + + // Initialize the GUI + initGui(fsm); + + // Start the finite state machine + fsm.start(); +}); |