Thursday, August 2, 2007

Eclipse RCP 2 (a noobs account)

I'm going through the book Eclipse Rich Client Platform by McAffer and Lemieus and have been beating my head against the wall for a bit. In chapter four, they have you create an application named Hyperbola using the Hello RCP template. That all went well as I happily navigated the tutorial.

Now, here comes the part where I'm a bonehead. The book shipped with JDK 1.4 and Eclipse 3.1. The current version I'm using is Java 1.6 and Eclipse 3.3. Like an idiot I decided to try to navigate the book using the more recent distros. After all, who wants to use old stuff.

I noted some differences in my last blog about how things have changed. Well, here's another to add to the list. In chapter four they showed you how your plugin could remember the size and location of its window the last time the plug-in ran. Well, I left that in and spent a while trying to figure out why the tutorial in chapter five wouldn't work.

So, now for what went wrong.

When you use the Hello RCP template to generate a plug-in, it creates several java files. One of these is named ApplicationWorkbenchAdvisor.java. In chapter 4 they had you make the following modifications to that file.

public void initialize(IWorkbenchConfigurer configurer) {
// TODO Auto-generated method stub
configurer.setSaveAndRestore(true);
//super.initialize(configurer);
}

Well, for some reason when you make this change, it never calls createInitialLayout in Perspective.java which is what adds the new view to your perspective. So far I've tried running the configurer.setSaveRestore to true before and after the super class constructor but nothing seems to work.

I did eventually find a work-a-round at CT Armstrong's Blog. You can either delete the workbench.xml file from your target env or go to Run->Open Run Dialog and check Clear under Main->Workspace Data. You'll want to turn this back off or else you'll never save the position and size of your plug-ins window. The final version of my initalize method looks like this.

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



Good Luck(you'll need it)
Drifter

1 comment:

Anonymous said...

Great! Thanks!! I have spend 3 hours looking whats going one, why configurer.setSaveAndRestore(true)doesn't work!