Eclipse ZEST, custom figures and nodes size

You may already know Eclipse ZEST, the Eclipse Visualization Toolkit.

I am currently trying to build an EIP editor with it.
Normally, it is not intended to create editors but to visualize graphs. However, by adding commands to manipulate the model behind the graph, and associated with a good architecture (e.g. MVC), it is possible to do a simple editor. There are still some little things that are hard to do. Actually, I am wondering if I should not completely move to GEF. What I like the most with ZEST, is the JFace approach, that you do not have natively with GEF.

Anyway…
For Enterprise Integration Patterns, my model is made up of 3 concepts: EIP nodes, Petals end-points and connections between nodes.
Because I did not wanted to use the default ZEST node shapes (even with a label and a decoration icon), I customized my label provider to provide specific shapes for my nodes. This is achieved by making your label provider implement org.eclipse.zest.core.viewers.IFigureProvider.

/*
 * (non-Javadoc)
 * @see org.eclipse.zest.core.viewers.IFigureProvider
 * #getFigure(java.lang.Object)
 */
 public IFigure getFigure( Object element ) {

 	IFigure result = null;
	if( element instanceof EipNode ) {
		result = new EipFigure((EipNode) element);

	} else if( element instanceof EipEndpoint ) {
 		result = new EndpointFigure((EipEndpoint) element);
 	}

	 return result;
 }

The problem is that with a HorizontalLayout algorithm, the nodes are resized and do not appear entirely on the graph viewer.
Or if you pass LayoutStyles.NO_LAYOUT_NODE_RESIZING to the layout, the nodes are not visible at all.

I first though I had to create my own layout. But eventually, I found a better solution.
First, pass LayoutStyles.NO_LAYOUT_NODE_RESIZING to your layout.
And then, set the size of your figures to (-1, -1).

/*
 * (non-Javadoc)
 * @see org.eclipse.zest.core.viewers.IFigureProvider
 * #getFigure(java.lang.Object)
 */
 public IFigure getFigure( Object element ) {

 	IFigure result = null;
	if( element instanceof EipNode ) {
		result = new EipFigure((EipNode) element);
 		result.setSize( -1, -1 );

	} else if( element instanceof EipEndpoint ) {
 		result = new EndpointFigure((EipEndpoint) element);
 		result.setSize( -1, -1 );
 	}

	 return result;
 }

The nodes will take the size their figures need.

Get WSDL schema elements with WSDL4J

Just a very short snippet to show how one may access schema elements from a WSDL definition by using WSDL4J.

javax.wsdl.xml.WSDLReader wsdlReader11 = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLReader();
Definition def = wsdlReader11.readWSDL( wsdlUri );
for( Object o : def.getTypes().getExtensibilityElements()) {
	if( o instanceof javax.wsdl.extensions.schema.Schema ) {
		org.w3c.dom.Element elt = ((javax.wsdl.extensions.schema.Schema) o).getElement();
		// Navigate in the DOM model of the schema
		// You can use Schema#getImport() to work with imports
	}
}

Obviously, one better approach could be to get the schema object from WSDL4J and pass it to a XML schema parser then, instead of navigating in the DOM model.
Anyway, I tried this approach, but it is quite heavy then. I will most probably migrate to EasyWSDL as soon as the next release is online. In a first time, it will replace WSDL4J for WSDL 1.1. And later, it should also replace Apache Woden for WSDL 2.0. I think I will talk in details of that soon.

Petals Link @ OW2 Conference – November 2010

While I am blogging, let me seize the occasion to mention the talks some of my colleagues gave last week at the OW2 conference 2010.
This annual event was hold this year at La Cantine in Paris and lasted two days. The conference mainline theme was Open Source for Open Clouds.

I was not there, so I cannot give a lot of feedback.
However, the talks were filmed and the video are available here.

Among them, there is the one of Pierre-Yves Gibello, who presented the work made on PRESTO.
PRESTO is a communication protocol based on WS Reliable Messaging (WS-RM) and powered by French Government and Administration.
It is made up of a common library (a kit), that should be able to interoperate with several Software (and this is why Microsoft and Oracle also try to support it).
Petals Link is involved in both the development of the kit and in the development of a Petals connector for PRESTO.
You can watch this talk here.

The second talk for Petals Link was made by Christophe Hamerling about Petals and Cloud Computing.
The presentation is based upon the work that has been done in a European Research project called SOA 4 All. This project focus on both large-scaled service deployments (at the Internet scale) and on Web semantics. But it also defined the foundations of the usage of Petals in cloud solutions. These foundations also contribute to the OW2 Cloud Initiative (Christophe being among the technical leaders of this initiative).
You can watch his talk here. And take a look at his blog for more feedback about the conference.

Eclipse menus and unwanted contribution items

I have just faced a problem with Eclipse menus.
Because I did not find a simple solution, I had to use mine and I decided to share it here.
It is not elegant, but it works.

The problem

I have created a multipage editor. And one of the pages is a simple composite that embeds a ZEST diagram.
And I want to have a contextual menu on this diagram.

So, I registered it on the composite using:

MenuManager menuMgr = new MenuManager() ;
final Menu menu = menuMgr.createContextMenu( this.graphViewer.getGraphControl());
this.graphViewer.getGraphControl().setMenu( menu );
this.eipDesigner.getSite().registerContextMenu( menuMgr, this.graphViewer );

It allows me to register menu items from commands in my plugin.xml (using the org.eclipse.ui.menus extension-point).
Unfortunately, my menu contains items that do not make sense for my editor (Run as, Debug as, Compare with…).
These items are contributed by other plug-ins that I cannot get rid off (they are required).

The solution

After looking at the code that populates the menu from plug-in contributions, I found a light way to filter the displayed items.

MenuManager menuMgr = new MenuManager() {
@Override
public IContributionItem[] getItems() {

  IContributionItem[] items = super.getItems();
  List<IContributionItem> filteredItems = new ArrayList<IContributionItem> ();
  for( IContributionItem item : items ) {
      if( item != null
           && item.getId() != null
           && item.getId().startsWith( "com.ebmwebsourcing." ))
         filteredItems.add( item );
  }

  items = new IContributionItem[ filteredItems.size()];
  return filteredItems.toArray( items );
  }
};

final Menu menu = menuMgr.createContextMenu( this.graphViewer.getGraphControl());
this.graphViewer.getGraphControl().setMenu( menu );
this.eipDesigner.getSite().registerContextMenu( menuMgr, this.graphViewer );

And it works.
I only have to make sure my contributions have a valid ID.