Java 如果分离视图,则活动透视图为空
如果我右键单击并分离视图,Java 如果分离视图,则活动透视图为空,java,eclipse-rcp,e4,Java,Eclipse Rcp,E4,如果我右键单击并分离视图,modelService.getActivePerspective(窗口)开始返回null。这意味着重置透视图无法正常工作 如果未分离视图,它将正常工作。我认为,当一个新窗口打开时,它将通过一个不包含透视图的不同窗口 示例 public class ResetPerspectiveHandler { @Execute public static void resetPerspective(final MApplication app, final EPa
modelService.getActivePerspective(窗口)
开始返回null。这意味着重置透视图无法正常工作
如果未分离视图,它将正常工作。我认为,当一个新窗口打开时,它将通过一个不包含透视图的不同窗口
示例
public class ResetPerspectiveHandler {
@Execute
public static void resetPerspective(final MApplication app, final EPartService partService,
final EModelService modelService, final MWindow window) {
// Prints null
System.out.println(modelService.getActivePerspective(window));
PerspectiveSnippetsCopier.resetPerspective(modelService, partService, app, window,
modelService.getActivePerspective(window).getElementId());
}
}
这可能是什么原因造成的 getActivePerspective的代码是:
public MPerspective getActivePerspective(MWindow window) {
List<MPerspectiveStack> pStacks = findElements(window, null, MPerspectiveStack.class);
if (pStacks.size() == 1) {
MPerspective perspective = pStacks.get(0).getSelectedElement();
return perspective;
}
return null;
}
这是有道理的。我现在可以成功地获取主窗口并重置其透视图。问题是分离的视图不关闭,因为它们是单独的窗口。如何获取应用程序中的所有窗口?因此,我可以处理所有不是主窗口的窗口。我可以通过id查看如何获取windows,但无法查看如何获取所有窗口。
modelService.findElements(app,null,MWindow.class)
将返回应用程序中的窗口列表。啊,我没有意识到null可以作为id传入。感谢您一如既往的帮助!
MWindow mainWindow = (MWindow)modelService.find("main window id", app);