Update node label / icon in zest 2

I am using GraphViewer with SpaceTreeLayoutAlgorithm and trying to update node labels / icons after creating a graph.

Already tested options

viewer.refresh(node, true);

and

viewer.refresh(viewer.getGraphModelNode(node), true);

in combination with various methods of updating / redrawing the viewer or graph management tool, but without success.

Additional information about using the viewer:

GraphViewer viewer = new GraphViewer(parent, SWT.BORDER);
ArrayContentProvider content = new MyArrayContentProvider(..);

viewer.setContentProvider(content);
LabelProvider glp = new MyGraphLabelProvider(..);
viewer.setLabelProvider(glp);

List<MyNodeClass> nodes = .. //list of all node elements
viewer.setInput(nodes);

TriangleSubgraphFactory subGraphFactory = new TriangleSubgraphFactory();
SpaceTreeLayoutAlgorithm spaceTreeAlg = new SpaceTreeLayoutAlgorithm();

viewer.getGraphControl().setSubgraphFactory(subGraphFactory);
viewer.getGraphControl().setExpandCollapseManager(
    spaceTreeAlg.getExpandCollapseManager());
viewer.setLayoutAlgorithm(spaceTreeAlg, true);

The code works as expected, with the exception of the ones updated above.

I think that maybe I'm doing something wrong, since calling viewer.setInput (..), as Fabian recommended, is causing errors. I also cannot use SpaceTreeLayoutAlgorithm (int direction) with any direction other than TOP_DOWN, otherwise I get NPE.

A call to viewer.setInput later calls the following:

Caused by: java.util.NoSuchElementException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:813)
at java.util.HashMap$KeyIterator.next(HashMap.java:845)
at org.eclipse.zest.core.widgets.custom.TriangleSubgraph.updateFigure(TriangleSubgraph.java:169)
at org.eclipse.zest.core.widgets.custom.TriangleSubgraph$1.defaultHandle(TriangleSubgraph.java:147)
at org.eclipse.zest.layouts.algorithms.TreeLayoutObserver$TreeListener.nodeRemoved(TreeLayoutObserver.java:308)
at org.eclipse.zest.layouts.algorithms.TreeLayoutObserver$1.nodeRemoved(TreeLayoutObserver.java:344)
at org.eclipse.zest.core.widgets.InternalLayoutContext.fireNodeRemovedEvent(InternalLayoutContext.java:399)
at org.eclipse.zest.core.widgets.InternalNodeLayout.dispose(InternalNodeLayout.java:327)
at org.eclipse.zest.core.widgets.Graph.removeNode(Graph.java:977)
at org.eclipse.zest.core.widgets.GraphNode.dispose(GraphNode.java:188)
at org.eclipse.zest.core.viewers.AbstractStructuredGraphViewer.inputChanged(AbstractStructuredGraphViewer.java:494)
at org.eclipse.zest.core.viewers.GraphViewer.inputChanged(GraphViewer.java:136)
at org.eclipse.jface.viewers.ContentViewer.setInput(ContentViewer.java:280)
at org.eclipse.jface.viewers.StructuredViewer.setInput(StructuredViewer.java:1690)

The following steps are for updating, but it may not be for use:

GraphLabelProvider glp
GraphNode n = viewer.getGraphModelNode(node);
n.setText(glp.getText(node));
n.setImage(glp.getImage(node));
+3
1

, , , , reset , ( - ). :

viewer.setInput(myChangedDataToBeVisualized);
+2

All Articles