Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 385165

Summary: Custom Theming problem with the Lightweight OSGI setup for RAP
Product: [RT] RAP Reporter: Kees Pieters <info>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: ivan, rsternberg
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Kees Pieters CLA 2012-07-16 08:03:54 EDT
Build Identifier: 20120614-1722

I am trying to get RAP running in a lightweight setting, according to the following blog post:

http://eclipsesource.com/blogs/2011/08/29/lightweight-osgi-applications-using-raps-widget-toolkit/

Everything seems to work fine, but when I try to add a theme id in the Webclient properties, I get an exception that my themeId does not exist. I have also tried the business / fancy themes provided by RAP plugins themselves, but with the same results.

After debugging, I found out that the themes DO get registered in the ThemeManager, but when the servlet is called from the browser , a new ThemeManager is constructed, which only loads the two default themes. all the themes that are defined in the extension registry are therefore no longer available.

This seems to me to be a lazy loading problem. I am using the most recent stable build of RAP 1.5.x, following the example of the blog post, with the only addition that I include the following line in the subclassed ApplicationConfiguration file:

   properties.put( WebClient.THEME_ID, S_THEME_ID );

S_THEME_ID being the theme id I have registered in the extensions.

Reproducible: Always

Steps to Reproduce:
1.Create a plugin project that runs with the org.eclipse.rap.rwt and org.eclipse.rap.rwt.osgi, and which registers an Applicationconfiguration using declarative services, as described in the blog post mentioned above
2.Register a custom theme in the extension registry
3.activate this in the subclassed ApplicationConfiguration file (properties.put( WebClient.THEME_ID, S_THEME_ID );
4: Create a debug/run configuration activating only the required plugins, the console and jetty (I have used the 2.8.2 SDK equinox version with the necessary RAP files included, and arguments to run jetty on localhost:8080
5: set breakpoints on the constructor of the ThemeManager and at the registration of themes of RAP and debug the plugin. all the themes are registered upon starting the debugger
6: set the browser to localhost:8080/simple. The ThemeManager is constructed again, without loading the registered themes
Comment 1 Kees Pieters CLA 2012-07-16 08:31:20 EDT
I have done some further debugging, and I see now that the applicationLauncher.launch method is called twice. The first time from

org.eclipse.rap.ui.internal.servlet.HttpServiceTracker

which seems to work fine, and then from

org.eclipse.rap.rwt.osgi.internal.ApplicationLauncherImpl,

which does not seem to register the themes.

Despite my previous post, this seems to happen in one sweep, so calling the servlet from the browser does not seem to matter.
Comment 2 Ivan Furnadjiev CLA 2012-07-16 08:45:40 EDT
Probably you have a workbench bundle mistakenly selected in your launch configuration. In order to register custom theme in a lightweight application use:
Application#addStyleSheet in your ApplicationConfiguration#configure method.
Comment 3 Kees Pieters CLA 2012-07-16 09:00:08 EDT
@Ivan

Even if this were the case, the second applicationcontext should still register the themes. We then would have a double applicationcontext -which is not very helpful-  but they should still work correctly. I have found out by now that the lightweight RAP-osgi example results in a double call to 

org.eclipse.rap.rwt.osgi.internal.ApplicationReferenceImpl.start();

This results in two applicationRunners and two applicationContexts, which gives
the afore mentioned problems. One applicationRunner is able to access the
themes, the other does not.

If I add the theme as you suggest, the FIRST themeManager is used (which already contains the theme) and therefore the method does not add the theme.
Comment 4 Kees Pieters CLA 2012-07-16 09:56:14 EDT
What I mean to say, that there are still two applicationRunners active. I suspect the initial one is started with org.eclipse.rap.ui, which evidently takes care of the workbench manner of working. If I remove the references to this plugin in my launch configuration, I only get one applicationRunner.

However, even in a lightweight osgi approach I would have no problem using extensions for themes and branding. The documentation also suggests that this should be done as well. I have seen no reference to Application#addStyleSheet in the docs I read so far. Besides this, if I use this method to add the stylesheet, then it does not become the currentTheme at runtime, so I still see the default theme.
Comment 5 Ivan Furnadjiev CLA 2012-07-16 10:33:25 EDT
It's not possible to use the new OSGi API together with workbench/ui bundles (see bug 377414). Do the following:
1. Don't use workbench/ui bundles and extension points
2. Register your application with the new OSGi API
3. Register your custom theme with the new OSGi API
4. Start your application
Comment 6 Ralf Sternberg CLA 2012-07-16 11:53:04 EDT
(In reply to comment #4)
> However, even in a lightweight osgi approach I would have no problem using
> extensions for themes and branding.

The themes extension point is located in the bundle org.eclipse.rap.ui, which is part of the old eclipse 3.x stack (it depends on and re-exports the workbench). You can use the extension registry together with the new API, but not the old extension points.

> The documentation also suggests that this
> should be done as well. I have seen no reference to Application#addStyleSheet
> in the docs I read so far. Besides this, if I use this method to add the
> stylesheet, then it does not become the currentTheme at runtime, so I still see
> the default theme.

If the documentation is misleading, we should fix it. Which part are you referring to?
Comment 7 Ralf Sternberg CLA 2012-07-16 12:24:14 EDT
Reopened by accident
Comment 8 Kees Pieters CLA 2012-07-17 05:30:28 EDT
(In reply to comment #7)
> Reopened by accident

Hi Ralf,

The errors are all mine ~). Being a newbie on RAP, I got confused with the various posts on the Internet regarding RAP. De development guide and the new and noteworthy listing on the RAP forums provide accurate info. Some other issues complicated stuff, but these are strictly speaking not part of the bug I reported.

I would like to compliment all of the RAP developers on making a very professional application, kudoos!
Comment 9 Kees Pieters CLA 2012-07-17 05:38:56 EDT
I think the main problem in the documentation is that when you start by setting up a light-weight osgi app, and then you move on to the RWT theming in the documentation, that things start to get mixed up. A note in that chapter, pointing to the programmatic inclusion of theme files, may be very helpful there.

Hope this helps