【问题标题】:Eclipse 4 RCP - how to remove Part from application model?Eclipse 4 RCP - 如何从应用程序模型中删除部件?
【发布时间】:2014-10-28 15:42:39
【问题描述】:

我有这个实用方法,可以轻松更改应用程序特定位置显示的内容。

问题是新部件看起来更像是在旧部件之上(旧部件没有被删除,它仍然在新部件下可见)。

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

    }
}

【问题讨论】:

    标签: eclipse eclipse-rcp e4


    【解决方案1】:

    你应该使用:

    partService.hidePart(oldPart);
    

    隐藏旧部分(也将其从子项中删除)。

    你也可以这样做:

    oldPart.setToBeRendered(false);
    

    但我不确定这是否足以更新 Eclipse 内部状态。

    【讨论】:

    • 如果我没记错的话,hidePart 使该部分“不可见”。这可能会导致意外的行为(例如,如果您在此部分中有事件触发方法)。 hidePart(oldPart,true) 强制将其作为子项从部件堆栈中移除。仅作为提示;)
    • @MatthiasH 该部分在隐藏时被破坏(只需运行测试确认)
    猜你喜欢
    • 1970-01-01
    • 2023-03-24
    • 2011-05-31
    • 1970-01-01
    • 1970-01-01
    • 2013-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多