eclipse plugin (gef) and graph visualization (zest)

断了今生、忘了曾经 提交于 2019-12-13 16:16:00

问题


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 :)


回答1:


In short, Zest does not support this scenario directly.

However, you can build an in-memory representation of you edit parts that can be layouted using Zest. In Zest 1.0 you have to provide a translation to Graph Nodes and Graph Arcs Relations manually; in Zest 2.0 you only have to provide a LayoutContext. Zest 2.0 is not released yet, but it seems easier for me to handle this scenario.

Additional idea: the open source project Spray support Zest layouting for Graphiti graphs (Graphiti extends GEF - maybe there are some ideas that can be reused). See the following code file: http://code.google.com/a/eclipselabs.org/p/spray/source/browse/plugins/org.eclipselabs.spray.runtime.graphiti.zest/src/org/eclipselabs/spray/runtime/graphiti/zest/features/ZestLayoutDiagramFeature.java for some ideas.

EDIT: I looked into a related code in my computer; we managed to get such layouting to work in Zest 1.0 the following way:

  1. Have a single GraphNode for each node, and a Connection for each arc between the nodes. You can collect them into two different arrays; e.g. SimpleNode[] nodes; SimpleRelationship[] relationships;
  2. Instantiate an algorithm class, and set your optional parameters as you like.
  3. Call algorithm.applyLayout(nodes, relationships, 0, 0, diagram.width, diagram.height, false, false) - sorry, don't have an available Zest 1.0 installation to check the exact meanings of the parameters; the first two are the nodes and relationships used; then the next four sets the drawing board; and I honestly have no idea what are the final two for. :D

Further clarification: Zest uses nodes and relations as a terminology - replace my previous arc with relation.



来源:https://stackoverflow.com/questions/8884792/eclipse-plugin-gef-and-graph-visualization-zest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!