如何以编程方式关闭eclipse rcp 4 mwindow

时间:2013-09-10 09:34:17

标签: java eclipse swt eclipse-rcp rcp

我在运行时使用

创建一个MWindow
MWindow window = _modelService.createModelElement(MWindow.class);
window.setWidth(200);
window.setHeight(300);
// add new Window to the application 
// @Inject
// MApplication _application;
_application.getChildren().add(window);

比我用

添加一部分
EModelService windowModelService = window.getContext().get(EModelService.class);
EPartService windowPartService = window.getContext().get(EPartService.class);

// find part if exists
MPart part = windowPartService.findPart("partId");

if (part == null) {
    // create if not exists
    part = windowPartService.createPart("partId");
}


// Required if initial not visible
part.setVisible(true);

// Show the part
MPart newPart = windowPartService.showPart(part, PartState.VISIBLE);

但我不知道如何在不再使用此窗口后关闭或处理它。 Mwindow没有关闭/处置或退出功能。如果我试图简单地从应用程序中删除它,我会得到npe。

如何摆脱窗户?

1 个答案:

答案 0 :(得分:4)

使用EPartService.hidePart(MPart)hidePart(MPart, boolean)

hidePart(MPart)通常只是隐藏了该部分,但如果在部分标签中设置了removeOnHide值,那么它也会被删除。

hidePart(MPart, true)可让您强制删除,无论标记如何。

编辑:

要关闭窗口调用MWindow.setToBeRendered(false),窗口将保留在应用程序模型中,但资源等将被处理。

相关问题