11 February 2011

RAP: Useful snippets

Just want to record some handy code snippets...

Save/Restore workbench state

In the Application WorkbenchAdvisor


/**
* set auto restore of workbench state
*/

public void initialize( IWorkbenchConfigurer configurer ) {
    getWorkbenchConfigurer().setSaveAndRestore( true );
    super.initialize( configurer );
}

10 February 2011

RAP: App suddenly stopped working

I edited the Preference feature in my app and could not start the app. I was getting the following error:

java.lang.IllegalArgumentException: no layout registered with default id (LayoutRegistry.DEFAULT_LAYOUT_ID) or no layout activated over branding extension.
at org.eclipse.rap.ui.interactiondesign.layout.ElementBuilder.<init>(ElementBuilder.java:96)
at org.eclipse.rap.internal.design.example.builder.DummyBuilder.<init>(DummyBuilder.java:23)
at org.eclipse.rap.internal.design.example.managers.CoolBarManager.<init>(CoolBarManager.java:140)
Turns out that the cookies have got themselves in a muddle and need to be deleted. I don't like to delete all my cookies so I (in IE8) opened Tools -> Internet options -> Browsing history -> Settings -> View files. This shows all the temp files. I sorted by last changed date and deleted the files which looked like 'Cookie@127.0.0.1'

Then it all worked again.

09 February 2011

RAP: First deploy to WebSphere

It didn't work first time but it didn't take too long to get the first results. This is what I did.

  • Ensure RAP WAR Products feature installed -- http://wiki.eclipse.org/RAP/Equinox_WAR_products
  • Create a new WAR Product Configuration in the plugin project. New -> Other... -> Plugin Development
  • Select parent folder, name the product and choose the lauch configuration
  • Open the WAR product file and enter an ID and Name
  • On the configuration page add the JARs used by the project
  • Return to the Overview page and select Validate
  • If necessary, add the missing plugins or JARs
  • Start the export wizard and enter the name of the output file. Press Finish.
  • The WAR file has now been exported
  • Open the Websphere Integrated Solutions Console
  • Create new Application Server. I called it RAP_TEST.
  • I had to modify a few ports because the defaults clashed with other App Servers
  • Install new Enterprise Application and enter the name of the WAR file
  • Accept all defaults and enter a context root such as /apps/rap
  • Finish
  • Might need to sync nodes etc but should now work
  • <servername>/apps/rap/fair?startup=fair (in my case)
So, my app kind of works. Unfortunately, the whole branding is missing so there are no images, styles etc. When I find the cause, I'll post more here.

Missing images problem

I set up a simple Tomcat server to check that it wasn't a WAS problem. I then noticed that there was an exception in the logs. Something to do with Jetty and an 'Address already in use' bind error. I was surprised that Jetty would be active on the Tomcat server so I checked my plugin dependencies. In the end I removed all the dependencies and added the 'Required plugins'. That seemed to cure the problem. After redeploying, there were no Jetty exceptions and I get the images which were missing.

08 February 2011

Strangeness(?) with RAP i18n

Just made my first attempt to add multi-language support to my RAP app. I created a default bundle for English and then one for German.

messages.properties
messages_de.properties

My browser was setup to accept German and English in that order so I got the German texts. I then swapped the language prefs in the browser to put English first but I still got German. I tried closing the browser, restarting the app etc. but I still got German. Finally, I added a new bundle, messages_en.properties and now I get English.

Is this the correct behaviour? It is not what I expected but I guess nothing is known about the default bundle and the browser is saying that German is acceptable (if not preffered), Hmmm...


UPDATE
the explanation is as follows:

your VM is set to German, right? What happens is that the
Browser asks for English, but RWT does not find a messages_en.properties
file. So it tries the default locale, in your case German and Bingo!
there is a messages_de.properties file. So you get German. If you want to
have English as your fallback, set your VM to English. Does this explain
the behavior?

Regards, Ralf

--
Ralf Sternberg

I18n in RAP. What a chore!

I18n is bad enough, but in RAP there is even more typing to do :-(

You need to create a Messages class and add a public field for every string you need to translate. You then have to create a properties file for each language and add the texts. The convention for key names is Classname_fieldname.

For example:

Messages.java
...
public String MyView_controltext;
...

Messages.properties
...
MyView_controltext = Hello World
...

MyView.java
...
control.setText(Messages.get().MyView_controltext);
...

I made life a liitle easier by adding a template. Window -> Preferences -> Java -> Editor -> Templates -> New...
Name = msg (or whatever you like)
Pattern = Messages.get().${enclosing_type}_${cursor}

Now I can just type 'msg' <Ctrl>+Space and I get most of what I need.

I can also recommend the Eclipse ResourceBundle Editor at http://sourceforge.net/projects/eclipse-rbe/.