// This sample demonstrates how to access the
  // active (selected) element in a diagram and
  // how to perform basic navigation in the graph

  // The active diagram element is obtained via the
  // ActiveItem property of the Diagram object
  DiagramItem active = diagram.getActiveItem();

  // This might happen when there is no selected object
  if (active == null)
    return;

  // Make sure the selected object is a node
  if (!(active instanceof DiagramNode))
    return;

  DiagramNode activeNode = (DiagramNode)active;

  // Now it is possible to access the direct relatives of the active node
  ArrayList<DiagramNode> relatives = new ArrayList<DiagramNode>();

  for (DiagramLink link : activeNode.getOutgoingLinks())
    relatives.add(link.getDestination());

  for (DiagramLink link : activeNode.getIncomingLinks())
    relatives.add(link.getOrigin());