Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Active Selection in Child Context
Active Selection in Child Context [message #987073] Fri, 23 November 2012 10:01 Go to next message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 699
Registered: July 2009
Senior Member
Hi,
I have a part with several subcomponents. I would like those
sub-components to be initialized via DI, too. So the solution would look
sth. like this:

Context child = context.createChild();
child.set(Composite.class);
ContextInjectionFactory.make(MySubComponent.class, child);

If I now get the ESelectionProvider injected in MySubComponent,
setSelection will not have any effect. This is because the selection
service of the child context, which is a new instance is not registered
as an aggregator.
The following fix therefore works, but is this really intended?

Context child = context.createChild();
child.set(Composite.class, myParentComposite);
child.set(ESelectionService.class, context.get(ESelectionService.class));
ContextInjectionFactory.make(MySubComponent.class, child);

Regards
Jonas
Re: Active Selection in Child Context [message #987076 is a reply to message #987073] Fri, 23 November 2012 10:18 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

The problem is that you are not activating your child context hence you
are not publishing back up the stuff, if you look at
EPartService#activate(MPart) you'll notice that it activates the
IEclipseContext associated with your MPart.

So if your subcomponent is the one with the focus (=it is the selection
provider) you need to activate this IEclipseContext through
IEclipseContext#activateBranch().

This all sounds overly complex though so maybe we should have an
ESelectionProvider which walks up the context hierarchy to find the
IEclipseContext associate with the MPart and request the
ESelectionService from there freeing the app developer.

Anyways this activateBranch() stuff has other implications if not done
because e.g. if you push values in your child they are not seen e.g. in
handlers who always use the current active-context which without
activateBranch is still the MPart-Context and not your child!

Tom

Am 23.11.12 11:01, schrieb Jonas Helming:
> Hi,
> I have a part with several subcomponents. I would like those
> sub-components to be initialized via DI, too. So the solution would look
> sth. like this:
>
> Context child = context.createChild();
> child.set(Composite.class);
> ContextInjectionFactory.make(MySubComponent.class, child);
>
> If I now get the ESelectionProvider injected in MySubComponent,
> setSelection will not have any effect. This is because the selection
> service of the child context, which is a new instance is not registered
> as an aggregator.
> The following fix therefore works, but is this really intended?
>
> Context child = context.createChild();
> child.set(Composite.class, myParentComposite);
> child.set(ESelectionService.class, context.get(ESelectionService.class));
> ContextInjectionFactory.make(MySubComponent.class, child);
>
> Regards
> Jonas
Previous Topic:BundleTranslationProvider usage
Next Topic:XWT Databinding
Goto Forum:
  


Current Time: Fri Apr 26 09:59:02 GMT 2024

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

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

Back to the top