Active Selection in Child Context [message #987073] |
Fri, 23 November 2012 10:01 |
Jonas Helming 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 |
Thomas Schindl 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
|
|
|
Powered by
FUDForum. Page generated in 0.02802 seconds