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

GEF/GEF4/Layout

< GEF‎ | GEF4
Revision as of 16:28, 20 January 2014 by Ujhelyiz.mit.bme.hu (Talk | contribs)

TODO: Sketch our ideas behind the planned GEF4 Layouts component here.

GEF4 Layouts

The GEF4 layout component supports all layout algorithms from Zest 1.x and more.

New layout algorithms

SpaceTreeLayoutAlgorithm

SpaceTreeLayoutAlgorithm keeps track of node positions all the time, always trying to form a nice tree structure. This means movement of nodes with the mouse is somehow restricted (you can move a node within its current layer, but only if it doesn't cause nodes to be pushed out of the graph area. When an expand operation is requested on a node, the node is centered and its subtree is shown, as long as there's enough space (other parts of the tree can be collapsed to extend available space).

Zest-tree-layout-spacetree.png

DirectedGraphLayoutAlgorithm

DirectedGraphLayoutAlgorithm was designed with the PDE Dependency Visualization in mind and is based on its layout algorithm. Initially only nodes without predecessors are expanded. Other nodes become visible if they have at least one direct predecessor which is visible and expanded. Collapsed nodes can have outcoming connections if the target node is visible because of a predecessor. There's an option to hide such connections.

Zest-tree-layout-dag.png

Migration from Zest 1.x to GEF4 Layouts

In GEF4, the layout API has been reworked. Most Zest 1.x code should keep working just fine. See the Javadoc of the deprecated API for documentation on migrating to the new API. In a few cases however, code changes are required.

The most important change is that LayoutStyles have been removed - it is safe to remove it from all constructor calls.

Custom Layouts

To define custom layouts, instead of extending AbstractLayoutAlgorithm implement LayoutAlgorithm (see example below and full code in CustomLayout.java in the examples bundle).

LayoutAlgorithm layoutAlgorithm = new LayoutAlgorithm() {
  private LayoutContext context;
  public void setLayoutContext(LayoutContext context) {
    this.context = context;
  }
  public void applyLayout(boolean clean) {
    EntityLayout[] entitiesToLayout = context.getEntities();
    int totalSteps = entitiesToLayout.length;
    double distance = context.getBounds().width / totalSteps;
    int xLocation = 0;
    for (int currentStep = 0; currentStep < entitiesToLayout.length; currentStep++) {
      EntityLayout layoutEntity = entitiesToLayout[currentStep];
      layoutEntity.setLocation(xLocation,
      layoutEntity.getLocation().y);
      xLocation += distance;
    }
  }
};

Back to the top