2014-10-27 83 views
0

我有這個實用程序方法,它可以很容易地改變我的應用程序的特定位置顯示的內容。Eclipse 4 RCP - 如何從應用程序模型中刪除部分?

問題在於,它看起來更像是新零件位於舊零件的頂部(舊零件未被移除並且在新零件下仍然可見)。

package cz.vutbr.fit.xhriba01.bc.ui; 

import org.eclipse.e4.ui.model.application.ui.basic.MPart; 
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer; 
import org.eclipse.e4.ui.workbench.modeling.EModelService; 
import org.eclipse.e4.ui.workbench.modeling.EPartService; 

public class UI { 

    public static final String PART_INSPECTOR_ID = "bc.part.inspector"; 

    public static void changeInspectorView(String partDescriptorId, EPartService partService, EModelService modelService) { 

     MPart part = partService.createPart(partDescriptorId); 
     MPart oldPart = partService.findPart(UI.PART_INSPECTOR_ID); 
     MPartSashContainer parent = (MPartSashContainer) modelService.getContainer(oldPart); 
     parent.getChildren().remove(oldPart); 
     part.setElementId(UI.PART_INSPECTOR_ID); 
     parent.getChildren().add(0, part); 

    } 
} 

回答

1

你應該使用:

partService.hidePart(oldPart); 

隱藏舊部分(也是從孩子中刪除)。

你也可能只是能夠做到:

oldPart.setToBeRendered(false); 

,但我不知道,做足夠的更新Eclipse的內部狀態。

+0

hidePart工作,thx – Krab 2014-10-28 09:24:01

+0

如果我沒有記錯,hidePart使部分「隱形」。這可能會導致意想不到的行爲(例如,如果您在此部分中有觸發事件的方法)。 hidePart(oldPart,true)強制將其作爲孩子從零件堆棧中移除。只作爲提示;) – 2014-10-28 14:46:49

+1

@MatthiasH零件在隱藏時被銷燬(只需運行測試以確認) – 2014-10-28 14:52:54

相關問題