2 * Copyright (C) Rafal Szczesniak 2007
6 * Swat Net Manager class finite state machine
8 qx.OO.defineClass("swat.module.netmgr.Fsm", swat.main.AbstractModuleFsm,
11 swat.main.AbstractModuleFsm.call(this);
15 qx.Proto.buildFsm = function(module)
24 * - if returning from RPC, display the result
27 * "changeselection" on tree
29 var state = new qx.util.fsm.State(
35 if (fsm.getPreviousState() == "State_AwaitRpcResult")
37 var rpcRequest = _this.popRpcRequest();
38 var result = rpcRequest.getUserData("result");
39 var origins = swat.main.AbstractModuleFsm.JsonRpc_Origin;
40 var serverErrors = swat.main.AbstractModuleFsm.JsonRpc_ServerError;
42 if (result.type == "failed" &&
43 result.data.origin == origins.Server &&
44 result.data.code == serverErrors.ResourceError)
46 alert("Error when receiving rpc: '" + result.id + "'" + " exception: " + result.data);
50 // get the result of the call and apply it
51 var gui = swat.module.netmgr.Gui.getInstance();
52 gui.displayData(module, rpcRequest);
55 rpcRequest.request.dispose();
56 rpcRequest.request = null;
65 "Transition_Idle_to_AwaitRpcResult_via_canvas_appear",
67 "Transition_Idle_to_AwaitRpcResult_via_vlayout_appear"
73 "Transition_Idle_to_AwaitRpcResult_via_tree_selection_changed"
78 // Replace the initial Idle state with this one
79 fsm.replaceState(state, true);
81 var trans = new qx.util.fsm.Transition(
82 "Transition_Idle_to_AwaitRpcResult_via_canvas_appear",
84 "nextState" : "State_AwaitRpcResult",
86 "ontransition" : function(fsm, event)
88 var request = _this.callRpc(fsm, "samba.ejsnet", "NetContext", []);
89 request.setUserData("requestType", "NetContext");
93 // Add the new transition
94 state.addTransition(trans);
96 var trans = new qx.util.fsm.Transition(
97 "Transition_Idle_to_AwaitRpcResult_via_vlayout_appear",
99 "nextState" : "State_AwaitRpcResult",
104 // Request our netbios name to add proper node to the tree
105 var request = _this.callRpc(fsm, "samba.config", "lp_get", [ "netbios name" ]);
106 request.setUserData("requestType", "hostname");
110 // Add the new transition
111 state.addTransition(trans);
113 var trans = new qx.util.fsm.Transition(
114 "Transition_Idle_to_AwaitRpcResult_via_tree_selection_changed",
116 "nextState" : "State_AwaitRpcResult",
118 "ontransition" : function(fsm, event)
120 var nodes = event.getData();
121 var selectedNode = nodes[0];
123 var gui = swat.module.netmgr.Gui.getInstance();
124 var parentNode = gui.getParentNode(module, selectedNode);
126 var params = (parentNode.credentials == undefined) ? [] : [ parentNode.credentials ];
131 // Add the new transition
132 state.addTransition(trans);
138 "tree" : qx.util.fsm.FiniteStateMachine.EventHandling.BLOCKED,
139 "vlayout" : qx.util.fsm.FiniteStateMachine.EventHandling.BLOCKED
143 // Add blocked events
144 this.addAwaitRpcResultState(module, blockedEvents);
150 * Singleton Instance Getter
152 qx.Class.getInstance = qx.lang.Function.returnInstance;