Where to Find Up-to-date yFiles Information

This page is from the outdated yFiles for Java 2.13 documentation. You can find the most up-to-date documentation for all yFiles products on the yFiles documentation overview page.

Please see the following links for more information about the yFiles product family of diagramming programming libraries and corresponding yFiles products for modern web apps, for cross-platform Java(FX) applications, and for applications for the Microsoft .NET environment.

More about the yFiles product family Close X

Multiple Views on a Common Model Graph

The yFiles library provides advanced support for establishing and managing model-view relationships between graphs which allow to easily create mulitple views on a common model graph.

Concept

The concept that enables having multiple views on a common model graph bases on the notion of model-view relationships between graphs. A distinguished graph, the "model graph" whose content defines an actual model, is connected by means of model-view relationships to an arbitrary number of so-called "satellite graphs." The satellite graphs all derive from the model graph, i.e., their contents reflect that of the model graph either completely or only in part.

In particular, model-view relationships comprise the following functionality:

  • Automatic synchronization of the model to the views, where all satellite graphs are updated whenever nodes or edges are inserted into or removed from the model graph.
  • Synchronization of a view to the model, where the model graph is updated whenever nodes or edges are inserted into or removed from a satellite graph.
  • Filtering on a per-view basis, such that a satellite graph only contains specific graph elements from the model graph.

A specialized case of multiple views is the local view which is especially useful for providing detail views of complex graphs. Local views are explained in the section called “Local Views”.

Figure 6.64, “Multiple views on a common model graph” shows a screenshot of tutorial demo application ModelViewManagerDemo.java which has four Graph2DViews in a two-by-two arrangement. The upper-left view shows the common model graph, the remaining views the satellite graphs that are derived from it. Each of the views uses a different layout algorithm for its graph.

Figure 6.64. Multiple views on a common model graph

Multiple views on a common model graph.

Note that the lower two satellite graphs seen in the screenshot present a filtered subset of the model graph's elements:

  • In the lower-left view, only the nodes but no edges from the model graph are contained.
  • The lower-right view shows only those graph elements of the model graph that are created after the views have been initialized, i.e., initially, this view has an empty graph.

Class ModelViewManager

Class ModelViewManager is the central instance that enables and manages multiple views on a common model graph. It is responsible for establishing and maintaining the model-view relationships between model graph and satellite graphs. Specifically, this includes the mappings from model graph elements to satellite graph elements, but also any automatic synchronization of structural graph changes, i.e., insertion and removal of nodes and edges, from the model graph to all satellite graphs and vice versa.

Important

Synchronization between model graph and satellite graphs is done using specialized graph listener implementations. It is strongly discouraged to invoke any hide or unhide operations on either model graph or satellite graphs, since this will prevent ModelViewManager from proper synchronization.

Additionally, class ModelViewManager also provides support for filtering whenever the model is synchronized to the views.

Example 6.46, “Creating a ModelViewManager instance for a model graph” shows how to create a ModelViewManager instance for a given graph that serves as the common model graph.

Example 6.46. Creating a ModelViewManager instance for a model graph

// 'myModelGraph' is of type y.base.Graph.

// Creating a ModelViewManager instance for the given model graph.
ModelViewManager mvManager = ModelViewManager.getInstance(myModelGraph);

Establishing a model-view relationship using the ModelViewManager instance can then be done by means of one of the following methods:

Synchronization

Synchronization is the process of updating either the satellite graphs or the model graph whenever a structural change in the model or one of the views occurred. Basically, this means that a copy of a node or an edge is created in the satellite graphs when a new node or edge is created in the model graph. Similarly, when a graph element edge is removed from the model graph, the corresponding graph element in the satellite graphs is removed, too.

In order to create copies of a new model graph element in the views, GraphCopier.CopyFactory instances are used. The copy factory that shall be used for a view can be given at creation time of the satellite graph. If no copy factory is set, an instance of Graph2DCopyFactory.HierarchicGraph2DCopyFactory is used by default.

Synchronization takes place in either of two directions:

  • From model graph to satellite graphs: happens automatically, but can additionally be triggered explicitly, too.
  • From a satellite graph back to the model graph: can optionally be enabled when establishing a model-view relationship to happen automatically. Additionally, explicit synchronization can be triggered, too.

Observe carefully, that whenever a satellite graph's content is synchronized back to the model graph, the model graph in turn updates all views.

Filtering

Filtering means the technique for determining what graph elements, i.e., what nodes or edges of the common model graph are also present in a specific satellite graph. By default, all elements from the model graph are also in the satellite graphs. Filtering is applied automatically when the model is synchronized to the views.

A filter is defined by interface ModelViewManager.Filter and can be associated with a satellite graph by means of the following setter method or at creation time of the satellite graphs when a model-view relationship is established.

ModelViewManager.Filter getFilter(Graph viewGraph)
void setFilter(Graph viewGraph, ModelViewManager.Filter filter)
Description Getter and setter methods for associating a filter with satellite graphs.

For example, a filter that results in omitting all edges present in the model graph is shown in Example 6.47, “Filter implementation that filters out all edges”.

Example 6.47. Filter implementation that filters out all edges

public class NoEdgesFilter implements ModelViewManager.Filter {
  public boolean acceptInsertion(final Node node) { return true; }
  public boolean acceptInsertion(final Edge edge) { return false; }

  public boolean acceptRetention(final Node node) { return true; }
  public boolean acceptRetention(final Edge edge) { return false; }

  public boolean acceptRemoval(final Node model) { return true; }
  public boolean acceptRemoval(final Edge model) { return true; }
}

Using filters is presented in tutorial demo application ModelViewManagerDemo.java.