summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafal Szczesniak <mimir@samba.org>2007-03-11 18:35:19 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:49:25 -0500
commit95c3927e2b618a5c3cda8fc69caec3e7332adfe9 (patch)
treed9a5725cfc6a4d2e5a2e091b0750b9bb2827fa66
parent3e697d5110653d22bebade0da8f0c6c3749a2d09 (diff)
downloadsamba-95c3927e2b618a5c3cda8fc69caec3e7332adfe9.tar.gz
samba-95c3927e2b618a5c3cda8fc69caec3e7332adfe9.tar.bz2
samba-95c3927e2b618a5c3cda8fc69caec3e7332adfe9.zip
r21786: My initial attempts in qooxdoo coding. Derrell, please take
a look and I'll have a lot of questions to you. rafal (This used to be commit d92604ebd2f9d8d2d0a8883c193110780102912f)
-rw-r--r--webapps/swat/source/class/swat/module/netmgr/Fsm.js106
-rw-r--r--webapps/swat/source/class/swat/module/netmgr/Gui.js126
-rw-r--r--webapps/swat/source/class/swat/module/netmgr/NetManager.js29
3 files changed, 261 insertions, 0 deletions
diff --git a/webapps/swat/source/class/swat/module/netmgr/Fsm.js b/webapps/swat/source/class/swat/module/netmgr/Fsm.js
new file mode 100644
index 0000000000..f8a8953db6
--- /dev/null
+++ b/webapps/swat/source/class/swat/module/netmgr/Fsm.js
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) Rafal Szczesniak 2007
+ */
+
+/**
+ * Swat Net Manager class finite state machine
+ */
+qx.OO.defineClass("swat.module.netmgr.Fsm", swat.main.AbstractModuleFsm,
+function()
+{
+ swat.main.AbstractModuleFsm.call(this);
+});
+
+
+qx.Proto.buildFsm = function(module)
+{
+ var fsm = module.fsm;
+ var _this = this;
+
+ /*
+ * State: Idle
+ *
+ * Actions upon entry
+ * - if returning from RPC, display the result
+ *
+ * Transition on:
+ * "changeselection" on tree
+ */
+ var state = new qx.util.fsm.State(
+ "State_Idle",
+ {
+ "onentry" :
+ function(fsm, event)
+ {
+ if (fsm.getPreviousState() == "State_AwaitRpcResult")
+ {
+ var rpcRequest = _this.popRpcRequest();
+ var result = rpcRequest.getUserData("result");
+ var origins = swat.main.AbstractModuleFsm.JsonRpc_Origin;
+ var serverErrors = swat.main.AbstractModuleFsm.JsonRpc_ServerError;
+
+ if (result.type == "failed" &&
+ result.data.origin == origins.Server &&
+ result.data.code == serverErrors.ResourceError)
+ {
+ this.debug("error" + result);
+ }
+ else
+ {
+ // get the result of the call and apply it
+ var gui = swat.module.netmgr.Gui.getInstance();
+ gui.displayData(module, rpcRequest);
+ }
+
+ rpcRequest.request.dispose();
+ rpcRequest.request = null;
+ }
+ },
+
+ "events" :
+ {
+ "appear" :
+ {
+ "tree" :
+ "Transition_Idle_to_AwaitRpcResult_via_tree_appear"
+ }
+ }
+ });
+
+ // Replace the initial Idle state with this one
+ fsm.replaceState(state, true);
+
+ var trans = new qx.util.fsm.Transition(
+ "Transition_Idle_to_AwaitRpcResult_via_tree_appear",
+ {
+ "nextState" : "State_AwaitRpcResult",
+
+ "ontransition" :
+ function(fsm, event)
+ {
+ // Request our netbios name to add proper node to the tree
+ var request = _this.callRpc(fsm, "samba.config", "lp_get", [ "netbios name" ]);
+ request.setUserData("requestType", "hostname");
+ }
+ });
+
+ // Add the new transition
+ state.addTransition(trans);
+
+ blockedEvents =
+ {
+ "appear":
+ {
+ "tree" : qx.util.fsm.FiniteStateMachine.EventHandling.BLOCKED
+ }
+ }
+
+ this.addAwaitRpcResultState(module, blockedEvents);
+
+};
+
+
+/**
+ * Singleton Instance Getter
+ */
+qx.Class.getInstance = qx.lang.Function.returnInstance;
diff --git a/webapps/swat/source/class/swat/module/netmgr/Gui.js b/webapps/swat/source/class/swat/module/netmgr/Gui.js
new file mode 100644
index 0000000000..3b62337811
--- /dev/null
+++ b/webapps/swat/source/class/swat/module/netmgr/Gui.js
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) Rafal Szczesniak 2007
+ */
+
+/**
+ * Swat Net Manager class graphical user interface
+ */
+qx.OO.defineClass("swat.module.netmgr.Gui", qx.core.Object,
+function()
+{
+ qx.core.Object.call(this);
+});
+
+
+//qx.OO.addProperty({ name : "_tree", type : "object" });
+
+qx.Proto.buildGui = function(module)
+{
+ var fsm = module.fsm;
+
+ // We need a horizontal box layout for the database name
+ var vlayout = new qx.ui.layout.VerticalBoxLayout();
+ vlayout.set({
+ top: 20,
+ left: 20,
+ right: 20,
+ height: "100%"
+ });
+
+ // Create a hosts tree
+ this._tree = new qx.ui.treevirtual.TreeVirtual(["Net"]);
+ var tree = this._tree;
+
+ // Set the tree's properties
+ tree.set({
+ backgroundColor: 255,
+ border: qx.renderer.border.BorderPresets.getInstance().thinInset,
+ overflow: "hidden",
+ width: "30%",
+ height: "1*",
+ alwaysShowOpenCloseSymbol: true
+ });
+
+ tree.setCellFocusAttributes({ backgroundColor : "transparent" });
+
+ // Create event listener
+ tree.addEventListener("appear", fsm.eventListener, fsm);
+
+ // Give a tree widget nicer name to handle
+ fsm.addObject("tree", tree, "swat.main.fsmUtils.disable_during_rpc");
+
+ // Add the label to the horizontal layout
+ vlayout.add(tree);
+
+ module.canvas.add(vlayout);
+};
+
+
+qx.Proto.displayData = function(module, rpcRequest)
+{
+ var gui = module.gui;
+ var fsm = module.fsm;
+ var result = rpcRequest.getUserData("result");
+ var requestType = rpcRequest.getUserData("requestType");
+
+ // Something went wrong
+ if (result.type == "failed")
+ {
+ alert("Async(" + result.id + ") exception: " + result.data);
+ return;
+ }
+
+ switch (requestType)
+ {
+ case "hostname":
+ this._addHostNode(module, rpcRequest);
+ break;
+
+ case "NetContext":
+ this._initNetContext(module, rpcRequest);
+ break;
+ }
+
+ qx.ui.core.Widget.flushGlobalQueues();
+};
+
+
+qx.Proto._addHostNode = function(module, rpcRequest)
+{
+ var fsm = module.fsm;
+ var hostname = rpcRequest.getUserData("result").data;
+
+ // Get the tree widget
+ var tree = this._tree;
+ var dataModel = tree.getDataModel();
+
+ // Add new host and its service branches
+ var hostNodeId = dataModel.addBranch(null, hostname, false);
+
+ var domainNodeId = dataModel.addBranch(hostNodeId, "Domain", false);
+ var usersNodeId = dataModel.addBranch(hostNodeId, "Users", false);
+ var groupsNodeId = dataModel.addBranch(hostNodeId, "Groups", false);
+ var srvcsNodeId = dataModel.addBranch(hostNodeId, "Services", false);
+
+ // Services don't expand
+ dataModel.setState(domainNodeId, { bHideOpenClose : true });
+ dataModel.setState(usersNodeId, { bHideOpenClose : true });
+ dataModel.setState(groupsNodeId, { bHideOpenClose : true });
+ dataModel.setState(srvcsNodeId, { bHideOpenClose : true });
+
+ dataModel.setData();
+};
+
+
+qx.Proto._initNetContext = function(module, rpcRequest)
+{
+ // Gather obtained NetContext handle
+ var result = rpcRequest.getUserData("result").data;
+ module.netCtx = result;
+};
+
+
+/**
+ * Singleton Instance Getter
+ */
+qx.Class.getInstance = qx.lang.Function.returnInstance;
diff --git a/webapps/swat/source/class/swat/module/netmgr/NetManager.js b/webapps/swat/source/class/swat/module/netmgr/NetManager.js
new file mode 100644
index 0000000000..cdb9ba4515
--- /dev/null
+++ b/webapps/swat/source/class/swat/module/netmgr/NetManager.js
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) Rafal Szczesniak 2007
+ */
+
+/**
+ * Swat Net Manager class
+ */
+qx.OO.defineClass("swat.module.netmgr.NetManager",
+ swat.main.AbstractModule,
+function()
+{
+ swat.main.AbstractModule.call(this);
+});
+
+
+qx.Proto.initialAppear = function(module)
+{
+ // Replace the existing (temporary) finite state machine with the real one
+ swat.module.netmgr.Fsm.getInstance().buildFsm(module);
+
+ // Create the real gui
+ swat.module.netmgr.Gui.getInstance().buildGui(module);
+};
+
+
+/**
+ * Singleton Instance Getter
+ */
+qx.Class.getInstance = qx.lang.Function.returnInstance;