在application.e4xmi文件中構建透視圖後,我無法通過調用IWorkbenchPage.resetPerspective()來重置透視圖。如何重置Eclipse e4 RCP應用程序的透視圖?
2
A
回答
3
我認爲這可能會爲他人節省一些時間,併爲自己記錄它。
訣竅能夠重置e4的透視如下(假定與PerspectiveStack元件的基本application.e4xmi):
- 在你application.e4xmi文件中找到你的應用在你PerspectiveStack/TrimmedWindow節點。記錄/設置其ID。
- 在Eclipse 4模型編輯器中,將Perspective(s)從PerspectiveStack下拖動到Application/Snippets。 (這會導致您的透視ID向IPerspectiveRegistry註冊,並提供原始狀態)。
創建新的CopyPerspectiveSnippetProcessor。這會在啓動時將片段中的透視圖複製到您的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); } }
相關問題
- 1. 如何在RCP應用程序中重用Eclipse 4 IDE透視圖功能
- 2. e4 Rcp應用程序中的樹視圖
- 3. Eclipse e4 RCP BundleActivator
- 4. 如何在e4 RCP應用程序中添加透視更改監聽器?
- 5. Eclipse RCP:如何配置透視菜單?
- 6. 如何重新啓動e4 RCP應用程序
- 7. Eclipse RCP圖像應用程序:如何佈置我的圖像?
- 8. 在RCP應用程序中添加翻譯到Eclipse e4 PartStack
- 9. 如何取消在Eclipse RCP e4中創建視圖?
- 10. RCP應用程序和進度視圖在Eclipse RCP
- 11. Eclipse RCP以編程方式打開視圖e4方式
- 12. 如何在eclipse RCP應用程序中集成XML Schema視圖
- 13. 如何將Project Explorer視圖添加到Eclipse RCP應用程序
- 14. 如何在Eclipse RCP應用程序中使視圖可滾動?
- 15. Eclipse RCP和遍歷透視和視圖
- 16. rcp eclipse應用程序的位置
- 17. Eclipse-RCP:如何將一個帶有應用程序模型的插件添加到新的RCP應用程序的透視圖中?
- 18. 如何在Eclipse(e4)RCP中實現IWindowCloseHandler?
- 19. 如何將xText編輯器添加到Eclipse(e4)RCP應用程序中?
- 20. 如何使一個自定義視圖中的透視RCP應用程序中
- 21. eclipse e4 - 如何識別eclipse e4視圖(零件)?
- 22. 將文件添加到elipse E4 RCP應用程序的根
- 23. 如何更新Eclipse RCP應用程序?
- 24. 如何在e4 rcp應用程序中獲得活動窗口?
- 25. 如何設置eclipse RCP應用程序的遠程調試
- 26. 自Eclipse Juno以來在RCP應用程序中切換透視圖?
- 27. Eclipse RCP - 透視佈局
- 28. 如何在Eclipse 4.2的RCP應用程序中重用菜單?
- 29. E4 RCP + GEF5應用實施
- 30. 使用e4工具的Eclipse RCP
你應該寫的問題一部分問題,並把答案作爲一個答案。然後你可以在24小時後自己接受(這非常好!)。 – oers
感謝您的建議。 – n8n8baby