2013-10-31 4 views

답변

3

다른 사람들에게 시간을 절약하고 자신을 문서화 할 수 있다고 생각했습니다.

다음과 같이 E4 관점은 다시 할 수있을 트릭은 (PerspectiveStack 요소와 기본 application.e4xmi 가정) : 당신의 응용 프로그램 아래 PerspectiveStack을 찾아 당신의 application.e4xmi 파일에서

  1. 을/TrimmedWindow 마디. ID 기록/설정.
  2. Eclipse 4 Model Editor에서 PerspectiveStack 아래의 Perspective를 Application/Snippets로 드래그하십시오. (이는 원근감 ID가 IPerspectiveRegistry에 등록하고 원시 상태를 제공하게합니다).
  3. 새 CopyPerspectiveSnippetProcessor를 만듭니다. 그러면 시작할 때 Snippets의 Perspective가 PerspectiveStack으로 복사됩니다. 이렇게하면 e4xmi 파일에 각 원근감 요소의 사본 두 개를 유지할 필요가 없습니다.

    package com.example.application.processors; 
    
    import org.eclipse.e4.core.di.annotations.Execute; 
    import org.eclipse.e4.ui.model.application.MApplication; 
    import org.eclipse.e4.ui.model.application.ui.MUIElement; 
    import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; 
    import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack; 
    import org.eclipse.e4.ui.workbench.modeling.EModelService; 
    
    /** 
    * Copies all snippet perspectives to perspective stack called "MainPerspectiveStack" In order to register/reset perspective and not have to sync two copies in 
    * e4xmi. 
    * 
    */ 
    public class CopyPerspectiveSnippetProcessor { 
        private static final String MAIN_PERSPECTIVE_STACK_ID = "MainPerspectiveStack"; 
    
        @Execute 
        public void execute(EModelService modelService, MApplication application) { 
         MPerspectiveStack perspectiveStack = (MPerspectiveStack) modelService.find(MAIN_PERSPECTIVE_STACK_ID, application); 
    
         // Only do this when no other children, or the restored workspace state will be overwritten. 
         if (!perspectiveStack.getChildren().isEmpty()) 
          return; 
    
         // clone each snippet that is a perspective and add the cloned perspective into the main PerspectiveStack 
         boolean isFirst = true; 
         for (MUIElement snippet : application.getSnippets()) { 
          if (snippet instanceof MPerspective) { 
           MPerspective perspectiveClone = (MPerspective) modelService.cloneSnippet(application, snippet.getElementId(), null); 
           perspectiveStack.getChildren().add(perspectiveClone); 
           if (isFirst) { 
            perspectiveStack.setSelectedElement(perspectiveClone); 
            isFirst = false; 
           } 
          } 
         } 
        } 
    } 
    
  4. CopyPerspectiveSnippetProcess를 plugin.xml 파일에 등록하십시오.

    <extension id="MainAppModel" point="org.eclipse.e4.workbench.model"> 
        <processor beforefragment="false" class="com.example.application.processors.CopyPerspectiveSnippetProcessor"/> 
    </extension> 
    
  5. 원근법을 정상적으로 재설정하십시오. 퍼스펙티브 스택과 현재 퍼스펙티브를 보이지 않게 설정할 수 있기 때문에 퍼스펙티브 스택과 현재 퍼스펙티브를 가시로 설정하기를 원할 것이다. 당신은 질문 같은 질문 부분을 작성하고 답변으로 대답을 넣어해야

    import org.eclipse.e4.core.di.annotations.Execute; 
    import org.eclipse.e4.ui.model.application.MApplication; 
    import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack; 
    import org.eclipse.e4.ui.workbench.modeling.EModelService; 
    import org.eclipse.ui.PlatformUI; 
    
    public class ResetPerspectiveHandler { 
        private static final String MAIN_PERSPECTIVE_STACK_ID = "MainPerspectiveStack"; 
    
        @Execute 
        public void execute(EModelService modelService, MApplication application) { 
         MPerspectiveStack perspectiveStack = (MPerspectiveStack) modelService.find(MAIN_PERSPECTIVE_STACK_ID, application); 
         PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().resetPerspective(); 
         perspectiveStack.getSelectedElement().setVisible(true); 
         perspectiveStack.setVisible(true); 
        } 
    } 
    
+0

지속적인 작업 공간 상태를 덮어 쓰지 않도록 테스트를 추가했습니다. – n8n8baby

+0

이 방법을 사용하면 UI 요소 차원 지속성 같은 것을 방해 할 수 있으므로 부작용이 용납되지 않을 수 있음을 알아 냈습니다. UI를 제한하여 퍼스펙티브 재설정에 대한 요구 사항을 제거 할 수있었습니다. – n8n8baby