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.

2 thoughts on “Eclipse ZEST, custom figures and nodes size

  1. Hi,
    Thanks for the Example…. I am using a similar way in my Application (usage of IFigureProvider). However, the method getFigure() only gets called for the Nodes and not for the Connections. Any idea what may be going wrong here?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s