2013-05-22 15 views
0

我正在開發Eclipse RCP4項目。我有不同的觀點,展示了一組從中選擇信息的部分。選擇我想要查看的內容後,會打開一個新零件並顯示我想要編輯/查看的對象。 我可以打開相同類型的很多部分。如果我關閉了應用程序,日食framwork將保留所有打開的零件的位置。如果我重新啓動應用程序,所有以前打開的部件都打開,但沒有信息。Eclipse RCP4關閉關於退出/禁用零件持久性的部分?

- 如何防止Eclipseframwork堅持零件的狀態?

- 退出時如何關閉零件?

我正在尋找一種方法來添加一個「removeOnExit」標籤到零件上,而不是在退出時關閉這樣一個標記的零件。

在此先感謝:)

+0

是否可以使用configurer.setSaveAndRestore(false)在ApplicationWorkbenchAdvisor中切換佈局持久性? –

回答

2

有了這個,您可以關閉具有特定標記的MParts。

看來你必須切換到零件所在的透視圖,否則它不會從上下文中移除,這將導致空指針異常。

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

} 
0

我們也試着從Eclipse 3遷移到Eclipse 4.我們使用了comp層,並且在遷移時遇到了很多問題。我有一個與eclipse工作臺持久存儲類似的問題。因此,零件和視圖與重新啓動之前的位置相同。

Eclipse 4中的持久性範例已更改。請大家看看here

據我記得configurer.setSaveAndRestore(false)的調用在Eclipse 4中無法正常工作。