Monday, October 8, 2007

Eclipse Summit 2007

I'm going to Eclipse Summit Europe 2007

I think there is no words more needed.

Tuesday, October 2, 2007

PDE enhancement

As you probably know we've just finished Eclipse Summer School workshops. It was great time, but now we are back to work. Recently I'm working on new PDE enhancement called "Convert jars to Plug-in Project". How it works, you can select jars in your project and transform them into plug-in project. You can also decide to change references in other project, that contains that jar's, to the new project.

It still needs some work but you can take a look and put your comments in bugzilla.

But this is only context to issue I want to share with you :).
As we all know laziness is a bliss and good programmer is a lazy one. I decided to put it into life when working on this bug. I needed to filter a list of jar files to finds a duplicates. Two jars are the same when have the same manifests (this is only an assumption for this project). This is a great occasion to use TreeSet. I've written a comparator for jar files but I didn't know what to do when two manifests are different. I followed the rule from the beginning of this paragraph and decide that when two manifest are different then result of comparison is jar1.hashCode() - jar2.hasCode(). Of course it couldn't work and I've spent a hour to find what is going on.
So I decide to change my paradigm of good programmer: "good programmer is lazy one but have to know what he is doing".

Custom Property Source for EMF generated RCP application

Have you ever tried to generate your application using EMF? If yes, you have probably noticed, that EMF puts standard editors for properties. For testing purposes this is enough, but for commercial application... well... answer yourself.

In this post I will show you how to generate simple date editor for the EMF application.
Here is the model:

As you see, it is not very complicated. If we generate RCP appliaction we will receive something like that:

and additional three plugins in your workspace (.edit, .editor, and .tests).

So we start to work.

In the pluging .editor we open our application Editor, and then, in the method getPropertySheetPage() we replace the

propertySheetPage.setPropertySourceProvider(new AdapterFactoryContentProvider(adapterFactory));


propertySheetPage.setPropertySourceProvider(new CustomizedAdapterFactoryContentProvider(adapterFactory));

Such a class does not exists, so we have to create it (it should extend AdapterFactoryContentProvider) and override method createPropertySource:

protected IPropertySource createPropertySource(Object object,
 IItemPropertySource itemPropertySource) {
            return new CustomizedPropertySource(object, itemPropertySource);

We do not have CustomizedPropertySource yet, so we create one, and override
createPropertyDescriptor() method:

protected IPropertyDescriptor createPropertyDescriptor(
IItemPropertyDescriptor itemPropertyDescriptor) {
      return new CustomizedPropertyDescriptor(object, itemPropertyDescriptor);

We do not have one. We have to create it and override createPropertyEditor, finally;):

public CellEditor createPropertyEditor(Composite composite) {
   CellEditor result = super.createPropertyEditor(composite);
   if(result == null) return result;
   EClassifier eType =         ((EStructuralFeature)itemPropertyDescriptor.getFeature(object)).getEType();
   if (eType instanceof EDataType) {
      EDataType eDataType = (EDataType) eType;
      if(eDataType.getInstanceClass() == Date.class){
         result = new ExtendedDialogCellEditor(composite, getEditLabelProvider()){
             protected Object openDialogBox(Control cellEditorWindow) {
                final DateTime dateTime[] = new DateTime[1];
                final Date[] date = new Date[1];
                Dialog d = new Dialog(cellEditorWindow.getShell()){
                   protected Control createDialogArea(Composite parent) {
                      Composite dialogArea = (Composite) super.createDialogArea(parent);
                      dateTime[0] = new DateTime(dialogArea, SWT.CALENDAR);
                      dateTime[0].addSelectionListener(new SelectionAdapter(){
                          public void widgetSelected(SelectionEvent e) {
                              Date dateValue = new Date();
                              date[0] = dateValue;
                      return dialogArea;
               if(d.getReturnCode() == Dialog.OK){
                  return date[0];
               return null;
   return result;

In this method we provide date property editor, but also we have to check, if the property is editable and if it is really a date, because our method will take care about all properties. So, if this is not a date, we pass everything to the super implementation.

And voila :) Here it is:

So, to sum up: you modify your editor to use subclassed AdapterFactoryContentProvider that will return subclassed PropertySource that will return subclassed PropertyDescriptor that will create your desired cell editor.

Hope that will help you :).

Monday, October 1, 2007

Tips & Tricks for debugging in Eclipse

During the Eclipse Summer School, which took place last week at our university, I had a chance to be a tutor. On Thurdsay I had classes about debugging in Eclipse. People were very eager to learn new things about the Eclipse debugger, so they asked me questions, thanks to which I had a chance to remind (and learn) myself some tricks in the debugger . So I thought that maybe not everyone knew about new features available in Eclipse 3.3 or even about features that had been in Eclipse for ages. Here are the features I find most interesting (and not so obvious):

1) Debug details formatter

When you debug your application you probably use the Variables view. One of the disadvantages is that you cannot see the data inside complex objects (unless they implement toString() method). Eclipse allows you to write your own formatter for displaying the content you are interested in. You can do it in the Eclipse preferences under Java->Debug->Detail Formatters.

Lets consider the following class:

When you want to check the value of the an object of this class during the debugging session you have to expand the object and inspect the value of all it’s parts. (see the picture below).

Let’s write our own formatter:

And now in the Variables view we can see that the person object is shown differently:

If you want to see the formatter in the labels for variables you have to select the following option in the Eclipse preferences:

This allows you to see the result of your formatter in the value field of the Variables view:

I find this option very useful also for the standard classes (e.g. ArrayList), then instead of:

I can see:

2) Toggling class breakpoints on the class without the source code

When you want to stop the execution of your application in the moment when some of your class is loaded by the class loader you can use the class breakpoints (just toggle the breakpoint on the line when the declaration of the class begins). But what about the situation when you want the same behavior when a class, which you don’t have the sources for, is loaded? How to toggle such a breakpoint without the source code? Actually this was the question from one of our students and I had no idea how to answer it. Fortunately Jacek was in the room with me and he found the answer very quickly. You just have to go to the main menu and choose Run->Add Class Load Breakpoint…

3) Displaying all references of an object (new in Eclipse 3.3)

Sometimes it is worth to see all references of some object. How to achieve this? There are two ways of doing this. If you want to display references of the specific object, right click on the object in the Variables view and choose All References. The popup window will appear with all references. If you want to see all references of all available objects go to the menu in the Variables view and choose Java->Show References.

4) Displaying all instances of a class (new in Eclipse 3.3)

If you want to see all instances of a class just mark this class in the Java editor and choose All Instanced from the context menu.