Class Graph

All Implemented Interfaces:
Drawable, IContainer, IContainer2

public class Graph extends FigureCanvas implements IContainer2
Holds the nodes and connections for the graph.
Since:
1.0
  • Field Details

    • ANIMATION_TIME

      public static final int ANIMATION_TIME
      See Also:
    • FISHEYE_ANIMATION_TIME

      public static final int FISHEYE_ANIMATION_TIME
      See Also:
    • 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 class will be removed in a future release in accordance with the two year deprecation policy.
      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 class will be removed in a future release in accordance with the two year deprecation policy.
      Sets the constraint adapters on this model
      Parameters:
      constraintAdapters -
    • getRootLayer

      public 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:
    • getConnectionStyle

      public int getConnectionStyle()
      Gets the default connection style.
      Returns:
      the connection style
      See Also:
    • setNodeStyle

      public void setNodeStyle(int nodeStyle)
      Sets the default node style.
      Parameters:
      nodeStyle - the node style to set
      See Also:
    • getNodeStyle

      public int getNodeStyle()
      Gets the default node style.
      Returns:
      the node style
      See Also:
    • setGraphStyle

      public final void setGraphStyle(int style)
      Sets the default graph style.
      Parameters:
      style - the graph style to set.
      Since:
      1.15
      See Also:
    • 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 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 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(IFigure figure)
      Specified by:
      addSubgraphFigure in interface IContainer2
      Parameters:
      figure -
      @noreference
      This method is not intended to be referenced by clients.
    • createLayers

      protected 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(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(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