Package org.eclipse.zest.core.widgets

# Class Graph

java.lang.Object
org.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Scrollable
org.eclipse.swt.widgets.Composite
org.eclipse.swt.widgets.Canvas
org.eclipse.draw2d.FigureCanvas
org.eclipse.zest.core.widgets.Graph

All Implemented Interfaces:
  `Drawable`, `IContainer`, `IContainer2`

public class Graph extends org.eclipse.draw2d.FigureCanvas implements IContainer2
Holds the nodes and connections for the graph.

Since:
  1.0

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`ANIMATION_TIME`
`protected List<GraphConnection>`
`connections`
`Color`
`DARK_BLUE`
`Color`
`DEFAULT_NODE_COLOR`
`static final int`
`FISHEYE_ANIMATION_TIME`
`Color`
`GREY_BLUE`
`Color`
`HIGHLIGHT_ADJACENT_COLOR`
`Color`
`HIGHLIGHT_COLOR`
`static final String`
`KEY_ANIMATION_TIME`
`static final String`
`KEY_FISHEYE_ANIMATION_TIME`
`Color`
`LIGHT_BLUE`
`Color`
`LIGHT_BLUE_CYAN`
`Color`
`LIGHT_YELLOW`

### Fields inherited from class org.eclipse.draw2d.FigureCanvas

`ALWAYS, AUTOMATIC, NEVER`

### Fields inherited from class org.eclipse.swt.widgets.Control

`view`

## Constructor Summary

Constructors
Constructor
Description
`Graph(Composite parent, int style)`
Constructor for a Graph.
`Graph(Composite parent, int style, boolean enableHideNodes)`
Constructor for a Graph.

## Method Summary

Modifier and Type
Method
Description
`void`
`addConstraintAdapter(ConstraintAdapter constraintAdapter)`
Deprecated, for removal: This API element is subject to removal in a future version.
No longer used in Zest 2.x.
`void`
`addFisheyeListener(FisheyeListener listener)`
Adds a listener that will be notified when fisheyed figures change in this graph.
`void`
`addLayoutFilter(LayoutFilter filter)`
Adds a filter used for hiding elements from layout algorithm.
`void`
`addNode(GraphNode node)`
`void`
`addSelectionListener(SelectionListener selectionListener)`
This adds a listener to the set of listeners that will be called when a selection event occurs.
`void`
`addSubgraphFigure(org.eclipse.draw2d.IFigure figure)`
`void`
`applyLayout()`
Runs the layout on this graph.
`void`
`applyLayoutNow()`
Apply this graphs's layout cleanly and display all changes.
`boolean`
`canCollapse(GraphNode node)`
`boolean`
`canExpand(GraphNode node)`
`void`
`clear()`
Clear the graph of all its content.
`protected GraphDragSupport`
`createGraphDragSupport()`
Creator method for DragSupport
`protected org.eclipse.draw2d.IFigure`
`createLayers()`
Layer creation
`protected org.eclipse.zest.core.widgets.internal.ZestRootLayer`
`createZestRootLayer()`
Creator method for ZestRootLayer
`void`
`dispose()`
Dispose of the nodes and edges when the graph is disposed.
`List<? extends GraphConnection>`
`getConnections()`
Gets the list of GraphModelConnection objects.
`int`
`getConnectionStyle()`
Gets the default connection style.
`ExpandCollapseManager`
`getExpandCollapseManager()`
`org.eclipse.draw2d.IFigure`
`getFigureAt(int x, int y)`
Finds a figure at the location X, Y in the graph This point should be translated to relative before calling findFigureAt
`Graph`
`getGraph()`
`protected GraphItem`
`getGraphItem(org.eclipse.draw2d.IFigure figure)`
Returns the item for the given figure
`Graph`
`getGraphModel()`
Deprecated, for removal: This API element is subject to removal in a future version.
`final int`
`getGraphStyle()`
Gets the default graph style.
`boolean`
`getHideNodesEnabled()`
`Widget`
`getItem()`
`int`
`getItemType()`
`LayoutAlgorithm`
`getLayoutAlgorithm()`
`DisplayIndependentRectangle`
`getLayoutBounds()`
`final LayoutContext`
`getLayoutContext()`
`List<? extends GraphNode>`
`getNodes()`
Gets a list of the GraphModelNode children objects under the root node in this diagram.
`int`
`getNodeStyle()`
Gets the default node style.
`org.eclipse.draw2d.geometry.Dimension`
`getPreferredSize()`
`org.eclipse.draw2d.ScalableFigure`
`getRootLayer()`
Gets the root layer for this graph
`List<? extends GraphItem>`
`getSelection()`
Gets the list of currently selected graph items
`SubgraphFactory`
`getSubgraphFactory()`
`org.eclipse.zest.core.viewers.internal.ZoomManager`
`getZoomManager()`
Returns the ZoomManager component used for scaling the graph widget.
`boolean`
`isDynamicLayoutEnabled()`
`void`
`notifyListeners(int eventType, Event event)`
`void`
`removeFisheyeListener(FisheyeListener listener)`
`void`
`removeLayoutFilter(LayoutFilter filter)`
Removes given layout filter.
`void`
`removeSelectionListener(SelectionListener selectionListener)`
`void`
`selectAll()`
`void`
`setConnectionStyle(int connectionStyle)`
Sets the default connection style.
`void`
`setConstraintAdapters(List<ConstraintAdapter> constraintAdapters)`
Deprecated, for removal: This API element is subject to removal in a future version.
No longer used in Zest 2.x.
`void`
`setDynamicLayout(boolean enabled)`
Enables or disables dynamic layout (that is layout algorithm performing layout in background or when certain events occur).
`void`
`setExpandCollapseManager(ExpandCollapseManager expandCollapseManager)`
`void`
`setExpanded(GraphNode node, boolean expanded)`
`final void`
`setGraphStyle(int style)`
Sets the default graph style.
`void`
`setLayoutAlgorithm(LayoutAlgorithm algorithm, boolean applyLayout)`
Sets the LayoutAlgorithm for this container and optionally applies it.
`void`
`setNodeStyle(int nodeStyle)`
Sets the default node style.
`void`
`setPreferredSize(int width, int height)`
Sets the preferred size of the layout area.
`void`
`setRouter(org.eclipse.draw2d.ConnectionRouter connectionRouter)`
Updates the connection router and applies to to all existing connections that have no connection routers set to them.
`void`
`setSelection(GraphItem[] items)`
Changes the selection to the list of items
`void`
`setSubgraphFactory(SubgraphFactory factory)`
`String`
`toString()`

### Methods inherited from class org.eclipse.draw2d.FigureCanvas

`computeSize, getContents, getFont, getHorizontalScrollBarVisibility, getLightweightSystem, getVerticalScrollBarVisibility, getViewport, scrollSmoothTo, scrollTo, scrollToX, scrollToY, setBorder, setContents, setFont, setHorizontalScrollBarVisibility, setScrollBarVisibility, setVerticalScrollBarVisibility, setViewport`

### Methods inherited from class org.eclipse.swt.widgets.Canvas

`drawBackground, getCaret, getIME, scroll, setCaret, setIME`

### Methods inherited from class org.eclipse.swt.widgets.Composite

`changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, redraw, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList`

### Methods inherited from class org.eclipse.swt.widgets.Scrollable

`computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar, setScrollbarsMode`

### Methods inherited from class org.eclipse.swt.widgets.Control

`addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setAutoscalingMode, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update`

### Methods inherited from class org.eclipse.swt.widgets.Widget

`addDisposeListener, addListener, addTypedListener, checkWidget, getData, getData, getDisplay, getListeners, getStyle, getTypedListeners, isAutoDirection, isDisposed, isListening, removeDisposeListener, removeListener, removeListener, removeListener, removeTypedListener, reskin, setData, setData`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.eclipse.swt.graphics.Drawable

`isAutoScalable`

## Field Details

### ANIMATION_TIME

public static final int ANIMATION_TIME

See Also:
  - Constant Field Values

### FISHEYE_ANIMATION_TIME

public static final int FISHEYE_ANIMATION_TIME

See Also:
  - Constant Field Values

### KEY_ANIMATION_TIME

public static final String KEY_ANIMATION_TIME

Since:
  1.18
See Also:
  - Constant Field Values

### KEY_FISHEYE_ANIMATION_TIME

public static final String KEY_FISHEYE_ANIMATION_TIME

Since:
  1.18
See Also:
  - Constant Field Values

### LIGHT_BLUE

public Color LIGHT_BLUE

### LIGHT_BLUE_CYAN

public Color LIGHT_BLUE_CYAN

### GREY_BLUE

public Color GREY_BLUE

### DARK_BLUE

public Color DARK_BLUE

### LIGHT_YELLOW

public Color LIGHT_YELLOW

### HIGHLIGHT_COLOR

public Color HIGHLIGHT_COLOR

### HIGHLIGHT_ADJACENT_COLOR

public Color HIGHLIGHT_ADJACENT_COLOR

### DEFAULT_NODE_COLOR

public Color DEFAULT_NODE_COLOR

### connections

protected List<GraphConnection> connections

## Constructor Details

### Graph

public Graph(Composite parent, int style)
Constructor for a Graph. This widget represents the root of the graph, and can contain graph items such as graph nodes and graph connections.

Parameters:
  `parent` -
  `style` - The SWT style used for the underlying `FigureCanvas`. See `FigureCanvas.ACCEPTED_STYLES` for a list of all supported styles. Use `setGraphStyle(int)` to set the Zest-specific styles.

### Graph

public Graph(Composite parent, int style, boolean enableHideNodes)
Constructor for a Graph. This widget represents the root of the graph, and can contain graph items such as graph nodes and graph connections.

Parameters:
  `parent` -
  `style` - The SWT style used for the underlying `FigureCanvas`. See `FigureCanvas.ACCEPTED_STYLES` for a list of all supported styles. Use `setGraphStyle(int)` to set the Zest-specific styles.
  `enableHideNodes` -
Since:
  1.8

## Method Details

### addSelectionListener

public void addSelectionListener(SelectionListener selectionListener)
This adds a listener to the set of listeners that will be called when a selection event occurs.

Parameters:
  `selectionListener` -

### removeSelectionListener

public void removeSelectionListener(SelectionListener selectionListener)

### getNodes

public List<? extends GraphNode> getNodes()
Gets a list of the GraphModelNode children objects under the root node in this diagram. If the root node is null then all the top level nodes are returned.

Specified by:
  `getNodes` in interface `IContainer`
Returns:
  List of GraphModelNode objects

### addConstraintAdapter

@Deprecated(since="2.0", forRemoval=true) public void addConstraintAdapter(ConstraintAdapter constraintAdapter)
Deprecated, for removal: This API element is subject to removal in a future version.
No longer used in Zest 2.x. This method will be removed after the 2026-12 release.
Adds a new constraint adapter to the list of constraint adapters

Parameters:
  `constraintAdapter` -

### setConstraintAdapters

@Deprecated(since="2.0", forRemoval=true) public void setConstraintAdapters(List<ConstraintAdapter> constraintAdapters)
Deprecated, for removal: This API element is subject to removal in a future version.
No longer used in Zest 2.x. This method will be removed after the 2026-12 release.
Sets the constraint adapters on this model

Parameters:
  `constraintAdapters` -

### getRootLayer

public org.eclipse.draw2d.ScalableFigure getRootLayer()
Gets the root layer for this graph

### setConnectionStyle

public void setConnectionStyle(int connectionStyle)
Sets the default connection style.

Parameters:
  `connectionStyle` - style the connection style to set
See Also:
  - `ZestStyles`

### getConnectionStyle

public int getConnectionStyle()
Gets the default connection style.

Returns:
  the connection style
See Also:
  - `ZestStyles`

### setNodeStyle

public void setNodeStyle(int nodeStyle)
Sets the default node style.

Parameters:
  `nodeStyle` - the node style to set
See Also:
  - `ZestStyles`

### getNodeStyle

public int getNodeStyle()
Gets the default node style.

Returns:
  the node style
See Also:
  - `ZestStyles`

### setGraphStyle

public final void setGraphStyle(int style)
Sets the default graph style.

Parameters:
  `style` - the graph style to set.
Since:
  1.15
See Also:
  - `ZestStyles`

### getGraphStyle

public final int getGraphStyle()
Gets the default graph style.

Returns:
  the default graph style
Since:
  1.15

### getConnections

public List<? extends GraphConnection> getConnections()
Gets the list of GraphModelConnection objects.

Specified by:
  `getConnections` in interface `IContainer2`
Returns:
  list of GraphModelConnection objects

### setSelection

public void setSelection(GraphItem[] items)
Changes the selection to the list of items

Parameters:
  `items` -

### selectAll

public void selectAll()

### getSelection

public List<? extends GraphItem> getSelection()
Gets the list of currently selected graph items

Returns:
  Currently selected graph items

### toString

public String toString()

Overrides:
  `toString` in class `Composite`

### getGraphModel

@Deprecated(since="1.12", forRemoval=true) public Graph getGraphModel()
Deprecated, for removal: This API element is subject to removal in a future version.

### dispose

public void dispose()
Dispose of the nodes and edges when the graph is disposed.

Overrides:
  `dispose` in class `Widget`

### applyLayout

public void applyLayout()
Runs the layout on this graph. If the view is not visible layout will be deferred until after the view is available.

Specified by:
  `applyLayout` in interface `IContainer`

### applyLayoutNow

public void applyLayoutNow()
Apply this graphs's layout cleanly and display all changes.

Since:
  1.14

### setDynamicLayout

public void setDynamicLayout(boolean enabled)
Enables or disables dynamic layout (that is layout algorithm performing layout in background or when certain events occur). Dynamic layout should be disabled before doing a long series of changes in the graph to make sure that layout algorithm won't interfere with these changes. Enabling dynamic layout causes the layout algorithm to be applied even if it's not actually a dynamic algorithm.

Parameters:
  `enabled` -
Since:
  1.14

### isDynamicLayoutEnabled

public boolean isDynamicLayoutEnabled()

Returns:
  true if dynamic layout is enabled (see `setDynamicLayout(boolean)`)
Since:
  1.14

### setPreferredSize

public void setPreferredSize(int width, int height)
Sets the preferred size of the layout area. Size of ( -1, -1) uses the current canvas size.

Parameters:
  `width` -
  `height` -

### getPreferredSize

public org.eclipse.draw2d.geometry.Dimension getPreferredSize()

Returns:
  the preferred size of the layout area.
Since:
  1.14

### getLayoutContext

public final LayoutContext getLayoutContext()

Specified by:
  `getLayoutContext` in interface `IContainer2`
@noreference
  This method is not intended to be referenced by clients.

### setLayoutAlgorithm

public void setLayoutAlgorithm(LayoutAlgorithm algorithm, boolean applyLayout)
Description copied from interface: `IContainer`
Sets the LayoutAlgorithm for this container and optionally applies it.

Specified by:
  `setLayoutAlgorithm` in interface `IContainer`
Parameters:
  `algorithm` -
  `applyLayout` -

### setSubgraphFactory

public void setSubgraphFactory(SubgraphFactory factory)

Since:
  1.14

### getSubgraphFactory

public SubgraphFactory getSubgraphFactory()

Since:
  1.14

### setExpandCollapseManager

public void setExpandCollapseManager(ExpandCollapseManager expandCollapseManager)

Since:
  1.14

### getExpandCollapseManager

public ExpandCollapseManager getExpandCollapseManager()

Since:
  1.14

### addLayoutFilter

public void addLayoutFilter(LayoutFilter filter)
Adds a filter used for hiding elements from layout algorithm. NOTE: If a node or subgraph if filtered out, all connections adjacent to it should also be filtered out. Otherwise layout algorithm may behave in an unexpected way.

Parameters:
  `filter` - filter to add
Since:
  1.14

### getLayoutAlgorithm

public LayoutAlgorithm getLayoutAlgorithm()

### removeLayoutFilter

public void removeLayoutFilter(LayoutFilter filter)
Removes given layout filter. If it had not been added to this graph, this method does nothing.

Parameters:
  `filter` - filter to remove
Since:
  1.14

### getFigureAt

public org.eclipse.draw2d.IFigure getFigureAt(int x, int y)
Finds a figure at the location X, Y in the graph This point should be translated to relative before calling findFigureAt

### getHideNodesEnabled

public boolean getHideNodesEnabled()

Since:
  1.8

### createGraphDragSupport

protected GraphDragSupport createGraphDragSupport()
Creator method for DragSupport

Returns:
  class that implemented GraphDragSupport
Since:
  1.9

### notifyListeners

public void notifyListeners(int eventType, Event event)

Overrides:
  `notifyListeners` in class `Widget`

### clear

public void clear()
Clear the graph of all its content.

Since:
  1.14

### addNode

public void addNode(GraphNode node)

Specified by:
  `addNode` in interface `IContainer2`
Parameters:
  `node` -
@noreference
  This method is not intended to be referenced by clients.

### addSubgraphFigure

public void addSubgraphFigure(org.eclipse.draw2d.IFigure figure)

Specified by:
  `addSubgraphFigure` in interface `IContainer2`
Parameters:
  `figure` -
@noreference
  This method is not intended to be referenced by clients.

### createLayers

protected org.eclipse.draw2d.IFigure createLayers()
Layer creation

Returns:
  IFigure the rootlayer
Since:
  1.9

### createZestRootLayer

protected org.eclipse.zest.core.widgets.internal.ZestRootLayer createZestRootLayer()
Creator method for ZestRootLayer

Returns:
  new ZestRootLayer instance
Since:
  1.9

### getGraph

public Graph getGraph()

Specified by:
  `getGraph` in interface `IContainer`

### addFisheyeListener

public void addFisheyeListener(FisheyeListener listener)
Adds a listener that will be notified when fisheyed figures change in this graph.

Parameters:
  `listener` - listener to add
Since:
  1.14

### removeFisheyeListener

public void removeFisheyeListener(FisheyeListener listener)

Since:
  1.14

### getItemType

public int getItemType()

Specified by:
  `getItemType` in interface `IContainer`

### getGraphItem

protected GraphItem getGraphItem(org.eclipse.draw2d.IFigure figure)
Returns the item for the given figure

Parameters:
  `figure` -
Returns:
  GraphItem for the given IFigure
Since:
  1.9

### setExpanded

public void setExpanded(GraphNode node, boolean expanded)

Since:
  1.14

### canExpand

public boolean canExpand(GraphNode node)

Since:
  1.14

### canCollapse

public boolean canCollapse(GraphNode node)

Since:
  1.14

### getItem

public Widget getItem()

Specified by:
  `getItem` in interface `IContainer2`
Since:
  1.12

### getLayoutBounds

public DisplayIndependentRectangle getLayoutBounds()

Specified by:
  `getLayoutBounds` in interface `IContainer2`
Since:
  1.12

### setRouter

public void setRouter(org.eclipse.draw2d.ConnectionRouter connectionRouter)
Updates the connection router and applies to to all existing connections that have no connection routers set to them.

Parameters:
  `connectionRouter` -
Since:
  1.14

### getZoomManager

public org.eclipse.zest.core.viewers.internal.ZoomManager getZoomManager()
Returns the ZoomManager component used for scaling the graph widget.

Returns:
  the ZoomManager component
Since:
  1.14