Hello Dann,
what would be the advantage of the object registry over just using
global variables? If you omit the "var" before the variable declaration,
you can access your widget from anywhere...
function foo()
{
globalWidget = new QxWindow;
}
function bar()
{
globalWidget.open();
}
C.
Danny Adair schrieb:
Hello,
If you want to access objects by a user-defined name from anywhere,
use the code below (ObjectRegistry.js).
Yesterday, I wanted to access a qooxdoo object from a function which
hadn't created it.
Unfortunately, qooxdoo doesn't seem to support that at this stage (and
iterating through children and checking, e.g., their label/value is
certainly not a real option).
Google led me to QxObjectDatabase, and that's what this code is based
on: User-defined strings are mapped to qooxdoo "unique id"s (the
hashcodes in QxDatabase). I'm not into Javascript (excuse my Python
indentation style) so I'm sure this can be improved. I didn't do any
error handling.
Hope this will help others.
Cheers,
Danny
[EMAIL PROTECTED]
/*
Object Registry
Usage:
1. Create a global registry object, e.g.
var object_registry = new ObjectRegistry();
2. To register an object under a name, use
object_registry.set(some_object, 'some object')
3. To access an object under its registered name (from anywhere), use
obj = object_registry.get('some object')
Advanced Usage:
You can register ObjectRegistry objects to create "sub registries":
1. Create a new ObjectRegistry object (does not need to be global), e.g.
var sub_registry = new ObjectRegistry();
2. Register the new sub registry with the global registry, e.g.
object_registry.set(sub_registry, 'my sub registry')
3. To register objects with the sub registry, use
sub_registry.set(other_object, 'other object')
4. If you don't have the sub registry in your scope and want to register
an object with it, access it through the global registry first:
object_registry.get('my sub registry').set(other_object, 'other
object')
5. Correspondigly, to access an object registered in the sub registry,
use
obj = object_registry.get('sub_registry').get('other object')
*/
function ObjectRegistry()
{
this._mapping = {};
};
ObjectRegistry.prototype.set = function(obj, id)
{
if (obj instanceof ObjectRegistry)
{
this._mapping[id] = obj;
}
else
{
this._mapping[id] = obj.toHashCode();
};
};
ObjectRegistry.prototype.get = function(id)
{
var entry = this._mapping[id];
if (entry instanceof ObjectRegistry)
{
return entry;
}
else
{
return QxObjectDataBase[entry];
};
};
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache
Geronimo
http://sel.as-us.falkag.net/sel?cmd_______________________________________________
Qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel