Eclipse RCP4 close Part on exit / disable persistence of a Part?

别来无恙 提交于 2019-12-08 12:35:45

问题


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.

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

-How to close Parts on exit?

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

Thanks in advance :)


回答1:


With this you can close MParts with a specific Tag.

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);
    }

}



回答2:


We too tried to migrate from Eclipse 3 to Eclipse 4.We used the comp layer and had a lot of problems with the migration. I had a similar problem with persistent store of the eclipse workbench. So parts and views had the same position as before restart.

The persistence paradigma in Eclipse 4 has changed. Please take a look here:

As far as I remember the call of configurer.setSaveAndRestore(false) does not work in Eclipse 4 correctly.



来源:https://stackoverflow.com/questions/16693443/eclipse-rcp4-close-part-on-exit-disable-persistence-of-a-part

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!