Java 如果进度条在Eclipse4中显示,则打开MPart时发生异常
在Eclipse4中,我试图在progress对话框I.e下打开一个MPart。进度条将一直显示,直到Mpart不显示/加载内容,但我得到以下异常:Java 如果进度条在Eclipse4中显示,则打开MPart时发生异常,java,eclipse,eclipse-plugin,eclipse-rcp,e4,Java,Eclipse,Eclipse Plugin,Eclipse Rcp,E4,在Eclipse4中,我试图在progress对话框I.e下打开一个MPart。进度条将一直显示,直到Mpart不显示/加载内容,但我得到以下异常: Caused by: java.lang.IllegalStateException: Application does not have an active window at org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl.getActiveWindowSe
Caused by: java.lang.IllegalStateException: Application does not have an active window
at org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl.getActiveWindowService(ApplicationPartServiceImpl.java:43)
at org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl.getParts(ApplicationPartServiceImpl.java:92)
at org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl.getParts(ApplicationPartServiceImpl.java:92)
at com.gui.common.utils.ViewUtils.createPart(ViewUtils.java:549)
... 49 more
下面是我用来打开MPart的代码:
IEclipseContext serviceContext=E4Workbench.getServiceContext;
最终IEclipseContext appContext=IEclipseContext serviceContext
.getActiveChild//$非NLS-1$
EModelService modelService = appContext.get(EModelService.class);
MApplication app = serviceContext.get(MApplication.class);
EPartService partService = serviceContext.get(EPartService.class);
MPerspective activePerspective = modelService
.getActivePerspective(app.getSelectedElement());
List<MPartStack> stacks = modelService.findElements(
activePerspective, null, MPartStack.class, null,
EModelService.IN_ACTIVE_PERSPECTIVE);
List<MPart> parts = modelService.findElements(
activePerspective, null, MPart.class, null,
EModelService.IN_ACTIVE_PERSPECTIVE);
MPartStack stack = null;
for (MPartStack foundStack : stacks) {
if (foundStack.getElementId().indexOf(stackType) >= 0) {
stack = foundStack;
break;
}
}
if (stack != null) {
MPart part = null;
// Create a new Part
String viewIDtoDisplay = null;
if(secondaryID!=null){
viewIDtoDisplay=viewID + RvsConstants.COLON + secondaryID;
}else{
viewIDtoDisplay=viewID;
}
for (MPart openedParts : parts) {
if (openedParts.getElementId().equalsIgnoreCase(
viewIDtoDisplay)) {
part = openedParts;
}
}
if (part == null) {
part = modelService.createModelElement(MPart.class);
part.setElementId(viewIDtoDisplay);
part.setContributionURI(COMPATIBILITY_VIEW);
part.setCloseable(true);
if (isClosable) {
part.getTags().add(REMOVE_ON_EXIT);
}
part.getTags().add(EPartService.REMOVE_ON_HIDE_TAG);
MElementContainer<MUIElement> parent = null;
for (MStackElement element : stack.getChildren()) {
if (element instanceof MPlaceholder) {
MPlaceholder holder = (MPlaceholder) element;
if (holder.getRef().getElementId()
.equalsIgnoreCase(viewID)) {
holder.setWidget(part);
parent = holder.getParent();
}
}
}
if (parent != null) {
part.setParent(parent);
}
}
partService.showPart(part, PartState.ACTIVATE); // Show part
ViewReference ref = ((WorkbenchPage) PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage())
.getViewReference(part);
IViewPart viewRef = ref.getView(true);
这不是一个纯粹的E4应用程序,我使用的是Compat层。
如果我不使用进度条,则永远不会发生异常,Mpart将顺利打开。因此,如果进度条显示,是否有办法打开Mpart。Hi@Gaurav能否请您提供一些代码?如果不查看您编写的代码,就很难确定问题出在哪里。看起来您正在对应用程序使用EPartService,您可能需要对当前窗口使用EPartService。@greg-449,问题是我试图在作业中打开MPart列表,我们有一个要求,在前2秒的进度条不应该显示。因此,当进度条在应用程序i.e中显示2秒后出现上述异常时,请您指导我如何确保我使用的是当前的window EpartService,因为我无法预测进度条何时显示displaying@greg-449,如何在应用程序中获得当前的部分服务,似乎这就是解决方案?您可以在应用程序上下文上使用getActiveLeaf来获取活动上下文,并从上下文中获取服务。但这或多或少正是应用程序部分服务所要做的。