3

我有一个 TreeViewer,其中一些节点代表文件夹,所以我想在节点展开时显示打开文件夹的图标,在节点折叠时显示关闭文件夹的图标。听起来很简单,我只需要添加一个树监听器(代码在 Scala 中,但 Java 等价物应该很容易想象):

val tree = new TreeViewer(contents)
tree.addTreeListener(folderIconFixingListener)

private def folderIconFixingListener = new ITreeViewerListener {
  def treeCollapsed(event: TreeExpansionEvent) {
    tree.update(event.getElement, null)
  }

  def treeExpanded(event: TreeExpansionEvent) {
    tree.update(event.getElement, null)      
  }
}

不幸的是,这给出了一个例外:

Ignored reentrant call while viewer is busy. This is only logged once per viewer instance, but similar calls will still be ignored.
java.lang.RuntimeException
    at org.eclipse.jface.viewers.ColumnViewer.checkBusy(ColumnViewer.java:763)
    at org.eclipse.jface.viewers.ColumnViewer.update(ColumnViewer.java:552)
    at scsadmin.NodesTreeScreen$$anon$1.treeExpanded(NodesTreeScreen.scala:64)
    at org.eclipse.jface.viewers.AbstractTreeViewer$3.run(AbstractTreeViewer.java:1101)
    at org.eclipse.jface.util.SafeRunnable$1.run(SafeRunnable.java:128)
    at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
    at org.eclipse.jface.viewers.AbstractTreeViewer.fireTreeExpanded(AbstractTreeViewer.java:1099)
    at org.eclipse.jface.viewers.AbstractTreeViewer.handleTreeExpand(AbstractTreeViewer.java:1444)
    at org.eclipse.jface.viewers.TreeViewer.handleTreeExpand(TreeViewer.java:937)
    at org.eclipse.jface.viewers.AbstractTreeViewer$4.treeExpanded(AbstractTreeViewer.java:1453)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
    at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
    at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
    at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
    at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
    at org.eclipse.swt.widgets.Tree.gtk_test_expand_row(Unknown Source)
    at org.eclipse.swt.widgets.Widget.windowProc(Unknown Source)
    at org.eclipse.swt.widgets.Display.windowProc(Unknown Source)
    at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method)
    at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(Unknown Source)
    at org.eclipse.swt.widgets.Display.eventProc(Unknown Source)
    at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
    at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(Unknown Source)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
    at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
    at org.eclipse.jface.window.Window.open(Window.java:801)
    at scsadmin.BootStrapper$.main(BootStrapper.scala:64)
    at scsadmin.BootStrapper.main(BootStrapper.scala)

我怎样才能解决这个问题?

4

2 回答 2

3

您可能会尝试将您的代码在您的侦听器中放入 asyncExec 中,以稍微推迟其执行:

display.asyncExec(new Runnable(){
   public void run(){
      tree.update(.);
   }
});
于 2010-07-04T10:00:13.240 回答
0

我最终采用的解决方案是TreeListenerTree控件本身上使用 a ,效果很好。

于 2010-07-09T18:50:55.320 回答