svn commit: samba r20376 - in branches/SAMBA_4_0/swat/apps/swat/source/class/swat: main module

derrell at samba.org derrell at samba.org
Thu Dec 28 04:44:34 GMT 2006


Author: derrell
Date: 2006-12-28 04:44:34 +0000 (Thu, 28 Dec 2006)
New Revision: 20376

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

Log:
make module registration substantially cleaner
Added:
   branches/SAMBA_4_0/swat/apps/swat/source/class/swat/module/Module.js
Modified:
   branches/SAMBA_4_0/swat/apps/swat/source/class/swat/main/Gui.js
   branches/SAMBA_4_0/swat/apps/swat/source/class/swat/main/Main.js


Changeset:
Modified: branches/SAMBA_4_0/swat/apps/swat/source/class/swat/main/Gui.js
===================================================================
--- branches/SAMBA_4_0/swat/apps/swat/source/class/swat/main/Gui.js	2006-12-28 03:33:52 UTC (rev 20375)
+++ branches/SAMBA_4_0/swat/apps/swat/source/class/swat/main/Gui.js	2006-12-28 04:44:34 UTC (rev 20376)
@@ -12,8 +12,9 @@
  */
 qx.OO.defineClass("swat.main.Gui");
 
+qx.Class.currentCanvas = null;
 
-qx.Class.buildGui = function(modules)
+qx.Class.buildGui = function(moduleList)
 {
   var o;
 
@@ -98,10 +99,10 @@
   var menu = new qx.ui.menu.Menu();
 
   // We'll also track the current module's canvas in the modules object
-  modules.currentCanvas = null;
+  swat.main.Gui.currentCanvas = null;
 
   // For each menu item...
-  for (moduleName in modules.list)
+  for (moduleName in moduleList)
   {
     // create a radio button menu item
     o = new qx.ui.menu.RadioButton(moduleName, null, command);
@@ -123,13 +124,13 @@
     canvas.setBackgroundColor("white");
     canvas.setDisplay(false); // initially not displayed
 
-    var fsm = modules.list[moduleName].fsm;
+    var fsm = moduleList[moduleName].fsm;
     fsm.addObject("swat.module.canvas", canvas);
     canvas.addEventListener("appear", fsm.eventListener, fsm);
     canvas.addEventListener("disappear", fsm.eventListener, fsm);
 
     // Save the canvas
-    modules.list[moduleName].canvas = canvas;
+    moduleList[moduleName].canvas = canvas;
 
     // Add the canvas to the document
     canvas.addToDocument();
@@ -137,13 +138,13 @@
     // When a Module menu item is selected:
     o.addEventListener("changeChecked", function(e)
                        {
-                         var canvas = modules.list[this.moduleName].canvas;
+                         var canvas = moduleList[this.moduleName].canvas;
 
                          // If there's a current canvas, ...
-                         if (modules.currentCanvas)
+                         if (swat.main.Gui.currentCanvas)
                          {
                            // ... then remove display of it.
-                           modules.currentCanvas.setDisplay(false);
+                           swat.main.Gui.currentCanvas.setDisplay(false);
                            
                            // Dispatch an event on the canvas to notify old
                            // module it's coming into disuse.
@@ -154,11 +155,11 @@
                          if (e.getData())
                          {
                            // then display our canvas
-                           var canvas = modules.list[this.moduleName].canvas;
+                           var canvas = moduleList[this.moduleName].canvas;
                            canvas.setDisplay(true);
 
                            // Track the current canvas (now ours)
-                           modules.currentCanvas = canvas;
+                           swat.main.Gui.currentCanvas = canvas;
 
                            // Dispatch an event on the canvas to notify new
                            // module it's coming into use.

Modified: branches/SAMBA_4_0/swat/apps/swat/source/class/swat/main/Main.js
===================================================================
--- branches/SAMBA_4_0/swat/apps/swat/source/class/swat/main/Main.js	2006-12-28 03:33:52 UTC (rev 20375)
+++ branches/SAMBA_4_0/swat/apps/swat/source/class/swat/main/Main.js	2006-12-28 04:44:34 UTC (rev 20376)
@@ -8,10 +8,8 @@
  */
 
 /*
+#require(swat.module.Module)
 #require(swat.module.AbstractModule)
-#require(swat.module.statistics.Statistics)
-#require(swat.module.documentation.Documentation)
-#require(api.Viewer)
 */
 
 /**
@@ -23,31 +21,20 @@
   qx.component.AbstractApplication.call(this);
 });
 
-/**
- * The list of supported modules
+/*
+ * Register our supported modules
  */
-qx.Class.modules =
-{
-  list :
-  {
-    "System Status" :
-    {
-      "canvas" : null,
-      "fsm"    : null,
-      "gui"    : null,
-      "class"  : swat.module.statistics.Statistics
-    },
-    "API Documentation" :
-    {
-      "canvas" : null,
-      "fsm"    : null,
-      "gui"    : null,
-      "class"  : swat.module.documentation.Documentation
-    }
-  }
-};
 
+//#require(swat.module.statistics.Statistics)
+new swat.module.Module("Statistics",
+                       swat.module.statistics.Statistics);
 
+//#require(swat.module.documentation.Documentation)
+//#require(api.Viewer)
+new swat.module.Module("API Documentation",
+                       swat.module.documentation.Documentation);
+
+
 /*
 ---------------------------------------------------------------------------
   METHODS
@@ -56,8 +43,6 @@
 
 qx.Proto.initialize = function()
 {
-  var modules = swat.main.Main.modules;
-
   // Set the resource URI
   qx.Settings.setCustom("resourceUri", "./resource");
 
@@ -65,44 +50,44 @@
   qx.Settings.setCustomOfClass("qx.io.Json", "enableDebug", true);
 
   // For each module...
-  for (moduleName in modules.list)
+  var moduleList = swat.module.Module.getList();
+  for (moduleName in moduleList)
   {
     // ... add the module's name to the module object, ...
-    modules.list[moduleName].name = moduleName;
+    moduleList[moduleName].name = moduleName;
 
     // ... and call the module's buildInitialFsm() function
-    var module = modules.list[moduleName]["class"].getInstance();
-    module.buildInitialFsm(modules.list[moduleName]);
+    var module = moduleList[moduleName]["class"].getInstance();
+    module.buildInitialFsm(moduleList[moduleName]);
   }
 };
 
 
 qx.Proto.main = function()
 {
-  var modules = swat.main.Main.modules;
+  var moduleList = swat.module.Module.getList();
 
   // Initialize the gui for the main menu
-  swat.main.Gui.buildGui(modules);
+  swat.main.Gui.buildGui(moduleList);
 
   // Similarly, now that we have a canvas for each module, ...
-  for (moduleName in modules.list)
+  for (moduleName in moduleList)
   {
     // ... call the module's buildInitialGui() function
-    var module = modules.list[moduleName]["class"].getInstance();
-    module.buildInitialGui(modules.list[moduleName]);
+    var module = moduleList[moduleName]["class"].getInstance();
+    module.buildInitialGui(moduleList[moduleName]);
   }
 };
 
 
 qx.Proto.finalize = function()
 {
-  var modules = swat.main.Main.modules;
-
   // Call each module's finalization function
-  for (moduleName in modules.list)
+  var moduleList = swat.module.Module.getList();
+  for (moduleName in moduleList)
   {
-    var module = modules.list[moduleName]["class"].getInstance();
-    module.finalize(modules.list[moduleName]);
+    var module = moduleList[moduleName]["class"].getInstance();
+    module.finalize(moduleList[moduleName]);
   }
 };
 

Added: branches/SAMBA_4_0/swat/apps/swat/source/class/swat/module/Module.js
===================================================================
--- branches/SAMBA_4_0/swat/apps/swat/source/class/swat/module/Module.js	2006-12-28 03:33:52 UTC (rev 20375)
+++ branches/SAMBA_4_0/swat/apps/swat/source/class/swat/module/Module.js	2006-12-28 04:44:34 UTC (rev 20376)
@@ -0,0 +1,44 @@
+/*
+ * Copyright:
+ *   (C) 2006 by Derrell Lipman
+ *       All rights reserved
+ *
+ * License:
+ *   LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/
+ */
+
+/**
+ * This class defines a module descriptor (the registration of a module) and
+ * maintains the list of modules that have been registered.
+ */
+qx.OO.defineClass("swat.module.Module", qx.core.Object,
+function(moduleName, class)
+{
+  qx.core.Object.call(this);
+
+  // Initialize commonly-used properties of a module
+  this.canvas = null;
+  this.fsm = null;
+  this.gui = null;
+
+  // Save this class name
+  this.class = class;
+
+  // Add this new module to the module list.
+  swat.module.Module._list[moduleName] = this;
+});
+
+
+/**
+ * Return the list of modules
+ */
+qx.Class.getList = function()
+{
+  return swat.module.Module._list;
+};
+
+
+/**
+ * The list of modules which have been registered.
+ */
+qx.Class._list = { };



More information about the samba-cvs mailing list