Eclipse RCP4在退出时关闭部件/禁用部件的持久性? [英] Eclipse RCP4 close Part on exit / disable persistence of a Part?

查看:51
本文介绍了Eclipse RCP4在退出时关闭部件/禁用部件的持久性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Eclipse RCP4项目。我有不同的观点,显示了一组零件供您选择信息。选择要查看的内容后,将打开一个新零件,并显示我要编辑/查看其服装的对象。
我可以打开许多相同类型的零件。如果我关闭应用程序,则日食框架会保留所有打开的零件的位置。如果我重新启动应用程序,则所有先前打开的部件都会打开,但是没有信息。

i'm working on an Eclipse RCP4 project. I have different perspectives showing a set of Parts to choose informations from. After selecting what i want to see, a new Part opens and displays the objet i want to edit / view attibutes of. I can open many parts of the same type. If i close the application, the eclipse framwork persists the position of all opened Parts. If i restart the application all previously opened Parts are open but without informations.

-如何防止Eclipseframwork保持部件状态?

-How to prevent Eclipseframwork from persisting the state of Parts?

-如何在退出时关闭零件?

-How to close Parts on exit?

我正在寻找一种向零件添加 removeOnExit标签然后关闭的方法

I'm searching for a way to add an "removeOnExit" tag to a Part and than close such a marked Part on exit.

预先感谢:)

推荐答案

使用此功能,您可以关闭具有特定标签的MPart。

With this you can close MParts with a specific Tag.

似乎您必须切换到零件处于启用状态的 Perspective,否则它不会从上下文中移除会导致空指针异常。

It seems you have to switch to the Perspective the Part is on, else it's not removed from the context wich will cause nullpointer exceptions.

@Inject
    @Optional
    public void doEvent(@EventTopic(EventConstants.EventTopics.CLOSE_PARTS_WITH_TAGS) String tagToClose, MApplication app,


EModelService eModelService, EPartService ePartService) {
    MUIElement activePart = ePartService.getActivePart();
    EPartService activePeServcie = null;
    MPerspective activePerspective = null;
    if (activePart instanceof MPart) {
        activePeServcie = ((MPart) activePart).getContext().get(EPartService.class);
        activePerspective = eModelService.getPerspectiveFor(activePart);
    }

    List<String> tags = new ArrayList<String>();
    tags.add(tagToClose);
    List<MPart> elementsWithTags = eModelService.findElements(app, null, MPart.class, tags);

    for (MPart part : elementsWithTags) {
        try {
            logger.info("Closing part " + part.toString());
            EPartService peService = part.getContext().get(EPartService.class);
            peService.switchPerspective(eModelService.getPerspectiveFor(part));
            peService.hidePart(part);
        } catch (Exception e) {
            logger.error(e);
        }
    }

    if (activePart instanceof MPart && activePeServcie != null && activePerspective != null) {
        activePeServcie.switchPerspective(activePerspective);
    }

}

这篇关于Eclipse RCP4在退出时关闭部件/禁用部件的持久性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆