Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Closing a window seems to remove it from the model
Closing a window seems to remove it from the model [message #903946] Mon, 27 August 2012 11:42 Go to next message
Ulrich Obst is currently offline Ulrich ObstFriend
Messages: 12
Registered: August 2012
Junior Member
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 #903956 is a reply to message #903946] Mon, 27 August 2012 11:54 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Instead of directly adding it to the model you could register it the
EModelService has methods to clone such deep structures.

Tom

Am 27.08.12 13:42, schrieb Ulrich Obst:
> 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 #904376 is a reply to message #903956] Tue, 28 August 2012 10:46 Go to previous messageGo to next message
Ulrich Obst is currently offline Ulrich ObstFriend
Messages: 12
Registered: August 2012
Junior Member
I'm not sure I understand what you mean with "register it".
I found that I can define the window as a snippet and the clone it every time I want to open it (if it is not already present)
Is that what you mean?
Re: Closing a window seems to remove it from the model [message #904385 is a reply to message #904376] Tue, 28 August 2012 10:58 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Right - i somehow missed the "register as a snippet" ;-)

Tom

Am 28.08.12 12:46, schrieb Ulrich Obst:
> I'm not sure I understand what you mean with "register it". I found that
> I can define the window as a snippet and the clone it every time I want
> to open it (if it is not already present)
> Is that what you mean?
>
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 Go to previous messageGo to next message
Matthias F is currently offline Matthias FFriend
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 #1064142 is a reply to message #1048460] Mon, 17 June 2013 18:59 Go to previous messageGo to next message
Eric Moffatt is currently offline Eric MoffattFriend
Messages: 118
Registered: July 2009
Senior Member
This is likely a result of the 'CleanupAddon' (you could check by adding a breakpoint to the PartRenderingEngine's 'childrenHandler' which listens to model elements being added or removed from the model).

If it is the cleanup addon doing this then open an enhancement request, we've already added code (controlled througha tag) that prevents empty stacks being unrendered so this isn't much different.
Re: Closing a window seems to remove it from the model [message #1064888 is a reply to message #1064142] Fri, 21 June 2013 14:13 Go to previous messageGo to next message
Eric Moffatt is currently offline Eric MoffattFriend
Messages: 118
Registered: July 2009
Senior Member
Actually I'm just now addressing at least some of this. It turns out that it's not the CleanUpAddon but a specific listener in the WBWRenderer that automatically tears down and *removes* the MWindow whenever its Shell goes away. There's a bug in that code that simplistically just check how many children the parent (the MApplication) has rather than how many are actually visible on the screen.

I expect to be checking in a fix for this early in Luna (i.e. for M1) but I'd be happy to have a conversation about how to handle this situation. Our current approach shows its legacy; in the IDE you can open / close new windows but only the last one gets maintained in the model and closing it exits the app...
Re: Closing a window seems to remove it from the model [message #1077829 is a reply to message #903946] Fri, 02 August 2013 07:42 Go to previous messageGo to next message
Vadim Korkin is currently offline Vadim KorkinFriend
Messages: 2
Registered: August 2013
Junior Member
I'd like to add to this discussion. I'm using the Kepler release.
I also tried to create a new window. The idea: the user initiates an action, a progress window appears with a progress bar. The progress bar tracks the progress of the activity the user initiated. When the activity is complete the progress window is removed. But I couldn't make it work.

1. First I ran into the same issue of the window being removed from the model after the first call. Therefore I couldn't use the window I prepared in the model.

2. Then I tried the "clone" approach. And again it didn't work. The issue is that the widget for the window that already exists in the model is Shell "{Progress window}" and when this window is returned by the model service its widget has a parent something like "Shell {Part Rendering limbo}" or "Shell {Example GUI}" (Example GUI is my name).
Here is the structure:
Window (returned by EModelService.find)
|- widget - Shell {Progress window}
|- widget.parent - Shell {Part Rendering limbo or Example GUI}


But for the cloned window (like modelService.clone(progressWindowModel, null)) the parent of the widget is not present
Window (returned by EModelService.find)
|- widget - Shell {Progress window}

|- widget.parent - NULL!!
And when I try to remove it from the application like application.remove(progressWindow) I get a NullPointerException in PartRenderingEngine.childrenHandler:
if (removed.getWidget() instanceof Control) {
  Control ctrl = (Control) removed.getWidget();
  ctrl.setLayoutData(null);
  ctrl.getParent().layout(new Control[] { ctrl },
  SWT.CHANGED | SWT.DEFER);
}

ctrl.getParent returns null.

Is there a way to fix this?
Perhaps I should try another approach?

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 Go to previous message
Vadim Korkin is currently offline Vadim KorkinFriend
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

Previous Topic:How to get Eclipse context
Next Topic:How to add an e4 eclipse part into Show View dialog
Goto Forum:
  


Current Time: Tue Mar 19 04:05:54 GMT 2024

Powered by FUDForum. Page generated in 0.03201 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top