Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在EclipseRCP中检测工作台部件停靠到另一个窗口_Eclipse_Eclipse Rcp - Fatal编程技术网

如何在EclipseRCP中检测工作台部件停靠到另一个窗口

如何在EclipseRCP中检测工作台部件停靠到另一个窗口,eclipse,eclipse-rcp,Eclipse,Eclipse Rcp,我有两个窗口的EclipseRCP应用程序。 每个窗口都包含一些视图/编辑器。 一旦视图/编辑器从一个窗口移动到另一个窗口,我需要执行一些操作。所以,我需要某种方式检测到该部件停靠在另一个窗口中 目前,我找到的唯一解决方案是在每个partActivated事件上比较part的workbench窗口和E4 model窗口: IEditorPart editor = ... MPart editorPart = (MPart) editor.getSite().getService(MPart.cl

我有两个窗口的EclipseRCP应用程序。 每个窗口都包含一些视图/编辑器。 一旦视图/编辑器从一个窗口移动到另一个窗口,我需要执行一些操作。所以,我需要某种方式检测到该部件停靠在另一个窗口中

目前,我找到的唯一解决方案是在每个
partActivated
事件上比较part的workbench窗口和E4 model窗口:

IEditorPart editor = ...
MPart editorPart = (MPart) editor.getSite().getService(MPart.class);
EModelService modelService =  editorPart.getContext().get(EModelService.class);
MWindow window = modelService.getTopLevelWindowFor(editorPart);
IWorkbenchWindow workbenchWindow = window.getContext().get(IWorkbenchWindow.class);
if (workbenchWindow != editor.getSite().getWorkbenchWindow()) {
    // Editor was docked to another window
    ...
}
这种方法之所以有效,是因为一旦零件移动到另一个窗口,它的
editor.getSite().getWorkbenchWindow()
窗口将指向旧窗口,而从E4模型获得的窗口将指向零件当前抵制的窗口


但是这看起来很难看,应该有更好的解决方案。

您是否尝试在两个窗口上使用
IPartListener
查看是否获得部件事件?当部件停靠到另一个窗口
IPartListener
接收
部件激活
事件时。它不允许确定零件是否已停靠或仅激活。