在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