application.e4xmi 파일에 퍼스펙티브를 작성한 후 IWorkbenchPage.resetPerspective()를 호출하여 퍼스펙티브를 재설정 할 수 없습니다.Eclipse e4 RCP 애플리케이션의 퍼스펙티브를 어떻게 재설정합니까?
2
A
답변
3
다른 사람들에게 시간을 절약하고 자신을 문서화 할 수 있다고 생각했습니다.
다음과 같이 E4 관점은 다시 할 수있을 트릭은 (PerspectiveStack 요소와 기본 application.e4xmi 가정) : 당신의 응용 프로그램 아래 PerspectiveStack을 찾아 당신의 application.e4xmi 파일에서
- 을/TrimmedWindow 마디. ID 기록/설정.
- Eclipse 4 Model Editor에서 PerspectiveStack 아래의 Perspective를 Application/Snippets로 드래그하십시오. (이는 원근감 ID가 IPerspectiveRegistry에 등록하고 원시 상태를 제공하게합니다).
새 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; } } } } }
CopyPerspectiveSnippetProcess를 plugin.xml 파일에 등록하십시오.
<extension id="MainAppModel" point="org.eclipse.e4.workbench.model"> <processor beforefragment="false" class="com.example.application.processors.CopyPerspectiveSnippetProcessor"/> </extension>
원근법을 정상적으로 재설정하십시오. 퍼스펙티브 스택과 현재 퍼스펙티브를 보이지 않게 설정할 수 있기 때문에 퍼스펙티브 스택과 현재 퍼스펙티브를 가시로 설정하기를 원할 것이다. 당신은 질문 같은 질문 부분을 작성하고 답변으로 대답을 넣어해야
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); } }
: 같은 샘플 핸들러는 보일 수 있습니다. 24 시간 후에 직접 받아 들일 수 있습니다. – oers
조언 해 주셔서 감사합니다. – n8n8baby