Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "GEF/GEF4/Graph"

< GEF‎ | GEF4
 
(11 intermediate revisions by 3 users not shown)
Line 4: Line 4:
  
 
== Introduction ==
 
== Introduction ==
The <span style="color:#960607">[[GEF/GEF4/Graph|GEF4 Graph]]</span> component provides a simple, UI-independent graph model. It consists of the single [[#Graph|Graph]] module.
+
The <span style="color:#960607">[[GEF/GEF4/Graph|GEF4 Graph]]</span> component provides a simple, UI-independent graph model. It consists of the single [[#Graph|Graph]] module. There are also a couple of undeployed [[GEF/GEF4/Graph/Examples|Graph Examples]].
  
 
[[Image:GEF4-Components-Graph.png|600px]]
 
[[Image:GEF4-Components-Graph.png|600px]]
Line 12: Line 12:
 
*'''feature: org.eclipse.gef4.graph'''
 
*'''feature: org.eclipse.gef4.graph'''
 
*'''bundle: org.eclipse.gef4.graph'''
 
*'''bundle: org.eclipse.gef4.graph'''
 +
 +
The [[#Graph|Graph]] module of [[GEF/GEF4/Graph|GEF4 Graph]] provides the single [[#Graph:Root|{Root}]] package, which delivers a generic graph model representation and related utility classes.
 +
 +
----
  
 
<div id="Graph:Root"></div>
 
<div id="Graph:Root"></div>
Line 18: Line 22:
 
*'''package: org.eclipse.gef4.graph'''
 
*'''package: org.eclipse.gef4.graph'''
  
This package provides a simple graph model and a support class to copy/merge such models.
+
The [[#Graph:Root|{Root}]] package provides a simple graph model and a support class to copy/merge such models.
  
[[Image:GEF4Graph-model.png|907px]]
+
[[Image:GEF4Graph-model.png|1148px]]
  
 
==== Graph, Node, Edge ====
 
==== Graph, Node, Edge ====
 
A <code>Graph</code> serves as a container for <code>Node</code>s and <code>Edge</code>s. Additionally, a <code>Graph</code> can be ''nested'' inside a ''nesting'' <code>Node</code>, so that sub-graphs can be properly represented.  
 
A <code>Graph</code> serves as a container for <code>Node</code>s and <code>Edge</code>s. Additionally, a <code>Graph</code> can be ''nested'' inside a ''nesting'' <code>Node</code>, so that sub-graphs can be properly represented.  
  
Moreover, arbitrary attributes can be set on <code>Graph</code>s, <code>Node</code>s, and <code>Edge</code>s. The concrete attributes that are used are outside the scope of the [[GEF/GEF4/Graph |GEF Graph]] component. The DOT importer of the [[GEF/GEF4/DOT |GEF DOT]] component, e.g. adds DOT-specific attributes to the Graph it creates, the [[GEF/GEF4/Zest | GEF Zest]] component uses visualization-specific attributes, which determine the concrete visualization.
+
Moreover, arbitrary attributes can be set on <code>Graph</code>s, <code>Node</code>s, and <code>Edge</code>s, as they all implement [[GEF/GEF4/Common#IAttributeStore | org.eclipse.gef4.common.attributes.IAttributeStore]]. As all attributes are maintained in observable collections/properties, listeners can be registered to react to changes. The concrete attributes that are used are outside the scope of the [[GEF/GEF4/Graph|GEF4 Graph]] component. The DOT importer of the [[GEF/GEF4/DOT|GEF4 DOT]] component, e.g. adds DOT-specific attributes to the Graph it creates, the [[GEF/GEF4/Zest|GEF4 Zest]] component uses visualization-specific attributes, which determine the concrete visualization.
 +
 
 +
A <code>Graph</code> can be easily constructed using a <code>Graph.Builder</code>:
 +
 
 +
<source lang="java" style="border-style:solid;border-color:#f2f2f2;border-width:1px;padding:10px;margin-bottom:10px">
 +
  Graph graph = new Graph.Builder()
 +
    .attr(DotAttributes._TYPE__G, DotAttributes._TYPE__G__DIGRAPH)//
 +
    .attr("g_attr", "g1").node("n1")//
 +
    .attr(DotAttributes.LABEL__GNE, "1")//
 +
    .attr(DotAttributes.ID__GNE, "1")//
 +
    .node("n2")//
 +
    .attr(DotAttributes.LABEL__GNE, "2")//
 +
    .attr(DotAttributes.ID__GNE, "2")//
 +
    .node("n3")//
 +
    .attr(DotAttributes.LABEL__GNE, "3")//
 +
    .attr(DotAttributes.ID__GNE, "3")//
 +
    .edge("n1", "n2").attr(DotAttributes.LABEL__GNE, "e1")
 +
    .edge("n1", "n3").build();
 +
</source>
 +
 
 +
It allows to chain <code>Node.Builder</code>s, which can be made identifiable through an arbitrary Object key (here "n1", "n2", "n3"), and <code>Edge.Builder</code>s, which can refer to identifiable <code>Node.Builder</code>s to build their source and target elements, so even a complex wired graph can be created through a single builder chain. This is very useful when creating a Graph model that wraps a given semantic model (here a Statechart, which comprises States and Transitions):
 +
 
 +
<source lang="java" style="border-style:solid;border-color:#f2f2f2;border-width:1px;padding:10px;margin-bottom:10px">
 +
  Graph.Builder builder = new Graph.Builder().attr(ZestProperties.LAYOUT_ALGORITHM__G, new RadialLayoutAlgorithm());
 +
  for (State s : statechart.getStates()) {
 +
    // use the State as key for the Node builder
 +
    builder.node(s).attr(ZestProperties.LABEL__NE, s.getName());
 +
  }
 +
  for (Transition t : statechart.getTransitions()) {
 +
    // build an Edge for each Transition, referring to the Node builders of its source and target States
 +
    builder.edge(t.getSource(), t.getTarget()).attr(ZestProperties.LABEL__NE, "");
 +
  }
 +
  Graph graph = builder.build()
 +
</source>
  
 
==== GraphCopier ====
 
==== GraphCopier ====
The graph package also contains a utility class (<code>GraphCopier</code>) to copy/merge graphs.
+
A <code>GraphCopier</code> is a utility class to copy/merge graphs. It requires an [[GEF/GEF4/Common#IAttributeCopier | org.eclipse.gef4.common.attributes.IAttributeCopier]] to copy/transfer the attributes of the <code>Graph</code>, <code>Node</code>, and <code>Edge</code> elements that are copied.
  
 
[[Category:GEF]]
 
[[Category:GEF]]

Latest revision as of 10:52, 2 June 2016

Note to non-wiki readers: This documentation is generated from the Eclipse wiki - if you have corrections or additions it would be awesome if you added them in the original wiki page.


Introduction

The GEF4 Graph component provides a simple, UI-independent graph model. It consists of the single Graph module. There are also a couple of undeployed Graph Examples.

GEF4-Components-Graph.png

Graph

  • feature: org.eclipse.gef4.graph
  • bundle: org.eclipse.gef4.graph

The Graph module of GEF4 Graph provides the single {Root} package, which delivers a generic graph model representation and related utility classes.


{Root}

  • package: org.eclipse.gef4.graph

The {Root} package provides a simple graph model and a support class to copy/merge such models.

GEF4Graph-model.png

Graph, Node, Edge

A Graph serves as a container for Nodes and Edges. Additionally, a Graph can be nested inside a nesting Node, so that sub-graphs can be properly represented.

Moreover, arbitrary attributes can be set on Graphs, Nodes, and Edges, as they all implement org.eclipse.gef4.common.attributes.IAttributeStore. As all attributes are maintained in observable collections/properties, listeners can be registered to react to changes. The concrete attributes that are used are outside the scope of the GEF4 Graph component. The DOT importer of the GEF4 DOT component, e.g. adds DOT-specific attributes to the Graph it creates, the GEF4 Zest component uses visualization-specific attributes, which determine the concrete visualization.

A Graph can be easily constructed using a Graph.Builder:

  Graph graph = new Graph.Builder()
    .attr(DotAttributes._TYPE__G, DotAttributes._TYPE__G__DIGRAPH)//
    .attr("g_attr", "g1").node("n1")//
    .attr(DotAttributes.LABEL__GNE, "1")//
    .attr(DotAttributes.ID__GNE, "1")//
    .node("n2")//
    .attr(DotAttributes.LABEL__GNE, "2")//
    .attr(DotAttributes.ID__GNE, "2")//
    .node("n3")//
    .attr(DotAttributes.LABEL__GNE, "3")//
    .attr(DotAttributes.ID__GNE, "3")//
    .edge("n1", "n2").attr(DotAttributes.LABEL__GNE, "e1")
    .edge("n1", "n3").build();

It allows to chain Node.Builders, which can be made identifiable through an arbitrary Object key (here "n1", "n2", "n3"), and Edge.Builders, which can refer to identifiable Node.Builders to build their source and target elements, so even a complex wired graph can be created through a single builder chain. This is very useful when creating a Graph model that wraps a given semantic model (here a Statechart, which comprises States and Transitions):

  Graph.Builder builder = new Graph.Builder().attr(ZestProperties.LAYOUT_ALGORITHM__G, new RadialLayoutAlgorithm());
  for (State s : statechart.getStates()) {
    // use the State as key for the Node builder
    builder.node(s).attr(ZestProperties.LABEL__NE, s.getName());
  }
  for (Transition t : statechart.getTransitions()) {
    // build an Edge for each Transition, referring to the Node builders of its source and target States
    builder.edge(t.getSource(), t.getTarget()).attr(ZestProperties.LABEL__NE, "");
  }
  Graph graph = builder.build()

GraphCopier

A GraphCopier is a utility class to copy/merge graphs. It requires an org.eclipse.gef4.common.attributes.IAttributeCopier to copy/transfer the attributes of the Graph, Node, and Edge elements that are copied.

Back to the top