i'm writing an eclipse plugin that draws a finite state system. since it may be large, i'd like to attach some existing graph layout algorithm (e.g. hierarchical layout, force-based layout, ...) that automatically optimize the system visualization.
is there a way to integrate the plugin i'm writing (written using GEF) so that generated edit parts could be place on the editor area following some of the common graph layout algorithms?
i've found this interesting article but instead of optimizing edit parts visualization, it focuses on drawing a completely new graph.
so far what I'm doing is adding the following code (based on Zest 1)
private static void createNewGraph(String autName) {
Shell tmpShell = new Shell();
currGraph = new Graph(tmpShell, SWT.NONE);
mapStateAndNodes = new HashMap<State, GraphNode>();
}
private static void addGraphNode(State currState)
{
GraphNode newNode = new GraphNode(currGraph, SWT.NONE, currState.getName());
mapStateAndNodes.put(currState, newNode);
}
private static void addGraphConnection(Transition currTrans)
{
GraphNode source = mapStateAndNodes.get(currTrans.getOrigState());
GraphNode dest = mapStateAndNodes.get(currTrans.getDestState());
GraphConnection newConn = new GraphConnection(currGraph, SWT.NONE, source, dest);
}
private static void completeGraph()
{
currGraph.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
}
and while building my model, I also call createNewGraph(...)
, addGraphNode(...)
, addGraphConnection(...)
and completeGraph(...)
. the problem is: after currGraph.setLayoutAlgorithm(..., true)
that true
means it should apply the algorithm and place the objects in the "right" order. at this point (as suggested from some reader), it is possible to extract the computed coordinates through a GraphNode.getLocation()
method. unfortunately after setting a layout and applying it, all the states have Point(0,0)
as their location. i also found this comment:
/**
* Runs the layout on this graph. It uses the reveal listener to run the
* layout only if the view is visible. Otherwise it will be deferred until
* after the view is available.
*/
public void applyLayout() {
...
}
in org.eclipse.zest.core.widgets.Graph
sources :-[ to me it seems i cannot use zest Graph library to do this job. am i wrong? are there any alternatives?
any help would be appreciated :)