首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何为Eclipse应用程序重置透视图?

如何为Eclipse应用程序重置透视图?
EN

Stack Overflow用户
提问于 2013-10-31 21:45:30
回答 2查看 4.7K关注 0票数 3

在application.e4xmi文件中构建透视图之后,我无法通过调用IWorkbenchPage.resetPerspective()来重置透视图。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-11-20 20:30:33

我认为这可以节省别人的时间,也可以为我自己记录。

能够重置e4透视图的诀窍如下(假设基本application.e4xmi具有PerspectiveStack元素):

  1. 在application.e4xmi文件中,在应用程序/TrimmedWindow节点下找到您的PerspectiveStack。记录/设置其ID。
  2. 在Eclipse4ModelEditor中,将透视图从PerspectiveStack下面拖到应用程序/代码段。(这将导致透视图ID向IPerspectiveRegistry注册,并提供原始状态)。
  3. 创建新的CopyPerspectiveSnippetProcessor。这将在启动时将片段中的透视图复制到PerspectiveStack中。这使得您不必维护e4xmi文件中每个透视图元素的两个副本。 进口org.eclipse.e4.ui.model.application.MApplication;org.eclipse.e4.ui.model.application.ui.MUIElement;org.eclipse.e4.ui.model.application.ui.MUIElement;org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;org.eclipse.e4.ui.workbench.modeling.EModelService;/** *将所有片段透视图复制到称为"MainPerspectiveStack“的透视图堆栈中,以便注册/重置透视图,而不必在* e4xmi中同步两个副本。* */公共类CopyPerspectiveSnippetProcessor {私有静态最终字符串MAIN_PERSPECTIVE_STACK_ID = "MainPerspectiveStack";@ Execute (EModelService modelService,MApplication应用程序){ MPerspectiveStack perspectiveStack = (MPerspectiveStack) modelService.find(MAIN_PERSPECTIVE_STACK_ID,application);//仅在没有其他子级或恢复的工作区状态将被覆盖时执行此操作。如果(!perspectiveStack.getChildren().isEmpty())返回;//克隆作为透视图的每个片段,并将所克隆的透视图添加到主要的PerspectiveStack布尔isFirst = true;for (MUIElement代码段: application.getSnippets()) { if (snippet.getElementId){ MPerspective perspectiveClone = (MPerspective) modelService.cloneSnippet(应用程序,snippet.getElementId(),null);if ( isFirst ) {isFirst isFirst= false;}
  4. 将CopyPerspectiveSnippetProcess注册到plugin.xml文件中。
  5. 将透视图重置为正常。您还需要将透视图堆栈和当前透视图设置为可见,因为有时可以将这些设置为不可见。示例处理程序可能如下所示: 导入org.eclipse.e4.ui.model.application.MApplication;org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;org.eclipse.e4.ui.workbench.modeling.EModelService;org.eclipse.e4.core.di.annotations.Execute org.eclipse.ui.PlatformUI;公共类ResetPerspectiveHandler {私有静态最终字符串MAIN_PERSPECTIVE_STACK_ID = "MainPerspectiveStack";@ Execute (EModelService modelService,MApplication应用程序){ MPerspectiveStack perspectiveStack = (MPerspectiveStack) modelService.find(MAIN_PERSPECTIVE_STACK_ID,application);EModelService perspectiveStack.getSelectedElement().setVisible(true);perspectiveStack.setVisible(true);}}
票数 4
EN

Stack Overflow用户

发布于 2018-09-24 06:01:34

重置透视图(当您午餐e4应用程序而没有清除工作空间时,当您切换其他透视图时)。

步骤1:在应用程序级别的模型片段中添加一个外接程序。

步骤2:创建附加类并实现EventHandler

步骤3:在类中添加以下代码。

代码语言:javascript
运行
复制
public class ResetPrespectiveAddOn implements EventHandler {

private static final String MY_PERSPECTIVE_ID = "myPrespectiveId";

@Inject
private IEventBroker broker;

@PostConstruct
public void loadPrespective() {

    broker.subscribe(UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT, this);
}

@SuppressWarnings("restriction")
@Override
public void handleEvent(Event event) {

    //UIEvents.EventTags.ELEMENT is trigger  for all UI activity
    Object property = event.getProperty(UIEvents.EventTags.ELEMENT);
    if (!(property instanceof PerspectiveStackImpl)) {
        return;

    }

    // Reset perspective logic .
    IEclipseContext serviceContext = E4Workbench.getServiceContext();
    final IEclipseContext appContext = (IEclipseContext) serviceContext.getActiveChild();
    EModelService modelService = appContext.get(EModelService.class);
    MApplication application = serviceContext.get(MApplication.class);
    MWindow mWindow = application.getChildren().get(0);

    PerspectiveStackImpl perspectiveStack = (PerspectiveStackImpl) property;
    List<MPerspective> children = perspectiveStack.getChildren();
    for (MPerspective myPerspective : children) {
        if (myPerspective.getElementId().equals(MY_PERSPECTIVE_ID)) {

            //find active perspective
            MPerspective activePerspective = modelService.getActivePerspective(mWindow);
            if(activePerspective.getElementId().equals(MY_PERSPECTIVE_ID))

            //Reseting perspective  e3 way 
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().resetPerspective();


            // till now there is no direct e4 way to reset perspective 
            // but u can Add and remove e4 perspective with this code code              
            EPartService partService = serviceContext.get(EPartService.class);
            MPerspectiveStack perspectiveStack = (MPerspectiveStack) (MElementContainer<?>) activePerspective.getParent();
            int indexOf = perspectiveStack.getChildren().indexOf(activePerspective);
            perspectiveStack.getChildren().remove(indexOf);

            perspectiveStack.getChildren().add(myPerspective);
            partService.switchPerspective(myPerspective);
        }   
    }
}}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19717154

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档