As of 0.0.2-SNAPSHOT, Moomba now includes support for multiple "applications". This means you could effectively run a Cooee app on top of Moomba without it actually using the Moomba Workbench at all.
Note: This functionality is currently only available under OSGI.
This is enabled through the implementation and service export of the IApplication interface. This has been based around the Eclipse RCP, and is essentially the same interface you'd implement using the RCP. The interface looks like this:
public interface IApplication { /** * Exit object indicating normal termination */ public static final Integer EXIT_OK = new Integer(0); /** * Exit object requesting platform restart */ public static final Integer EXIT_RESTART = new Integer(23); /** * Exit object requesting that the command passed back be executed. Typically * this is used to relaunch Eclipse with different command line arguments. */ public static final Integer EXIT_RELAUNCH = new Integer(24); /** * blah blah blah */ public Object start(IApplicationContext context, Display display) throws Exception; /** * blah blah blah */ public void stop(); /** * Returns the unique ID for this application * This is a Moomba specific method, and may be changed once * the full API has been implemented * * * @return */ public String getApplicationId(); }
The key method here is public Object start(IApplicationContext context, Display display) throws Exception; As at 14 June 07, only getApplicationId() is also used. The parameter IApplicationContext will currently come in as Null until i work out a way to utilise it ![]()
*BE AWARE: It is highly likely this interface will change before the final release of Moomba 1.0. * That said, its actually not likely to be a big change.
The best way to look at how we implement this interface is by an example.
A problem we had on a seperate project was how to create a Login screen for the workbench - a very common use case. Under the RCP, you would implement the IApplication interface to call a login screen, and if authentication is successful, delegate to the workbench. This does essentially the same thing:
public class MyApplication implements IApplication, BundleActivator { LoginDialog loginDialog; static BundleContext bundleContext; public String getApplicationId() { return this.getClass().getName(); } public Object start(IApplicationContext context, Display display) throws Exception { loginDialog = new LoginDialog(display); loginDialog.open(new IWindowCallback() { public void windowClosed(int returnCode) { if (returnCode == LoginDialog.DISPLAY_WORKBENCH) { Display.getCurrent().removeAll(); PlatformUI platform = getPlatform(Display.getCurrent()); } } }); return null; } private PlatformUI getPlatform(Display display) { PlatformUI p = new PlatformUI(bundleContext); p.init(display); return p; } public void stop() { // Not implemented } public void start(BundleContext arg0) throws Exception { bundleContext = arg0; } public void stop(BundleContext arg0) throws Exception { // Not implemented } }
So what is this code doing?
Firstly, this piece of code is two things, both an IApplication and a BundleActivator. Being a bundle activator, it will be called when its parent bundle is activated by the OSGI framework. When this happens, it will take a reference to the bundle context. The bundle context is then later used to start the workbench.
As an IApplication, Moomba will look for it as a service. When it finds it, it will register it in its application registry. Once at least one IApplication is registered, Moomba will no longer fire its default IApplication implementation (which just runs the workbench). When a user hits the PlatformApplicationInstance servlet, it will start the IApplication, passing in the current "Display" (or in Cooee land, Window) for the application to add its components to.
Be aware, Moomba currently only supports one running application at a time. As such, it will run the first application it finds excluding the default one.

Add Comment