我想克隆一个透视图并保存该克隆的透视图。但是,对PerspectiveRegistry.clonePerspective(...)
的调用返回null,并且我的想法用光了,我的参数值可能有问题。
public void savePerspectiveAs(String label) {
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
IPerspectiveDescriptor perspectiveDescriptor = perspectiveRegistry
.findPerspectiveWithLabel(label);
// if the perspective doesn't exist, create a new one
// by cloning the current perspective
if (perspectiveDescriptor == null) {
IPerspectiveDescriptor currentPerspectiveDescriptor =
perspectiveRegistry.findPerspectiveWithId(currentPerspective);
// after this line, perspectiveDescriptor is still null
perspectiveDescriptor = perspectiveRegistry
.clonePerspective(currentPerspective + "."
+ label.replaceAll(" ", "_"), label,
currentPerspectiveDescriptor);
// hence I get a NullPointerException here...
connectedPerspectives.add(perspectiveDescriptor.getId());
}
page.savePerspectiveAs(perspectiveDescriptor);
}
所有其他值似乎都很好。
currentPerspectiveDescriptor
是有效对象,perspectiveRegistry
也是如此。label
类似于"Connected Perspective 2"
。它尚不存在,我创建的透视图ID也没有。有任何想法吗?
clonePerspective(...)
返回空值在这里可能出什么问题? 最佳答案
Eclipse 4.x不支持clonePerspective
。
这是PerspectiveRegistry.clonePerspective
的代码:
public IPerspectiveDescriptor clonePerspective(String id, String label,
IPerspectiveDescriptor desc) throws IllegalArgumentException {
// FIXME: compat clonePerspective. Not called in 3.8
E4Util.unsupported("clonePerspective"); //$NON-NLS-1$
return null;
}
Eclipse错误是382209
关于java - Eclipse RCP:clonePerspective返回null,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26384842/