如果在Eclipse E4中显示进度条,则在打开MPart时出现异常

时间:2014-12-19 11:15:05

标签: java eclipse eclipse-plugin eclipse-rcp e4

在eclipse E4中,我试图在进度对话框中打开一个MPart(即显示进度条,直到Mpart不会显示/加载内容),但我得到的是异常:

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(); // $ NON-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。

0 个答案:

没有答案