summaryrefslogtreecommitdiff
path: root/swat/apps
diff options
context:
space:
mode:
authorDerrell Lipman <derrell@samba.org>2006-12-28 04:44:34 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:30:19 -0500
commit2bbf187698f6f2ec465173fd21078b4d27abc15b (patch)
treee0aa5c640b402ba1a4c9dcd88d1c8cb7e7360746 /swat/apps
parentd1d2651a373445e70ddaf61f3c4c83a6695e7b09 (diff)
downloadsamba-2bbf187698f6f2ec465173fd21078b4d27abc15b.tar.gz
samba-2bbf187698f6f2ec465173fd21078b4d27abc15b.tar.bz2
samba-2bbf187698f6f2ec465173fd21078b4d27abc15b.zip
r20376: make module registration substantially cleaner
(This used to be commit 466f17ea3c8fa4a0a93047abd3529651b4fc9bdc)
Diffstat (limited to 'swat/apps')
-rw-r--r--swat/apps/swat/source/class/swat/main/Gui.js21
-rw-r--r--swat/apps/swat/source/class/swat/main/Main.js67
-rw-r--r--swat/apps/swat/source/class/swat/module/Module.js44
3 files changed, 81 insertions, 51 deletions
diff --git a/swat/apps/swat/source/class/swat/main/Gui.js b/swat/apps/swat/source/class/swat/main/Gui.js
index bb302a73fc..8d18f5f38a 100644
--- a/swat/apps/swat/source/class/swat/main/Gui.js
+++ b/swat/apps/swat/source/class/swat/main/Gui.js
@@ -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 @@ qx.Class.buildGui = function(modules)
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 @@ qx.Class.buildGui = function(modules)
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 @@ qx.Class.buildGui = function(modules)
// 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 @@ qx.Class.buildGui = function(modules)
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.
diff --git a/swat/apps/swat/source/class/swat/main/Main.js b/swat/apps/swat/source/class/swat/main/Main.js
index 2ae58a0c61..85e2140215 100644
--- a/swat/apps/swat/source/class/swat/main/Main.js
+++ b/swat/apps/swat/source/class/swat/main/Main.js
@@ -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,29 +21,18 @@ function()
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);
/*
@@ -56,8 +43,6 @@ qx.Class.modules =
qx.Proto.initialize = function()
{
- var modules = swat.main.Main.modules;
-
// Set the resource URI
qx.Settings.setCustom("resourceUri", "./resource");
@@ -65,44 +50,44 @@ qx.Proto.initialize = function()
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]);
}
};
diff --git a/swat/apps/swat/source/class/swat/module/Module.js b/swat/apps/swat/source/class/swat/module/Module.js
new file mode 100644
index 0000000000..e1f02caaba
--- /dev/null
+++ b/swat/apps/swat/source/class/swat/module/Module.js
@@ -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 = { };