protected void filterVisuals() {
   if (getGraphControl() == null) {
     return;
   }
   Object[] filtered = getFilteredChildren(getInput());
   SimpleGraphComparator comparator = new SimpleGraphComparator();
   TreeSet filteredElements = new TreeSet(comparator);
   TreeSet unfilteredElements = new TreeSet(comparator);
   List connections = getGraphControl().getConnections();
   List nodes = getGraphControl().getNodes();
   if (filtered.length == 0) {
     // set everything to invisible.
     // @tag zest.bug.156528-Filters.check : should we only filter out
     // the nodes?
     for (Iterator i = connections.iterator(); i.hasNext(); ) {
       GraphConnection c = (GraphConnection) i.next();
       c.setVisible(false);
     }
     for (Iterator i = nodes.iterator(); i.hasNext(); ) {
       GraphNode n = (GraphNode) i.next();
       n.setVisible(false);
     }
     return;
   }
   for (Iterator i = connections.iterator(); i.hasNext(); ) {
     GraphConnection c = (GraphConnection) i.next();
     if (c.getExternalConnection() != null) {
       unfilteredElements.add(c);
     }
   }
   for (Iterator i = nodes.iterator(); i.hasNext(); ) {
     GraphNode n = (GraphNode) i.next();
     if (n.getData() != null) {
       unfilteredElements.add(n);
     }
   }
   for (int i = 0; i < filtered.length; i++) {
     Object modelElement = connectionsMap.get(filtered[i]);
     if (modelElement == null) {
       modelElement = nodesMap.get(filtered[i]);
     }
     if (modelElement != null) {
       filteredElements.add(modelElement);
     }
   }
   unfilteredElements.removeAll(filteredElements);
   // set all the elements that did not pass the filters to invisible, and
   // all the elements that passed to visible.
   while (unfilteredElements.size() > 0) {
     GraphItem i = (GraphItem) unfilteredElements.first();
     i.setVisible(false);
     unfilteredElements.remove(i);
   }
   while (filteredElements.size() > 0) {
     GraphItem i = (GraphItem) filteredElements.first();
     i.setVisible(true);
     filteredElements.remove(i);
   }
 }
  @Override
  public void selfStyleNode(Object element, GraphNode node) {
    if (element == focusObject) {
      node.setBackgroundColor(FOCUS_COLOR);
    }

    node.setHighlightColor(getNodeHighlightColor(element));
    node.setTooltip(getTooltip(element));
  }
 void removeGraphModelNode(Object obj) {
   GraphNode node = (GraphNode) nodesMap.get(obj);
   if (node != null) {
     nodesMap.remove(obj);
     if (!node.isDisposed()) {
       node.dispose();
     }
   }
 }
 GraphNode addGraphModelNode(IContainer container, Object element) {
   GraphNode node = this.getGraphModelNode(element);
   if (node == null) {
     node = new GraphNode(container, SWT.NONE);
     this.nodesMap.put(element, node);
     node.setData(element);
   }
   return node;
 }
 GraphNode addGraphModelContainer(Object element) {
   GraphNode node = this.getGraphModelNode(element);
   if (node == null) {
     node = new GraphContainer((Graph) getControl(), SWT.NONE);
     this.nodesMap.put(element, node);
     node.setData(element);
   }
   return node;
 }
 public void unReveal(Object element) {
   Widget[] items = this.findItems(element);
   for (int i = 0; i < items.length; i++) {
     Widget item = items[i];
     if (item instanceof GraphNode) {
       GraphNode graphModelNode = (GraphNode) item;
       graphModelNode.unhighlight();
     } else if (item instanceof GraphConnection) {
       GraphConnection graphModelConnection = (GraphConnection) item;
       graphModelConnection.unhighlight();
     }
   }
 }
  /**
   * Removes the given element from the layout algorithm and the model.
   *
   * @param element The node element to remove.
   */
  public void removeNode(Object element) {
    GraphNode node = (GraphNode) nodesMap.get(element);

    if (node != null) {
      // remove the node from the layout algorithm and all the connections
      if (getLayoutAlgorithm() != null) {
        getLayoutAlgorithm().removeEntity(node.getLayoutEntity());
        getLayoutAlgorithm().removeRelationships(node.getSourceConnections());
        getLayoutAlgorithm().removeRelationships(node.getTargetConnections());
      }
      // remove the node and it's connections from the model
      node.dispose();
    }
  }
 GraphNode addGraphModelNode(Object element, IFigure figure) {
   GraphNode node = this.getGraphModelNode(element);
   if (node == null) {
     if (figure != null) {
       node = new CGraphNode((Graph) getControl(), SWT.NONE, figure);
       this.nodesMap.put(element, node);
       node.setData(element);
     } else {
       node = new GraphNode((Graph) getControl(), SWT.NONE);
       this.nodesMap.put(element, node);
       node.setData(element);
     }
   }
   return node;
 }
  public static void main(String[] args) {

    Display d = new Display();
    final Shell shell = new Shell(d);
    shell.setText("Animation Example");
    shell.setLayout(new FillLayout(SWT.VERTICAL));
    shell.setSize(400, 400);

    Button b = new Button(shell, SWT.PUSH);
    b.setText("Animate");

    final Graph g = new Graph(shell, SWT.NONE);

    final GraphNode n = new GraphNode(g, SWT.NONE, "Paper");
    final GraphNode n2 = new GraphNode(g, SWT.NONE, "Rock");

    b.addSelectionListener(
        new SelectionListener() {
          public void widgetDefaultSelected(SelectionEvent e) {}

          public void widgetSelected(SelectionEvent e) {
            Animation.markBegin();
            n2.setLocation(0, 0);
            n.setLocation(g.getSize().x - n2.getSize().width - 5, 0);
            Animation.run(1000);
          }
        });

    new GraphConnection(g, SWT.NONE, n, n2);

    int centerX = shell.getSize().x / 2;
    int centerY = shell.getSize().y / 4;

    n.setLocation(centerX, centerY);
    n2.setLocation(centerX, centerY);

    shell.open();
    while (!shell.isDisposed()) {
      while (!d.readAndDispatch()) {
        d.sleep();
      }
    }
  }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.jface.viewers.StructuredViewer#getRawChildren(java.lang.Object)
  */
 protected Object[] getRawChildren(Object parent) {
   if (parent == getInput()) {
     // get the children from the model.
     LinkedList children = new LinkedList();
     if (getGraphControl() != null) {
       List connections = getGraphControl().getConnections();
       List nodes = getGraphControl().getNodes();
       for (Iterator i = connections.iterator(); i.hasNext(); ) {
         GraphConnection c = (GraphConnection) i.next();
         if (c.getExternalConnection() != null) {
           children.add(c.getExternalConnection());
         }
       }
       for (Iterator i = nodes.iterator(); i.hasNext(); ) {
         GraphNode n = (GraphNode) i.next();
         if (n.getData() != null) {
           children.add(n.getData());
         }
       }
       return children.toArray();
     }
   }
   return super.getRawChildren(parent);
 }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object,
   *      java.lang.Object)
   */
  protected void inputChanged(Object input, Object oldInput) {
    IStylingGraphModelFactory factory = getFactory();
    factory.setConnectionStyle(getConnectionStyle());
    factory.setNodeStyle(getNodeStyle());

    // Save the old map so we can set the size and position of any nodes
    // that are the same
    Map oldNodesMap = nodesMap;
    Graph graph = (Graph) getControl();
    graph.setSelection(new GraphNode[0]);

    Iterator iterator = nodesMap.values().iterator();
    while (iterator.hasNext()) {
      GraphNode node = (GraphNode) iterator.next();
      if (!node.isDisposed()) {
        node.dispose();
      }
    }

    iterator = connectionsMap.values().iterator();
    while (iterator.hasNext()) {
      GraphConnection connection = (GraphConnection) iterator.next();
      if (!connection.isDisposed()) {
        connection.dispose();
      }
    }

    nodesMap = new HashMap();
    connectionsMap = new HashMap();

    graph = factory.createGraphModel(graph);

    ((Graph) getControl()).setNodeStyle(getNodeStyle());
    ((Graph) getControl()).setConnectionStyle(getConnectionStyle());

    // check if any of the pre-existing nodes are still present
    // in this case we want them to keep the same location & size
    for (Iterator iter = oldNodesMap.keySet().iterator(); iter.hasNext(); ) {
      Object data = iter.next();
      GraphNode newNode = (GraphNode) nodesMap.get(data);
      if (newNode != null) {
        GraphNode oldNode = (GraphNode) oldNodesMap.get(data);
        newNode.setLocation(oldNode.getLocation().x, oldNode.getLocation().y);
        if (oldNode.isSizeFixed()) {
          newNode.setSize(oldNode.getSize().width, oldNode.getSize().height);
        }
      }
    }

    applyLayout();
  }
  @Override
  protected Control createDialogArea(Composite parent) {
    //		toolkit = new FormToolkit(parent.getDisplay());
    //		form = toolkit.createScrolledForm(parent);
    //		form.setText("Dependency Graph UI Legend");
    //		form.getToolBarManager().add(new Action("Close Dialog", MavenEditorImages.CLEAR) {
    //		  public void run() {
    //	      close();
    //		  }
    //		});
    //		form.getToolBarManager().update(true);
    //		form.getBody().setLayout(new TableWrapLayout());
    //		toolkit.decorateFormHeading(form.getForm());

    Graph g =
        new Graph(parent, SWT.NONE) {
          public org.eclipse.swt.graphics.Point computeSize(int wHint, int hHint, boolean changed) {
            return new org.eclipse.swt.graphics.Point(260, 300);
          }
        };
    g.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);
    g.setEnabled(false);

    {
      GraphNode n1 = new GraphNode(g, SWT.NONE, " compile scope dependency ");
      n1.setLocation(10, 10);
      n1.setSize(240, 25);
    }

    {
      GraphNode n1 = new GraphNode(g, SWT.NONE, " non-compile scope dependency ");
      n1.setLocation(10, 40);
      n1.setSize(240, 25);
      n1.setBackgroundColor(colorTestBackground);
    }

    {
      GraphNode n1 = new GraphNode(g, SWT.NONE, " selected dependency ");
      n1.setLocation(10, 70);
      n1.setSize(240, 25);
      n1.setBackgroundColor(colorSelectedBackground);
    }

    {
      GraphNode n1 = new GraphNode(g, SWT.NONE, " selected non-compile ");
      n1.setLocation(10, 100);
      n1.setSize(240, 25);
      n1.setBackgroundColor(colorSelectedTestBackground);
    }

    {
      GraphNode n1 = new GraphNode(g, SWT.NONE, "    ");
      GraphNode n2 = new GraphNode(g, SWT.NONE, "    ");

      DependencyConnection c1 = new DependencyConnection(g, SWT.NONE, n1, n2);
      c1.setText("compile scope");
      c1.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED | ZestStyles.CONNECTIONS_SOLID);

      n1.setLocation(10, 140);
      n2.setLocation(220, 140);
    }

    {
      GraphNode n1 = new GraphNode(g, SWT.NONE, "    ");
      GraphNode n2 = new GraphNode(g, SWT.NONE, "    ");
      n2.setBackgroundColor(colorTestBackground);

      GraphConnection c1 = new DependencyConnection(g, SWT.NONE, n1, n2);
      c1.setText("non-compile scope");
      c1.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED | ZestStyles.CONNECTIONS_DOT);
      c1.setLineColor(colorTestRel);

      n1.setLocation(10, 170);
      n2.setLocation(220, 170);
    }

    {
      GraphNode n1 = new GraphNode(g, SWT.NONE, "    ");
      GraphNode n2 = new GraphNode(g, SWT.NONE, "    ");

      GraphConnection c1 = new DependencyConnection(g, SWT.NONE, n1, n2);
      c1.setText("resolved conflict");
      c1.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED | ZestStyles.CONNECTIONS_SOLID);
      c1.setLineColor(colorRelResolved);

      n1.setLocation(10, 200);
      n2.setLocation(220, 200);
    }

    {
      GraphNode n1 = new GraphNode(g, SWT.NONE, "    ");
      GraphNode n2 = new GraphNode(g, SWT.NONE, "    ");
      n2.setBackgroundColor(colorSelectedBackground);

      GraphConnection c1 = new DependencyConnection(g, SWT.NONE, n1, n2);
      c1.setText("referenced from selected");
      c1.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED | ZestStyles.CONNECTIONS_SOLID);
      c1.setLineColor(highlighted);
      c1.setLineWidth(3);

      n1.setLocation(10, 230);
      n2.setLocation(220, 230);
    }

    {
      GraphNode n1 = new GraphNode(g, SWT.NONE, "    ");
      GraphNode n2 = new GraphNode(g, SWT.NONE, "    ");
      n2.setBackgroundColor(colorSelectedTestBackground);

      GraphConnection c1 = new DependencyConnection(g, SWT.NONE, n1, n2);
      c1.setText("referenced from non-compile");
      c1.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED | ZestStyles.CONNECTIONS_DOT);
      c1.setLineColor(highlighted);
      c1.setLineWidth(3);

      n1.setLocation(10, 260);
      n2.setLocation(220, 260);
    }

    g.addFocusListener(
        new FocusAdapter() {
          public void focusLost(FocusEvent e) {
            close();
          }
        });

    return parent;
  }