Question

i create an MWindow at runtime with

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

than i add a part to it with

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

but i have no idea how to close or dispose this window after it is no longer used. Mwindow has no close / dispose or exit functions. And if i try to simply remove it from the applications children i get npe.

How to get rid of the window?

Was it helpful?

Solution

Use EPartService.hidePart(MPart) or hidePart(MPart, boolean).

hidePart(MPart) normally just hides the part but if the removeOnHide value is set in the part Tags then it is also deleted.

hidePart(MPart, true) lets you force the delete regardless of the tags.

Edit:

To close the window call MWindow.setToBeRendered(false) the window will remain in the application model but resources etc. will be disposed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top