|
|
|
|
Re: Closing a window seems to remove it from the model [message #1048460 is a reply to message #903946] |
Wed, 24 April 2013 13:54 |
Matthias F Messages: 20 Registered: June 2011 |
Junior Member |
|
|
Hi, I'm sorry to dig out and hijack this thread but I have the exact same problem but somehow specifying the Window as a Snipped did not solve it for me.
My 2nd window is defined in the model:
<snippets xsi:type="basic:TrimmedWindow" xmi:id="_aRu48PArEeG3DKBqtQNHNw" elementId="my.second.window.id" visible="false" label="Window2">
<...>
</snippets>
In a Handler I try to find the snippet or create a clone if the service can't find it.
@Execute
public void execute(MApplication application, EModelService modelService) {
MUIElement window = modelService.findSnippet(application,
"my.second.window.id");
if (window == null) {
window = modelService.cloneSnippet(application,
"my.second.window.id", null);
}
if (window != null) {
window.setVisible(true);
if (window.getParent() == null) {
application.getChildren().add((MWindow) window);
}
}
}
This works exactly one time. After I close the window once, findSnippet and cloneSnippet both return null. Do you have any suggestions on how to solve this?
Edit: To be clear, I only want one instance of the second window open at a time.
[Updated on: Wed, 24 April 2013 14:05] Report message to a moderator
|
|
|
|
|
|
Re: Closing a window seems to remove it from the model [message #1079443 is a reply to message #1077829] |
Sun, 04 August 2013 15:51 |
Vadim Korkin Messages: 2 Registered: August 2013 |
Junior Member |
|
|
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 16:14] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.10464 seconds