gpt4 book ai didi

java - 更新 zest 2 中节点的标签/图标

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:33:42 26 4
gpt4 key购买 nike

我正在使用带有 SpaceTreeLayoutAlgorithm 的 GraphViewer 并尝试在创建图形后更新节点的标签/图标。

已经测试过的变体

viewer.refresh(node, true);

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

结合查看器或其图形控件的各种刷新/重绘方法,但没有成功。

有关查看器使用情况的更多详细信息:

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);

代码按预期工作,除了我上面提到的刷新。

我想我可能做错了什么,因为按照 Fabian 的建议调用 viewer.setInput(..) 会导致错误。我也没有设法将 SpaceTreeLayoutAlgorithm(int direction) 与除 TOP_DOWN 以外的任何方向一起使用,否则我会得到 NPE。

稍后调用 viewer.setInput 会导致:

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)

以下用于刷新,但这不可能是预期用途:

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

最佳答案

我不确定您是如何使用查看器的,但最简单的方法可能是将查看器的输入重置为您想要可视化的新数据(您在内容和标签提供程序中处理)。当您设置输入时,图表会自动更新:

viewer.setInput(myChangedDataToBeVisualized);

关于java - 更新 zest 2 中节点的标签/图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10711024/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com