Build the e4 tools with “mvn clean install”

We finally made the build for the e4 tools as simple as possible. Just can now build the e4 tools which a simple “mvn clean install”. For the exact commands, please see Building Eclipse tutorial.

I think it is important to make the Eclipse build process as simple as possible and I think it is great that the build process for the e4 tools are now as simple as it can get.

See Bug report for the details on the fix. Many thanks to Paul Webster, Thanh Ha and Markus Kuppe for contributing this fix.

Posted in Eclipse, Lars Vogel | Tagged , , , | 1 Comment

Google Summer of Code at Eclipse

I would like to introduce myself. I’m Hendrik and currently I’m participating at the Google Summer of Code this year with a coding project at Eclipse.org.

The Google Summer of Code is a program by Google to motivate students (like me) to start working on Open Source projects. The whole program is organized by Google itself but the mentoring is done by volunteers of the Open Source projects. In my case I’m mentored by Lars Vogel and Markus Kuppe from the vogella GmbH and I also get support from John Arthone. After the project the students should have learned how to work at Open Source projects and be motivated to stay as committers or contributors in the Open Source community. With the successful completion of the project the participants are rewarded with a nice “pay check” from Google.

If you’re interested in the GSoC, you find more information at there site here and for Eclipse specific topics at the Eclipse Wiki .

But now to my project.

My accepted proposal with the title Implementing generics in JFace viewers is based on a feature-request/bug opened by Lars Vogel.

The reason for this bug is, that currently the JFace Framework does not support the Java generics feature, so the developers has to use typcastings to access there data in the viewers like in the following example:


col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Person p = (Person) element;
return p.getLastName();
}
});

While this works the casting has a big disadvantage. It does not ensure that your program is type safe, because the casting and the usage of the Object class allows the JVM only to determine the type of element object at runtime.

For example the the element object could be from the class Invoice which is not type compatible to the Person class. The program will compile, but the program will crash at runtime with a log like this:


Exception in thread "main" java.lang.ClassCastException: Invoice cannot be cast to Person

Hopefully the Exception will be raised at the testing phase, not in a sales presentation with an CEO attending.

Sure you can avoid this exception with an instanceOf like in the following example, but there is a good reason why a lot of programmers find this a little bit smelly.


combo.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if(element instanceof String){
String index = (String) element;
return index;
}else{
return "";
}
}
});

In this case the instanceof is even worse, because it will hide the potential problems. The change of the return “”; line to return null, will also get an exception and just wrote some boilerplatecode. With my project I want to fix this problem.

My task for the next three and a half months will be the implementation of the Java generics language feature for the JFace viewers.
This should help to avoid castings like in the first example. So the goal is to allow JFace users following coding.


col.setLabelProvider(new ColumnLabelProvider<Person>() {
@Override
public String getText(Person element) {
return element.getLastName();
}
});

To get started with the project I’ve committed a small change which will allow the usage of Java 1.5 within the org.eclipse.jface bundle. The change is based on the Bug #395213 and is committed to Gerrit

The next step will be the implementation of the generics feature for some smaller viewers like the ComboViewer and test them and the backwards compatibility. I also plan to look and document other things along the way if time permits.

If you’re interested in my project you find more information on my Google Summmer of Code proposal site here or on the Eclipse Wiki

Posted in Eclipse, Hendrik Still, Java, Other | Tagged | Leave a comment

SWT implemented with OpenGL in the Bling IDE

The cool guys at http://www.l33tlabs.com/ implement an IDE for game developers. They also in the process of implementing SWT with OpenGL and the result is pretty impressive.

Have a look at this video:

Pretty impressive. I hope they will make their SWT implementation available to others.

Posted in Eclipse, Lars Vogel | 3 Comments

Moved to new vogella server – Again

Even though we only moved a short while ago to a new server we again migrated to a bigger server to avoid performance bottlenecks. We now moved from a virtual host to a relatively strong root server and have done some load tests which have indicate that this server should perform much better.

We also spend some time in performance optimization of the server, so this one is not only bigger but also better tuned. One of the things we did was switching from mpm-prefork to mpm-worker for the Apache 2 HTTP server. We also learned a lot about the pagespeed Apache 2 module.

We also moved our blog URL to http://blog.vogella.com and our training offering to http://training.vogella.com, this allows us to move these PHP based sites transparently to a separate server if required in the future.

Let us know if you see any issues. Many thanks to Markus Kuppe who did the majority of the work and performance optimization.

Lars on behalf of the vogella team

Posted in vogella | Leave a comment

Ubuntu: How to move an application which is displayed offscreen

I use several monitors and sometimes an application, e.g. an Android emulator opens off-screen. I use the following approach to move it back to the visible area:

Use ALT+TAB to switch to the off-screen application
Press ALT-SPACE -> this shows the system menu, maybe the menu is not visible but you still can call its options
Press M to select the “Move” menu
Use the mouse or the arrow keys to move the application

Posted in Other | 1 Comment

Eclipse Papercut #14 Reduce delay in code completion

This is a fast preference settings tip. As you may know Eclipse triggers code completion for methods, fields and more. For example if you type the name of an object and a “.”, Eclipse offers via code completion the fitting methods and fields.

The current default value for triggering code completion is set to 200 ms, which is longer than in other IDEs, the most popular alternative one, uses a delay of zero. You can reduce this value to a lower one, for example I set it to “40″ which feels really good to me.

To set this value, use Window -> Preferences -> Java -> Editor -> Content Assists and set the “Auto activation delay (ms) to the new value.

Preferences _001

I hope this helps.

Posted in Eclipse, Lars Vogel, Papercut | 2 Comments

NatTable 1.0.0 released

Finally the long awaited Nebula NatTable 1.0.0 release is out. It took us longer than we initially planned, but as it is a the increase of the major version number indicates, there are plenty of enhancements included.

First of all, Nebula NatTable is now a mature phase project that is out of incubation with this release. This means that we demonstrated that we are an open-source project with an open and transparent process. We have an actively involved and growing community and provide Eclipse Quality technology which is proven by passing the Eclipse Release Review (Read more about the Eclipse Development Process here).

So what are the mentioned improvements? Let’s start with the infrastructural enhancements. We were active in working on our third-party dependencies and our build process. The NatTable extensions have dependencies to GlazedLists and Apache POI. As they weren’t available as OSGi bundles before, our build process had some workarounds which didn’t work out on the build server. With the update to GlazedLists 1.9 and the efforts on bringing GlazedLists and Apache POI into Eclipse Orbit, we were able to update our target platform and our build process. This enables us to provide automated builds for NatTable core and the extensions everytime we commit and push updates to the repository. These builds are available as SNAPSHOT releases to give users the opportunity to always use the latest developments. We also started to release the Javadoc. While our code is still not completely documented, we started working on that front within the classes we touched for 1.0.0, so we hope it will be helpful for our users to understand the codebase better.

There is a lot of new stuff and enhancement of the codebase at several places. One thing you won’t notice in your code, but definitely on using NatTable is the enhancement of the viewport to support smooth scrolling. While scrolling in NatTable was column/row based before, which means that on scrolling the table jumped cell wise, the scrolling is now pixel based, which increases the user experience on scrolling. It also enables the NatTable to support scrolling of cells that are larger than the available space, which was not possible before.

At the API side we cleaned up the code regarding editing. You shouldn’t notice them if you didn’t customize the editing behaviour by creating and using your own editing bindings or custom editors. The creation of new editors for the NatTable is now more straight forward as we extended the necessary interfaces and abstract implementations. These modifications allow to specify editors that open in subdialogs, and even support editors that are based on SWT or JFace dialogs.

There are several other enhancements and additions which are all related to stabilizing the codebase and the featureset, and making the usage and configuration of the NatTable as flexible as possible. The RowReorderLayer that was missing until now, a Excel like filter row and the possibility to set expand/collapse icons in a tree are just three notable enhancements.

For every enhancement and bug there is a corresponding ticket in Bugzilla. We resolved 122 tickets for NatTable 1.0.0 over the past months. So if you are interested in a detailed changelog you should have a look there. To get an overview of the notable changes you can also have a look at the New & Noteworthy page. There you will also find a link for the Bugzilla query to list the resolved tickets.

To all of our users that have waited so long for the 1.0.0 release, sorry for the delay. But we hope we can satisfy your needs and you are happy with using Nebula NatTable 1.0.0. It is always great to get feedback, so don’t hesitate with comments (and critics).

Posted in Dirk Fauth, Eclipse | 5 Comments

Eclipse Internationalization Part 2/4 – New Message Extension by Dirk Fauth and Tom Schindl

In my last blog post I explained the current available solutions for translating an Eclipse 4 application and what is wrong with them.

In this blog post I will show you a new solution for translating your Eclipse 4 application. This one is created as an OSGi service and gets rid of all the disadvantages of the existing solutions. The main idea and implementation was created by Tom Schindl, while I extended it to the current state, so we are writing this blog post together.

To use the services you need to install the latest E4 tools into your IDE or at least create a target-platform that contains the location to it. You could for example use the p2 update site for the E4 tools provided by vogella to get the latest version. (see here for more information http://blog.vogella.com/2013/03/12/eclipse-4-tools-update-sites-available-from-vogella/)

As the constant based solution has several benefits when used in combination with the tooling, e.g. code completion, refactoring and find references, the solution designed by Tom uses a similar approach. The big difference is, that it is not constant but member based. So using that solution is working on an instance of a message class, which means that it can be collected by the garbage collector if it is not referenced anymore and values can be changed at runtime.

Another advantage over the existing mechanisms is a more technical one. The existing translation mechanism in Eclipse is based on Java 1.4 and has some workaround code to deal with a special use case. What most people are not aware of is that the process on resolving a resource bundle is a little bit different than resolving a key out of a loaded resource bundle. Guess you have a loaded resource bundle for the locale de_DE, the search order for a key in that resource bundle looks like this:

  1. bundle_de_DE.properties
  2. bundle_de.properties
  3. bundle.properties

So it is searching from the most specific to the default bundle for that key. If the default bundle is configured to contain the English translations, if you missed to translate a key to German, the English one will be returned.

For resolving a resource bundle the process differs slightly with a huge impact. Guess you are running on a system that has the German locale set as default locale. Your application contains only the German and the default resource bundle files as shown above. What would you expect to get for translation if you set the application locale to fr_FR? Only knowing about the process above, you would expect to get the English translations out of the default resource bundle. But on resolving and loading the resource bundle, the default locale is used as fallback. So the following search order is used to resolve the bundle for fr_FR:

  1. bundle_fr_FR.properties
  2. bundle_fr.properties
  3. bundle_de_DE.properties
  4. bundle_de.properties
  5. bundle.properties

This means you will get the German translations on a German system if you try to localize your application to fr_FR and there are no such resource bundle files in your application.

In Equinox resolving the resource bundle was implemented like resolving keys without taking the default locale as fallback into account. That was reported and fixed a while ago (https://bugs.eclipse.org/bugs/show_bug.cgi?id=330602). A technical switch was introduced that allows to specify the equinox.root.locale as system property. If it is not set it will be treated as en by default. Now if the value for equinox.root.locale is en and the locale with language code en is requested, the default locale is not used as fallback.

Also the loading of resource bundles out of an OSGi bundle is a bit different because of the fragment support and the classloader per bundle. Using the Java 1.4 API dealing with all of these facts was quite difficult and caused the limitation that only properties based resource bundles are supported.

With Java 1.6 the ResourceBundle.Control class was introduced. It allows you to take control on how resource bundles are loaded, how the candidate locales are determined, e.g. using a fallback locale or not, and how the caching of the loaded resource bundles should be handled. The new message extension is based on Java 1.6 and makes use of this ResourceBundle.Control to deal with the described issues above in a more convenient way. Using the Java default mechanism instead of the custom workaround also enables the usage of class based resource bundles. The advantage of using class based resource bundles will be explained in the last blog post in this series.

To use the new message extension you need to add the org.eclipse.e4.tools.services bundle to the required plugins in your MANIFEST.MF. This bundle contains the OSGi services that are necessary for the new message extension and will give you access to two new annotations, @Message and @Translation.

To explain those annotations and their usage we first need to create the Messages class that will contain our translations.

public class Messages {
	public String label_message;
}

Comparing the implementation with the constant based OSGi NLS solution you will notice that

  • Messages is a POJO and does not implement or extend something
  • There are no constants but member variables
  • There is no static initialization block needed anymore

Now that we have the Messages class, we need to configure where to get the translation values that should be put into those member variables. As different developers have different opinions on where to put their resource bundles to, the new message extension supports a quite flexible approach to specify where the resource bundle files can be found. When processing the initialization, the mechanism searches for the resource bundle files in the following order:

  1. Check for a configuration via @Message annotation
    @Message(contributorURI=”...”)
    public class Messages {
    	public String label_message;
    }
  2. Check for resource bundle files with the same base name and in the same package as the Messages class
    NamedMessages
  3. Check for OSGi resource bundles configured in MANIFEST.MF
    If you placed your resource bundle files in OSGI-INF/l10n and named in bundle, there is nothing else you have to do

@Message annotation

The @Message annotation is optional and only necessary if you want to configure the location of the resource bundle files or the caching behaviour. To configure the location of the resource bundle files, you need to set the contributorURI parameter to the annotation. This parameter supports the following location patterns:

  • platform:/[plugin|fragment]/[Bundle-SymbolicName]
    Load the OSGi resource bundle out of the bundle/fragment named [Bundle-SymbolicName]
    For example:
    @Message(contributorURI="platform:/plugin/com.beone.e4.translation.extension")
    will load the OSGi resource bundle that is configured in the MANIFEST.MF of the com.beone.e4.translation.extension plugin
  • platform:/[plugin|fragment]/[Bundle-SymbolicName]/[Path]/[Basename]
    Load the resource bundle specified by [Path] and [Basename] out of the bundle/fragment named [Bundle-SymbolicName].
    For example:
    @Message(contributorURI="platform:/plugin/com.beone.e4.translation/resources/another")
    will load the resource bundle that is located in the folder resources/other in the com.beone.e4.translation plugin.
  • bundleclass://[plugin|fragment]/[Fully-Qualified-Classname]
    Instantiate the class based resourcebundle specified by [Fully-Qualified-Classname] out of the bundle/fragment named [Bundle-SymbolicName]. Note that the class needs to be a subtype of ResourceBundle.
    For example:
    @Message(contributorURI="bundleclass://com.beone.e4.translation/com.beone.e4.translation.resources.MockBundle")
    will load the class based resource bundle MockBundle in package com.beone.e4.translation.resources in the com.beone.e4.translation plugin.

Using the bundleclass contributorURI enables you to use class based resource bundles. What’s possible by implementing them will be explained in a later post.

While the constant based OSGi NLS translation mechanism had no chance to update the translation values at runtime and kept them in memory forever, you can specify the caching behaviour for messages in the new message extension. This is done by the referenceType parameter of the @Message annotation.

If the same translations are requested for injection at several places, for memory efficiency the same instance will be returned. This is achieved by internally caching the created instances as a SoftReference by default. As they are not hard references, once all requestors are garbage collected (e.g. the parts were closed) the message instance can be garbage collected as well. Using SoftReferences as default has the advantage that e.g. if a part is closed and opened again within a very short time, the message instance can be reused instead of being garbage collected and newly created. In case the default behavior does not suite your needs the @Message annotation provides the following caching/garbage collection strategies:

  • NONE: The message instance is not cached. Each requestor gets its own instance.
  • WEAK: The message instance is cached as a weak reference. If every requestor was garbage collected, the message instance is also discarded at the next garbage collection cycle.
  • SOFT: The message instance is cached as a soft reference. If every requestor was garbage collected, the message instance is not immediately discarded with the next garbage collection cycle, but will retain for a while in memory.

The strategy to use can be specified by setting the annotation parameter referenceType. The following for example will set the strategy to ReferenceType.NONE which means that every requestor will get its own instance of the messages class:

@Message(referenceType=ReferenceType.NONE)

@Translation annotation

After the messages class is created and connected to the resource bundle, it can simply be used by injecting the Messages instance with the @Translation annotation:

@Inject
@Translation
private Messages messages;
...
myLabel.setText(messages.label_message);

Compared with the TranslationService that is already available in Eclipse 4, you are injecting your Messages instance without the need to know the contributionURI of the containing bundle or the key of the translation you are requesting.

@PostConstruct annotation

With the latest implementation it is possibility to add methods annotated with @PostConstruct. Following the dependency injection rules, this method will be executed after the Messages instance is created. This allows you to use placeholders like with using the constant based NLS.bind() solution. Guess you have a property that looks like this:

my.label.message = {0} says {1}

You could initialize this property by adding a method annotated with @PostConstruct to your Messages class.

public class Messages {
	public String my_label_message;

	@PostConstruct
	public void format() {
		my_label_message = MessageFormat.format(
			my_label_message, "Dirk", "Cool");
	}
}

Note that the method annotated with @PostConstruct in the Messages class does not support parameters as it doesn’t support dependency injection at that place. This is quite the default behaviour when thinking of @PostConstruct in the JavaEE context. As @PostConstruct in Eclipse 4 generally supports dependency injection, we need to mention that in this special case it is not supported.

A small but personally huge improvement in properties key handling is the handling of the dot as property key separator. Using the constant based solution you need to use a separator that is valid within a Java variable, e.g. the underscore. This is because the dot is not valid as part of a field name and the binding from key to constant is directly without transformation. The new message extension at least supports the dot as key separator within the properties. So the properties can look like you know them from other Java frameworks. Of course you still can’t use it as separator in the fields. But as you can see in the example above, using the dot in the properties file is possible when using the underscore as separator in the Messages field.

Links:

Posted in Dirk Fauth, Eclipse, OSGi | 6 Comments

Removing the shopping and other unwanted lenses from Ubuntu

After playing with Ubuntu 13.04 for a while, I must say I really like it. I only dislike the lenses I don’t need.

But uninstalling them is straightforward.

sudo apt-get autoremove unity-lens-music unity-lens-photos unity-lens-gwibber unity-lens-shopping unity-lens-video

Posted in Other | 2 Comments

Getting the Eclipse New and Noteworthy information

If you are looking for the note and newsworthy notes of the Eclipse platform project you are potentially using Google to search for it.

This is not necessary, you can just clone the repository which contains this information.

git clone git://git.eclipse.org/gitroot/platform/eclipse.platform.news.git

You find the N&N for the platform in the “platform/4.3″ folder.

Posted in Eclipse, Lars Vogel | 4 Comments