gpt4 book ai didi

java - 以编程方式触发 RCP 选择事件

转载 作者:IT老高 更新时间:2023-10-28 20:39:54 24 4
gpt4 key购买 nike

在我的 Eclipse RCP 应用程序中,我使用了选择服务,如这篇不错的 article 中所述。 .在一个注册为 SelectionProvider 的 View 中有一个 TreeViewer:

getSite().setSelectionProvider(viewer);

另一个 View 正在接收来自 TreeViewer 的事件:

selectionListener = new ISelectionListener() {
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
pageSelectionChanged(part, selection);
}
};
getSite().getPage().addSelectionListener(selectionListener);

一切正常,如果触发了我的正常鼠标点击事件。我想通过选择树中的项目以编程方式触发选择事件:

treeViewer.setSelection(new StructuredSelection(element),true);

这不起作用。方法 selectionChanged 未在接收者 View 中调用。该问题在此 forum thread 中进行了讨论.没有解决办法。

编辑

没有像编程选择一样处理鼠标触发点击的正确方法。鼠标单击会激活以编程方式选择不会激活的 View 。

我的解决方案是通过 Selection Service 以相同的方式将第二个 View 注册为第一个 View 。之后,两个 View 都直接从 Activity 编辑器获取选择事件。

最佳答案

你可以做两件事:

1) 进行选择,然后为 SWT.SELECTION 调用通知监听器,即:

mybutton.setSelection(true);
mybutton.notifyListeners(SWT.Selection, new Event());

notifyListener 方法旨在用于自定义控件,因此更正确的是您可以执行选项 2。

2) 调用您在监听器中调用的方法,即:

this.myButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(final SelectionEvent e) {
doSomethingaboutTheSelMethod();
}

在这种情况下,您可以调用:

doSomethingaboutTheSelMethod();

关于java - 以编程方式触发 RCP 选择事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9102026/

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