when reset perspective is done on E4 error occurs

自作多情 提交于 2020-01-07 03:27:17

问题


When reset Perspective code is done as in the given link https://www.eclipse.org/forums/index.php/m/1209165/srch=reset+perspective+in+e4#msg_1209165 and code called is The code is as follows

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);
    }
 }

}

and reset perspective is selected gives the following error The error is as follows

!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:


It looks like you do not have a window in your application model with the id "Main" so modelService.find("Main", app) is returning null. null is an illegal argument for modelService.getActivePerspective(window) so you get an error.

You must adapt this code you found to use the ids for your application. You must also follow the instructions for creating snippets for the perspectives.



来源:https://stackoverflow.com/questions/24134818/when-reset-perspective-is-done-on-e4-error-occurs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!