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 07:42 Go to next message
Ulrich Obst is currently offline Ulrich Obst
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 07:54 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 4463
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 06:46 Go to previous messageGo to next message
Ulrich Obst is currently offline Ulrich Obst
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 06:58 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 4463
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 09:54 Go to previous message
Matthias F is currently offline Matthias F
Messages: 9
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 10:05]

Report message to a moderator

Previous Topic:MApplication.getDescriptors() returns an empty list
Next Topic:Changing MenuItem Text when contributed via plugin.xml in 3.8.1 (4.2.1)
Goto Forum:
  


Current Time: Fri May 24 16:13:00 EDT 2013

Powered by FUDForum. Page generated in 0.01765 seconds