org.eclipse.gef4.zest.core.widgets

## Class GraphWidget

- 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.gef4.zest.core.widgets.GraphWidget

All Implemented Interfaces:
  IContainer, Drawable

    public class GraphWidget
    extends org.eclipse.draw2d.FigureCanvas
    implements IContainer

Since:
  1.0

### Field Summary

Fields
`static int` `ANIMATION_TIME`
`protected java.util.List<GraphConnection>` `connections`
`Color` `DARK_BLUE`
`Color` `DEFAULT_NODE_COLOR`
`static int` `FISHEYE_ANIMATION_TIME`
`Color` `GREY_BLUE`
`Color` `HIGHLIGHT_ADJACENT_COLOR`
`Color` `HIGHLIGHT_COLOR`
`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 and Description
`GraphWidget(Composite parent, int style)` Constructor for a Graph.
`GraphWidget(org.eclipse.gef4.graph.Graph graph, Composite parent, int style)` Constructor for a GraphWidget, created from a given Graph data structure.

### Method Summary

Methods
`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.
`void` `dispose()` Dispose of the nodes and edges when the graph is disposed.
`java.util.List<GraphConnection>` `getConnections()` Gets the list of GraphModelConnection objects.
`int` `getConnectionStyle()` Gets the default connection style.
`IConnectionDecorator` `getDefaultConnectionDecorator()`
`IConnectionDecorator` `getDefaultDirectedConnectionDecorator()`
`org.eclipse.gef4.layout.interfaces.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
`GraphWidget` `getGraph()`
`Widget` `getItem()`
`int` `getItemType()`
`org.eclipse.gef4.layout.LayoutAlgorithm` `getLayoutAlgorithm()`
`org.eclipse.gef4.geometry.planar.Rectangle` `getLayoutBounds()`
`org.eclipse.gef4.zest.core.widgets.InternalLayoutContext` `getLayoutContext()`
`java.util.List<GraphNode>` `getNodes()` Gets a list of the GraphNode children objects under the root node in this graph.
`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
`java.util.List<GraphItem>` `getSelection()` Gets the list of currently selected GraphNodes
`SubgraphFactory` `getSubgraphFactory()`
`ZoomManager` `getZoomManager()` Returns the ZoomManager component used for scaling the graph widget.
`boolean` `isAnimationEnabled()`
`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` `setAnimationEnabled(boolean animate)`
`void` `setConnectionStyle(int connectionStyle)` Sets the default connection style.
`void` `setDefaultConnectionDecorator(IConnectionDecorator connectionDecorator)` Sets the connection decorator used for adding source and target decorations.
`void` `setDefaultDirectedConnectionDecorator(IConnectionDecorator connectionDecorator)` Sets the connection decorator used for adding source and target decorations.
`void` `setDynamicLayout(boolean enabled)` Enables or disables dynamic layout (that is layout algorithm performing layout in background or when certain events occur).
`void` `setExpandCollapseManager(org.eclipse.gef4.layout.interfaces.ExpandCollapseManager expandCollapseManager)`
`void` `setExpanded(GraphNode node, boolean expanded)`
`void` `setLayoutAlgorithm(org.eclipse.gef4.layout.LayoutAlgorithm algorithm, boolean applyLayout)`
`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)`
`java.lang.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, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList`

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

`computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar`

### 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, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, 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, checkWidget, getData, getData, getDisplay, getListeners, getStyle, isDisposed, isListening, removeDisposeListener, removeListener, removeListener, reskin, setData, setData`

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

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

### Field Detail

#### 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

#### 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 java.util.List<GraphConnection> connections

### Constructor Detail

#### GraphWidget

    public GraphWidget(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` -
See Also:
  `ZestStyles.GESTURES_DISABLED`, `ZestStyles#ANIMATION_DISABLED`

#### GraphWidget

    public GraphWidget(org.eclipse.gef4.graph.Graph graph,
               Composite parent,
               int style)

Constructor for a GraphWidget, created from a given Graph data structure. This widget represents the root of the graph, and can contain graph items such as graph nodes and graph connections.

Parameters:
  `graph` -
  `parent` -
  `style` -
See Also:
  `ZestStyles.GESTURES_DISABLED`, `ZestStyles#ANIMATION_DISABLED`

### Method Detail

#### 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 java.util.List<GraphNode> getNodes()

Gets a list of the GraphNode children objects under the root node in this graph. If the root node is null then all the top level nodes are returned.

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

#### getRootLayer

    public org.eclipse.draw2d.ScalableFigure getRootLayer()

Gets the root layer for this graph

Returns:

#### setConnectionStyle

    public void setConnectionStyle(int connectionStyle)

Sets the default connection style.

Parameters:
  `connection` - style the connection style to set
See Also:
  `org.eclipse.mylar.zest.core.widgets.ZestStyles`

#### getConnectionStyle

    public int getConnectionStyle()

Gets the default connection style.

Returns:
  the connection style
See Also:
  `org.eclipse.mylar.zest.core.widgets.ZestStyles`

#### setNodeStyle

    public void setNodeStyle(int nodeStyle)

Sets the default node style.

Parameters:
  `nodeStyle` - the node style to set
See Also:
  `org.eclipse.mylar.zest.core.widgets.ZestStyles`

#### getNodeStyle

    public int getNodeStyle()

Gets the default node style.

Returns:
  the node style
See Also:
  `org.eclipse.mylar.zest.core.widgets.ZestStyles`

#### getConnections

    public java.util.List<GraphConnection> getConnections()

Gets the list of GraphModelConnection objects.

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

#### setSelection

    public void setSelection(GraphItem[] items)

Changes the selection to the list of items

Parameters:
  `l` -

#### selectAll

    public void selectAll()

#### getSelection

    public java.util.List<GraphItem> getSelection()

Gets the list of currently selected GraphNodes

Returns:
  Currently selected graph node

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `Widget`

#### 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:
  2.0

#### 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:
  2.0

#### isDynamicLayoutEnabled

    public boolean isDynamicLayoutEnabled()

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

#### 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:
  2.0

#### getLayoutContext

    public org.eclipse.gef4.zest.core.widgets.InternalLayoutContext getLayoutContext()

Specified by:
  `getLayoutContext` in interface `IContainer`
Returns:

#### setLayoutAlgorithm

    public void setLayoutAlgorithm(org.eclipse.gef4.layout.LayoutAlgorithm algorithm,
                          boolean applyLayout)

Specified by:
  `setLayoutAlgorithm` in interface `IContainer`
Parameters:
  `algorithm` -
Since:
  2.0

#### getLayoutAlgorithm

    public org.eclipse.gef4.layout.LayoutAlgorithm getLayoutAlgorithm()

Since:
  2.0

#### setSubgraphFactory

    public void setSubgraphFactory(SubgraphFactory factory)

Since:
  2.0

#### getSubgraphFactory

    public SubgraphFactory getSubgraphFactory()

Since:
  2.0

#### setExpandCollapseManager

    public void setExpandCollapseManager(org.eclipse.gef4.layout.interfaces.ExpandCollapseManager expandCollapseManager)

Since:
  2.0

#### getExpandCollapseManager

    public org.eclipse.gef4.layout.interfaces.ExpandCollapseManager getExpandCollapseManager()

Since:
  2.0

#### 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:
  2.0

#### 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:
  2.0

#### 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

#### 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:
  2.0

#### addNode

    public void addNode(GraphNode node)

Specified by:
  `addNode` in interface `IContainer`

#### addSubgraphFigure

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

Specified by:
  `addSubgraphFigure` 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:
  2.0

#### removeFisheyeListener

    public void removeFisheyeListener(FisheyeListener listener)

Since:
  2.0

#### getItemType

    public int getItemType()

Specified by:
  `getItemType` in interface `IContainer`

#### setExpanded

    public void setExpanded(GraphNode node,
                   boolean expanded)

Since:
  2.0

#### canExpand

    public boolean canExpand(GraphNode node)

Since:
  2.0

#### canCollapse

    public boolean canCollapse(GraphNode node)

Since:
  2.0

#### getGraph

    public GraphWidget getGraph()

Specified by:
  `getGraph` in interface `IContainer`

#### getItem

    public Widget getItem()

Specified by:
  `getItem` in interface `IContainer`
Since:
  2.0

#### getLayoutBounds

    public org.eclipse.gef4.geometry.planar.Rectangle getLayoutBounds()

Specified by:
  `getLayoutBounds` in interface `IContainer`
Returns:
Since:
  2.0

#### getDefaultConnectionDecorator

    public IConnectionDecorator getDefaultConnectionDecorator()

Returns:
  The default connection decorator for undirected connections; never null

#### setDefaultConnectionDecorator

    public void setDefaultConnectionDecorator(IConnectionDecorator connectionDecorator)

Sets the connection decorator used for adding source and target decorations. Only called for undirected edges.

Parameters:
  `connectionDecorator` - the defaultConnectionDecorator to set; or null to reset to default

#### getDefaultDirectedConnectionDecorator

    public IConnectionDecorator getDefaultDirectedConnectionDecorator()

Returns:
  The default connection decorator for directed connections; never null

#### setDefaultDirectedConnectionDecorator

    public void setDefaultDirectedConnectionDecorator(IConnectionDecorator connectionDecorator)

Sets the connection decorator used for adding source and target decorations. Only called for directed edges.

Parameters:
  `connectionDecorator` - the defaultConnectionDecorator to set; or null to reset to default

#### 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:
  2.0

#### getZoomManager

    public ZoomManager getZoomManager()

Returns the ZoomManager component used for scaling the graph widget.

Returns:
  the ZoomManager component
Since:
  2.0

#### isAnimationEnabled

    public boolean isAnimationEnabled()

Returns:
  Returns true if animation is enabled for this graph.

#### setAnimationEnabled

    public void setAnimationEnabled(boolean animate)

Parameters:
  `animate` - Pass true to enable animation for this graph.