svn commit: samba r21786 - in branches/SAMBA_4_0/webapps/swat/source/class/swat/module: . netmgr

mimir at samba.org mimir at samba.org
Sun Mar 11 18:35:20 GMT 2007


Author: mimir
Date: 2007-03-11 18:35:19 +0000 (Sun, 11 Mar 2007)
New Revision: 21786

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=21786

Log:
My initial attempts in qooxdoo coding. Derrell, please take
a look and I'll have a lot of questions to you.


rafal


Added:
   branches/SAMBA_4_0/webapps/swat/source/class/swat/module/netmgr/
   branches/SAMBA_4_0/webapps/swat/source/class/swat/module/netmgr/Fsm.js
   branches/SAMBA_4_0/webapps/swat/source/class/swat/module/netmgr/Gui.js
   branches/SAMBA_4_0/webapps/swat/source/class/swat/module/netmgr/NetManager.js


Changeset:
Added: branches/SAMBA_4_0/webapps/swat/source/class/swat/module/netmgr/Fsm.js
===================================================================
--- branches/SAMBA_4_0/webapps/swat/source/class/swat/module/netmgr/Fsm.js	2007-03-11 18:32:26 UTC (rev 21785)
+++ branches/SAMBA_4_0/webapps/swat/source/class/swat/module/netmgr/Fsm.js	2007-03-11 18:35:19 UTC (rev 21786)
@@ -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;

Added: branches/SAMBA_4_0/webapps/swat/source/class/swat/module/netmgr/Gui.js
===================================================================
--- branches/SAMBA_4_0/webapps/swat/source/class/swat/module/netmgr/Gui.js	2007-03-11 18:32:26 UTC (rev 21785)
+++ branches/SAMBA_4_0/webapps/swat/source/class/swat/module/netmgr/Gui.js	2007-03-11 18:35:19 UTC (rev 21786)
@@ -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;

Added: branches/SAMBA_4_0/webapps/swat/source/class/swat/module/netmgr/NetManager.js
===================================================================
--- branches/SAMBA_4_0/webapps/swat/source/class/swat/module/netmgr/NetManager.js	2007-03-11 18:32:26 UTC (rev 21785)
+++ branches/SAMBA_4_0/webapps/swat/source/class/swat/module/netmgr/NetManager.js	2007-03-11 18:35:19 UTC (rev 21786)
@@ -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;



More information about the samba-cvs mailing list