Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[gef-dev] gef4 removing nodes from a graph does not refresh the viewer

Hi,

I have a adapted the CustomNodeExample to provide context menu for a graph.

I observer, that the graph won't get refreshed, if I only remove nodes and edges, however if I add a node, the graph view does get refreshed.

Here is the code, that changes the contents of the graph

  private static NodeContextMenuEntry includes(Scope scope)
  {
    return new NodeContextMenuEntry("show includes", "hide includes")
    {
      @Override
      protected void offAction(Graph graph, Node scopeNode)
      {
        WorkflowScopeNodeModel scopeNodeModel = (WorkflowScopeNodeModel) NodeModel.get(scopeNode);
        List<Node> nodes = graph.getNodes();
        ListIterator<Node> nodeIter = nodes.listIterator();
        Node hack = null;
        while (nodeIter.hasNext())
        {
          Node n = nodeIter.next();
          if (scopeNodeModel.includeNodes.contains(n))
          {
            hack = n;
            nodeIter.remove();
          }
        }
        ListIterator<Edge> edgeIter = graph.getEdges().listIterator();
        while (edgeIter.hasNext())
        {
          Edge e = edgeIter.next();
          if (scopeNodeModel.includeEdges.contains(e))
          {
            edgeIter.remove();
          }
        }
        // this is a hack - I have no idea, why removing does not update the graph whereas adding does.
        if(null != hack)
        {nodes.add(hack);nodes.remove(hack);}
      }

      @Override
      protected void onAction(Graph graph, Node scopeNode)
      {
        WorkflowScopeNodeModel scopeNodeModel = (WorkflowScopeNodeModel) NodeModel.get(scopeNode);
        List<Node> nodes = graph.getNodes();
        for (Node n : scopeNodeModel.includeNodes)
        {
          nodes.add(n);
        }
        List<Edge> edges = graph.getEdges();
        for (Edge e : scopeNodeModel.includeEdges)
        {
          edges.add(e);
        }
      }
    };
  }

 

If you cannot reproduce the behaviour, I'll post a more complete example.

 

Cheers,

Arne

 


Back to the top