Thursday, April 26, 2007

Synchronizing Views with a GEF Editor

View synchronizing is one of the fundamental features for most Eclipse workbench apps. When using a GEF editor, you can use additional views to provide more targeted information about the selection, or even allow editing. There is a lot of good information about this topic - both in the eclipse docs and in the newsgroups. However, I think I can augment that with a concise set of steps for getting this task done quickly.

In this post, I'll talk about how to easily allow views to respond to selection events in an editor.

  1. First, you will need to make sure events are being properly fired from your editor. Since a default selection provider is provided by the GEF Graphical Editor, this is handled for you if you are extending it.

  2. Next, you need to watch for these selection events in your views. This is done by simply adding a postSelectionListener to the page during createPartControl in the view:

  3. getSite().getPage().addPostSelectionListener(yourPageSelectionListener);

    It is important to note here that you can't use the other add method that allows filtering by workbench part. This does not work for editors. I have filed an enhancement request to get this added, but it wouldn't be until 3.4 at the earliest since 3.3 is at API freeze.

  4. If all you wanted was to get selection events of your edit parts, you're done. However, in my designs, I usually like to hide the edit parts from view outside the editor. For this, you will need to use the Eclipse adapter mechanism. In your edit part getAdapter method, you have the opportunity to do any pre-processing.

    Lets say that your edit parts are shapes and you want to find out the color, and size of them without exposing the edit parts to the view:
    1. First, put an interface in a shared plugin called: IShapeInfo with getters for color and size
    2. In Shape.getAdapter, when IShapeInfo is passed in, return an implementation that provides size and color. (You can implement IShapeInfo in Shape, create an anonymous inner class, etc.)
    3. In your view's pageSelectionListener:


//Get the selection as a list
StructuredSelection ss = (StructuredSelection) selection;
List sList = ss.toList();
/**
* Create a list of objects to show
*/
for (Iterator iterator = sList.iterator(); iterator.hasNext();) {
Object name = iterator.next();
//See if it implements IAdaptable
if (name instanceof IAdaptable) {
//See if the IShapeInfo is available as an adapter
Object o = ((IAdaptable)name).getAdapter(IShapeInfo.class);
if(o != null) {
IShapeInfo info = (IShapeInfo)o;
/** Now you can get size and color from the selected Object
}
}
}

Thats it. All you have to do is customize the interface and you can get custom information back from your edit parts - or any other selection - without exposing class details.

Read More...

Thursday, April 12, 2007

Current GEF Activity

Since I have been watching GEF progress closely, I got a nice surprise lately with a lot of Bugzilla activity. Even though the project plan still doesn't really contain any real detail, its nice to see bugs targeted at 3.3 milestone builds, as well as the final release. While I realize that this doesn't mean they will get fixed, its definitely a start. Thanks to the GEF Lead for taking the time to put this in!

For some reason, the GEF project seems to have really dropped in popularity over the last year - at least judging by the newsgroup activity and lack of project activity. As part of the community, I can take some blame for this since I haven't submitted any fixes. My 3.3 resolution is to find at least 1 bug for which I can provide a patch. I strongly encourage anyone interested in GEF to do the same!

Here is the list of bugs currently targeted at 3.3 if you're interested in helping.

Read More...

Thursday, March 15, 2007

GEF Updates and the Eclipse Project Info Process

Over the last few months, I have been getting increasingly frustrated at the lack of info I get about an Eclipse project that is really important to my work [GEF]. There is nothing in the project plan and nothing much targeted at 3.3. Even most things targeted at 3.2.2 weren't resolved or even updated as of the release. After getting little on the project newsgroup, I decided to post in the foundation newsgroup. I was a little apprehensive because I wasn't completely sure if this was appropriate, but soon after, I got a great response from David Williams:


I'll let GEF folks talk about GEF, but I'll speak to process. First, you did the right thing, just keep asking until you get an answer. First start with newsgroups, then a polite question on dev lists (if not response on newsgroups). And, if no response from dev list, then a not to a PMC member (or, the pmc mailing list) would probably be in order. I believe GEF is in the Tools project. Then, if no resposne from the PMC, the Eclipse foundation (this mailing list) is a good place. If no response there, you can bet the project will be "retired" as an inactive project soon -- which is _NOT_ the case for GEF. I know it is activly maintained, thought not sure they have lots of feature enhancements planned.
This stuff may seem like common sense to long time Eclipse developers, but at least for me, its nice to see it written down so others can follow it.

Read More...

Tuesday, March 13, 2007

Couple of Vista Utils

I found a couple of things that make life with Vista easier. The first is Start++, made by one of the MS devs. It adds some nice shortcut functionality the the start menu. The second is already built-in, but I was waiting on a Powertoy to do it. If you like the "Command Prompt From Here" powertoy, all you have to do to duplicate this functionality in Vista is Shift-Right_Click on a directory and select it from the context menu. Note that this only works in the right pane.

Read More...

Saturday, February 10, 2007

Eclipse 3.3M5 on Vista

So I just finished installing Vista on my work laptop (mostly so I could see the improvements Eclipse made for Vista support) and I have to say I'm really impressed with both. First, there are tons of new things in M5, like the new forms, splash, etc, that are really nice. As for Vista - it installed in about 30 minutes with no problems and all my programs, shortcuts still work. I'm still checking the performance, but so far, I haven't noticed any problems.

Read More...

Thursday, February 8, 2007

Finally - A Great UML Tool

Over the course of my career, I have tried to use UML several times. The one problem I kept having was that the tools did more to get in my way than ease documentation and development. Since starting a new job with a bigger team, I started feeling [again] that UML would really ease the development of the new products.
Since I work for a small startup - I evaluated all of the OSS tools I could find. I ended up with all of the old problems. Then, I was taking a look at the latest edition of my favorite java book and the author mentions this one. I have been trying it on an eval basis and so far, I'm really impressed. Now if I can only get the budget for some licenses...

Read More...

About

Since I've been using Eclipse for a good while now to develop software products, I decided that its time I had some space to keep track of stuff I want to remember. If anyone else reads this and it causes some healthy debate, that will definitely be a great side benefit. If that happens once I get some useful material here, I may ask to be added to the roll over at Planet Eclipse.

Read More...