Closing a window seems to remove it from the model [message #903946] |
Mon, 27 August 2012 07:42  |
Eclipse User |
|
|
|
Hi everybody
I have an e4 application with two windows. One is not visible at startup. In the first window I have a command handler that opens the second window:
@Execute
public void openWindow(EModelService modelService, MApplication application) {
MUIElement element = modelService.find(UIConstants.SECOND_WINDOW_ID, application);
MWindow window = (MWindow)element;
if (!window.isVisible()) {
window.setVisible(true);
}
window.setOnTop(true);
This works fine. But when I close the window and try to reopen it the second time, the call modelService.find(...) returns null. The windows is removed from the model.
What can I do to open the window the second time? Do I have to create it (How)? Can I force the model service to make the window invisible instead of removing it?
|
|
|
|
|
|
|
|
|
|
Re: Closing a window seems to remove it from the model [message #1079443 is a reply to message #1077829] |
Sun, 04 August 2013 11:51  |
Eclipse User |
|
|
|
I finally made it work. I'm posting this workaround for anyone who ran into the same issue. The issue is when a window (I used trimmed window) is cloned without a container like this:
MTrimmedWindow mtwModel = (MTrimmedWindow)modelService.find("progresswindow.1", application);
MTrimmedWindow mtw = (MTrimmedWindow)modelService.cloneElement(mtwModel, null);
Its parent is application (MApplication). Application has no renderer. Therefore in his piece of code (PartRenderingEngine) the element doesn't get any parent:
private Object safeCreateGui(MUIElement element) {
// Obtain the necessary parent widget
Object parent = null;
MUIElement parentME = element.getParent();
if (parentME == null)
parentME = (MUIElement) ((EObject) element).eContainer();
if (parentME != null) {
AbstractPartRenderer renderer = getRendererFor(parentME);
if (renderer != null) {
if (!element.isVisible()) {
parent = getLimboShell();
} else {
parent = renderer.getUIContainer(element);
}
}
}
...
When a window is cloned with a container (the main plugin window for example) like this:
MTrimmedWindow mtwModel = (MTrimmedWindow)modelService.find("progresswindow.1", application);
MTrimmedWindow mtw = (MTrimmedWindow)modelService.cloneElement(mtwModel, window);
its parent is null not the application. Then it can successfully get a parent in the safeCreateGui method. If setVisible(true) is called before setToBeRendered(true) then its widget will be the correct main shell.
If the professionals from Eclipse can comment on this I'm ready to listen. Am I right here? Is there a better way?
P.S.
I changed the element ID of the cloned window and it is not removed from the application model after application.getChildren().remove(). I can clone it as many times as I want.
[Updated on: Sun, 04 August 2013 12:14] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.24949 seconds