Showing posts with label RCP. Show all posts
Showing posts with label RCP. Show all posts

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

Monday, July 30, 2007

Eclipse RCP

I recently decided to upgrade my skill set and add Eclipse RCP to my list of things I almost know how to do. I purchased a book on the subject and gave it a whirl.

The book exhorts you to have two environments; one for you development environment and one for your deployment environment. I already had the Eclipse JAVA development environment at 3.3 so I downloaded RCP and installed it into a new directory. After this, you must go into window-preference then expand Plug-in Development->Target Platform to set your target platform to the RCP install location. I found I had to reselect all the Plug-ins it found in the RCP install location.

Next you create your project and the plug-in. The book left out the important step of configuring the environment the first time you use the RCP installation target. This is ignored in most tutorials (or is new in 3.3) due to the fact that the writers already have their environment set properly at the time the tutorial was developed.

The first thing that bit me was that there are subtle changes in the 3.1 to 3.3 versions of RCP. When you create your first plug-in, you'll find that IApplication no longer has a run() method. These have now been switched to start() and stop(). This, of course, blows the code compare function given by the book since the code base for 3.3 is different from 3.1. I grit my teeth and plow ahead.

Your first tutorial doesn't do much but pop up a screen. When you generate the plugin you get the following java files: Application, ApplicationActionBarAdvisor, ApplicationWorkbenchAdvisor, ApplicationWorkbenchWindowAdvisor, and Perspective.

Application.java is called at startup. Think of it as your entry point into the plug-in.

Perspective.java is where you create any views or editors you want the users to see when the plug-in is first invoked.

ApplicationWorkbenchAdvisor.java handles the GUI event loop. It has the following methods that can be overridden.
  • initialize() - called first to do such things as parse the command link, register adapters, and declare images
  • preStartup() - called after initialize but before the first window is opened.
ApplicationWorkbenchWindowAdvisor handles the windows customization like titles, placement and size.

ApplicationActionBarAdvisor creates and customizes information in the menu bar, cool bar (called tool bar most places) and the status line.

I've finished my first tutorial now and and off to the second. I'll post my problems and solutions here as I run into them

It had issues as well but I was able, in the end, to get it working in 3.3. This is the first tutorial. It has links to two others.

Good Luck (you'll need it)