Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Lifecycles ProcessAdditions - getting the MWindow
Lifecycles ProcessAdditions - getting the MWindow [message #1028579] Thu, 28 March 2013 12:58 Go to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
Hello,
In my org.eclipse.core.runtime.product I registerd a LifeCycle.

In this lifecycle there is @ProcessAdditions hook,
where the Model should allready exist.
(source http://www.vogella.com/articles/Eclipse4LifeCycle/article.html)

There I try to inject the MWindows it fails.
Indeed I can do:
@ProcessAddition 
run(IEclipseContext context){
MApplicaiton ma = context.get(MApplication.class);
MWindow window = ma.getChildren().get(0);
}


Is there a reason, why I can not inject the MWindow?
What objects are available at @ProcessAdditions ?

And is it possible to iterate the Context values to make the content - visible?
Re: Lifecycles ProcessAdditions - getting the MWindow [message #1028790 is a reply to message #1028579] Thu, 28 March 2013 18:44 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
So the context this runs on on the one of the application! Beside that
if there are multiple windows which one would you like to get?

Tom

On 28.03.13 08:58, Alex Kipling wrote:
> Hello,
> In my org.eclipse.core.runtime.product I registerd a LifeCycle.
>
> In this lifecycle there is @ProcessAdditions hook, where the Model
> should allready exist.
> (source http://www.vogella.com/articles/Eclipse4LifeCycle/article.html)
>
> There I try to inject the MWindows it fails.
> Indeed I can do:
>
> @ProcessAddition run(IEclipseContext context){
> MApplicaiton ma = context.get(MApplication.class);
> MWindow window = ma.getChildren().get(0);
> }
>
>
> Is there a reason, why I can not inject the MWindow?
> What objects are available at @ProcessAdditions ?
>
> And is it possible to iterate the Context values to make the content -
> visible?
Re: Lifecycles ProcessAdditions - getting the MWindow [message #1033720 is a reply to message #1028790] Thu, 04 April 2013 15:05 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
Thnx Tom,
but I did not get, why no MWindow can be injected, if the "ProcessAddition" hook is executed in Application context.

- Argument: Multiple Windows may exist.
But I can inject Parts too and there are plently of them. So I would expect to get the top most window / any Window. If I would need a specific window, I still can iterate over the children and find the specific child.
Re: Lifecycles ProcessAdditions - getting the MWindow [message #1033732 is a reply to message #1033720] Thu, 04 April 2013 15:15 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
What MPart instance (I doubt you can select the Part you get) do you
get? The lifecycle hooks are exectuted on the IEclipseContext of the
MApplication and so only this model-element can be there. The only
reason an MPart can be there is that something pushes it there, or some
context function, ... .

Tom

On 04.04.13 17:05, Alex Kipling wrote:
> Thnx Tom, but I did not get, why no MWindow can be injected, if the
> "ProcessAddition" hook is executed in Application context.
>
> - Argument: Multiple Windows may exist. But I can inject Parts too and
> there are plently of them. So I would expect to get the top most window
> / any Window. If I would need a specific window, I still can iterate
> over the children and find the specific child.
>
Re: Lifecycles ProcessAdditions - getting the MWindow [message #1034347 is a reply to message #1033732] Fri, 05 April 2013 10:29 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
Ah, I think it's a little missundertanding, Tom Smile

I do not get any MPart inside of the @ProcessAddition annotated method.

This was just the only a comment to your remark, about the reason, why I can not inject any windos inside of the @ProcessAddition annotated method.
Quote:
Beside that if there are multiple windows which one would you like to get?


As a counter example I mentioned the MParts, which you can insert (in other places) and of whome there exist multiple instances too.
Re: Lifecycles ProcessAdditions - getting the MWindow [message #1034419 is a reply to message #1034347] Fri, 05 April 2013 12:10 Go to previous message
Eclipse UserFriend
Alex, it's all about the context hierarchy. Every MApplication, MWindow, MPerspective and MPart has its own IEclipseContext. Imagine all these contexts arranged in a tree, in a hierarchy. App context as the root, Win contexts as its children, then perspective and parts as you go deeper etc, etc. Now when you try an @Inject MPart in a the part level (e.g when you are writing the Part class URI) there is a look up on this part context and if not found it goes to do a look up on its parent (perspective context) and if it fails it goes up to the win context and so on.

Thus if you look for a part in the e.g. window level you get an InjectionException because the lookup rule does not search downwards but just upwards. The reason is that this way you scope services, like grouping stuff for all children.

All objects available for injection (services, MParts, MWindows etc.) are splattered around in this tree and, depending on where you request your injection, you will get it only if it is (in your local context) or (in one of the nodes on your way up to the root).

Naturally now you are wondering but who puts these objects in the contexts to begin with. In the default way (context#set) it happens in two moments:
- at startup of the application for the higher levels (MApplication etc). For gut-level details check out the E4Application class in the eclipse internals.
- *by the renderers* for the lower levels (MPart etc). When and how it happens is irrelevant because that's the whole idea of dependency injection. Not just encapsulating your dependencies, but also their complete lifecycle (creation, disposal etc).

Back to your case, you try to inject an MWindow on an MApplication level context (also known as Worbkench Context) you are asking for something which resides in its children and you have no chance of getting one, because even if you would, which one would you get (picture an app with 2 top-level windows)? When you ask for an MPart in this specific part's context (as I said, like when you do the @PostConstruct and get the composite) you are requesting it in the context of the part itself, and in this scope there is only one part - the one that you'll get injected.

Do this on a part contribution and see for yourself:

@PostConstruct
public void pc(IEclipseContext localContext){

while (localContext!=null){
system.out.println(localContext);
localContext=localContext.getParent();
}

}

P.S.
If you want to intervene in this rule and do it your way you have the context functions. If you completely want to spectacularly smash this context thing you can use ExtendedObjectSupplier-s, though we (especially Oleg) won't let you do it for @Inject so you'd have to make up your own annotation (like @Preference and @UIEventTopic does).
Previous Topic:Why is it possible to inject E4Workbench.CLEAR_PERSISTED_STATE
Next Topic:Add Icon to Part in PartStack Container
Goto Forum:
  


Current Time: Wed Apr 24 23:58:16 GMT 2024

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

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

Back to the top