当重置透视完成E4时发生错误

时间:2014-06-10 07:03:23

标签: reset perspective e4

重置透视代码时,如在给定链接https://www.eclipse.org/forums/index.php/m/1209165/srch=reset+perspective+in+e4#msg_1209165中那样完成 和代码叫做 代码如下

public class ResetPerspective {
// private static final String MAIN_PERSPECTIVE_STACK_ID = "MainPerspectiveStack";

 @Execute
 public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
        EModelService modelService, MApplication app,
        EPartService partService) {

    MWindow window = (MWindow) modelService.find("Main", app);  //main

    final MPerspective perspective = modelService.getActivePerspective(window);

    final MUIElement snippet = modelService.cloneSnippet(app,
            perspective.getElementId(), window);
    snippet.setToBeRendered(true);
    if (snippet != null) {
        MElementContainer<MUIElement> parent = perspective.getParent();
        perspective.setToBeRendered(false);

        List<MWindow> existingDetachedWindows = new ArrayList<MWindow>();
        existingDetachedWindows.addAll(perspective.getWindows());



        MPerspective dummyPerspective = (MPerspective) snippet;
        while (dummyPerspective.getWindows().size() > 0) {
            MWindow detachedWindow = dummyPerspective.getWindows()
                    .remove(0);
            perspective.getWindows().add(detachedWindow);
        }

        parent.getChildren().remove(perspective);

        parent.getChildren().add(snippet);
        System.out.println(parent.getChildren().get(0).getElementId());
        partService.switchPerspective((MPerspective) snippet);
    }
 }

}
选择

并重置透视图会出现以下错误 错误如下

!ENTRY org.eclipse.e4.ui.workbench 4 0 2014-06-10 11:28:54.063
!MESSAGE Internal Error
!STACK 0
org.eclipse.e4.core.di.InjectionException: java.lang.IllegalArgumentException: 
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
    at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:243)
    at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:224)
    at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
    at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:167)
    at org.eclipse.core.commands.Command.executeWithChecks(Command.java:499)
    at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
    at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:213)
    at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:850)
    at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:743)
    at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:727)
    at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:662)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1057)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4170)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3759)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:140)
    at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:162)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
Caused by: java.lang.IllegalArgumentException: 
    at org.eclipse.core.runtime.Assert.isLegal(Assert.java:63)
    at org.eclipse.core.runtime.Assert.isLegal(Assert.java:47)
    at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.findElementsRecursive(ModelServiceImpl.java:286)
    at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.findElements(ModelServiceImpl.java:371)
    at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.getActivePerspective(ModelServiceImpl.java:1075)
    at bomb.handlers.ResetPerspective.execute(ResetPerspective.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
    ... 33 more

1 个答案:

答案 0 :(得分:1)

您的应用程序模型中似乎没有一个带有id&#34; Main&#34;所以modelService.find("Main", app)返回null。 null是modelService.getActivePerspective(window)的非法参数,因此您会收到错误。

您必须调整此代码,以便为您的应用程序使用ID。您还必须按照说明创建透视图的片段。