Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » [e4] How to get ready ?
[e4] How to get ready ? [message #534946] Thu, 20 May 2010 14:15 Go to next message
Christophe Fondacci is currently offline Christophe Fondacci
Messages: 95
Registered: July 2009
Location: Paris
Member
Hello guys,

I do not know much about e4 but started to read some docs about upcoming features. As a RCP app developer, I am REALLY interested in the service injection feature.
So far, I need to handle service consumption in a custom way, most of the time relying on plugin singleton instance that gives me the proper service singleton I need. Not talking about the platform services but about "custom" services which a RCP app needs as well.

So now I am wondering :
- Will it be possible for us to take advantage of service injection to inject custom services ?
- Is there anything we can do right now in our developments to "prepare the future" ? I mean, is there some best practices which could reduce the migration efforts when e4 will be released ? This is always less work to prepare this now on fresh code than to refactor it after it has got old...

Another question : will e4 migrate to Java 1.5 and will introduce the generics ? I ask this (but I guess the answer is no) because I can see in the e4 docs code like :
MWindow window = (MWindow) mwindow.getContext().get(MWindow.class.getName());

And I can't wait being able to do this :
MWindow window = mwindow.getContext().get(MWindow.class);

thanks to generics: more compact, more readable, less writing.

I understand that there might be a big compatibility constraint for you Eclipse platform guyz....

If anyone could lead me to some documentation on these topics it would be marvellous.

Anyway thank you for all the great work you're doing on this release,
Christophe
http://www.nextep-softwares.com
Re: [e4] How to get ready ? [message #534960 is a reply to message #534946] Thu, 20 May 2010 15:29 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5296
Registered: July 2009
Senior Member
Am 20.05.10 20:15, schrieb Christophe Fondacci:
> Hello guys,
>
> I do not know much about e4 but started to read some docs about upcoming
> features. As a RCP app developer, I am REALLY interested in the service
> injection feature.
> So far, I need to handle service consumption in a custom way, most of
> the time relying on plugin singleton instance that gives me the proper
> service singleton I need. Not talking about the platform services but
> about "custom" services which a RCP app needs as well.
>
> So now I am wondering :
> - Will it be possible for us to take advantage of service injection to
> inject custom services ?

Yes. All services registered in OSGi-Service-Registry are a subject for
injection

> - Is there anything we can do right now in our developments to "prepare
> the future" ? I mean, is there some best practices which could reduce
> the migration efforts when e4 will be released ? This is always less
> work to prepare this now on fresh code than to refactor it after it has
> got old...
> Another question : will e4 migrate to Java 1.5 and will introduce the
> generics ? I ask this (but I guess the answer is no) because I can see
> in the e4 docs code like :

Some rules are:
* Don't inherit from things like ViewPart, EditorPart
* Don't references pure 3.x workbench services (e.g. ISelectionService)
=> Abstract them away in own services you delegate

If you want a concrete example on how to structure such a component you
can take a look at my ModelEditor which runs in:
* 3.x
* 4.0
* native e4

http://tomsondev.bestsolution.at/2010/05/17/a-week-at-e4-sha re-me-please/

Sources to it can be found in the
e4/org.eclipse.e4.tools/bundles/org.eclipse.e4.tools.emf*


>
> MWindow window = (MWindow)
> mwindow.getContext().get(MWindow.class.getName());
>
> And I can't wait being able to do this :
>
> MWindow window = mwindow.getContext().get(MWindow.class);
>
> thanks to generics: more compact, more readable, less writing.

We are using Java 5 generics so the you are able to write

MWindow window = mwindow.getContext().get(MWindow.class);

with the latest builds.

>
> I understand that there might be a big compatibility constraint for you
> Eclipse platform guyz....
>
> If anyone could lead me to some documentation on these topics it would
> be marvellous.
>
> Anyway thank you for all the great work you're doing on this release,
> Christophe
> http://www.nextep-softwares.com
>

Tom
Re: [e4] How to get ready ? [message #534966 is a reply to message #534960] Thu, 20 May 2010 15:30 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5296
Registered: July 2009
Senior Member
Please use the e4 newsgroup for follow ups.

Tom

Am 20.05.10 21:29, schrieb Tom Schindl:
> Am 20.05.10 20:15, schrieb Christophe Fondacci:
>> Hello guys,
>>
>> I do not know much about e4 but started to read some docs about upcoming
>> features. As a RCP app developer, I am REALLY interested in the service
>> injection feature.
>> So far, I need to handle service consumption in a custom way, most of
>> the time relying on plugin singleton instance that gives me the proper
>> service singleton I need. Not talking about the platform services but
>> about "custom" services which a RCP app needs as well.
>>
>> So now I am wondering :
>> - Will it be possible for us to take advantage of service injection to
>> inject custom services ?
>
> Yes. All services registered in OSGi-Service-Registry are a subject for
> injection
>
>> - Is there anything we can do right now in our developments to "prepare
>> the future" ? I mean, is there some best practices which could reduce
>> the migration efforts when e4 will be released ? This is always less
>> work to prepare this now on fresh code than to refactor it after it has
>> got old...
>> Another question : will e4 migrate to Java 1.5 and will introduce the
>> generics ? I ask this (but I guess the answer is no) because I can see
>> in the e4 docs code like :
>
> Some rules are:
> * Don't inherit from things like ViewPart, EditorPart
> * Don't references pure 3.x workbench services (e.g. ISelectionService)
> => Abstract them away in own services you delegate
>
> If you want a concrete example on how to structure such a component you
> can take a look at my ModelEditor which runs in:
> * 3.x
> * 4.0
> * native e4
>
> http://tomsondev.bestsolution.at/2010/05/17/a-week-at-e4-sha re-me-please/
>
> Sources to it can be found in the
> e4/org.eclipse.e4.tools/bundles/org.eclipse.e4.tools.emf*
>
>
>>
>> MWindow window = (MWindow)
>> mwindow.getContext().get(MWindow.class.getName());
>>
>> And I can't wait being able to do this :
>>
>> MWindow window = mwindow.getContext().get(MWindow.class);
>>
>> thanks to generics: more compact, more readable, less writing.
>
> We are using Java 5 generics so the you are able to write
>
> MWindow window = mwindow.getContext().get(MWindow.class);
>
> with the latest builds.
>
>>
>> I understand that there might be a big compatibility constraint for you
>> Eclipse platform guyz....
>>
>> If anyone could lead me to some documentation on these topics it would
>> be marvellous.
>>
>> Anyway thank you for all the great work you're doing on this release,
>> Christophe
>> http://www.nextep-softwares.com
>>
>
> Tom
Re: [e4] How to get ready ? [message #535138 is a reply to message #534946] Fri, 21 May 2010 08:26 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

I'll just add on what Tom said. In 3.x you can use
org.eclipse.ui.services to create your own service factory, and then
consume them in your view using:

getSite().getService(YourService.class) ... even if you abstract this
part away it will make it easier to consume services in a similar
fashion from e4.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: [e4] How to get ready ? [message #535166 is a reply to message #535138] Fri, 21 May 2010 09:13 Go to previous messageGo to next message
Christophe Fondacci is currently offline Christophe Fondacci
Messages: 95
Registered: July 2009
Location: Paris
Member
Thank you very much for your replies. It helped me understood how that will work.

Regarding your last suggestion Paul, the org.eclipse.ui.services is indeed the kind of things I need to rely on. But this is UI-related stuff. A RCP product may need to declare non-UI services. At least this is my case.

Actually, in my design I always try to seperate everything in business layer and UI layer. Even if the result is a RCP "graphical" application, I need to be able to extract the business part and make it run headless without any UI on top of it.

This led me in the direction of always creating "business" services which literally do the work or fail and generally an UI companion service which could embed the processing in the UI (like by spawning the process in a UI job) or which could interact with the user to get information, handle UI-thread synchronization, or a combination of this.

User-actions always rely on my UI services than delegating to one or several business services. Business services may only rely on other business services.

I was looking for a way of registering these services so that they could be injected when migrating to e4. But it seems like everything is UI-stuff, at least in 3.x. I don't really like having 2 ways of accessing services (1 for the UI through service locators, 1 other for the business services) but maybe this is the best thing to do... Any best-practice on this (well mostly for business services) ?

Hope I was clear enough...
Thanks again for your explanations, it really helps.

Christophe.
http://www.nextep-softwares.com


Re: [e4] How to get ready ? [message #535168 is a reply to message #535166] Fri, 21 May 2010 09:17 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5296
Registered: July 2009
Senior Member
Hi,

What you want are OSGi (Declarative) Services?

Tom

Am 21.05.10 15:13, schrieb Christophe Fondacci:
> Thank you very much for your replies. It helped me understood how that
> will work.
>
> Regarding your last suggestion Paul, the org.eclipse.ui.services is
> indeed the kind of things I need to rely on. But this is UI-related
> stuff. A RCP product may need to declare non-UI services. At least this
> is my case.
>
> Actually, in my design I always try to seperate everything in business
> layer and UI layer. Even if the result is a RCP "graphical" application,
> I need to be able to extract the business part and make it run headless
> without any UI on top of it.
>
> This led me in the direction of always creating "business" services
> which literally do the work or fail and generally an UI companion
> service which could embed the processing in the UI (like by spawning the
> process in a UI job) or which could interact with the user to get
> information, handle UI-thread synchronization, or a combination of this.
>
> User-actions always rely on my UI services than delegating to one or
> several business services. Business services may only rely on other
> business services.
>
> I was looking for a way of registering these services so that they could
> be injected when migrating to e4. But it seems like everything is
> UI-stuff, at least in 3.x. I don't really like having 2 ways of
> accessing services (1 for the UI through service locators, 1 other for
> the business services) but maybe this is the best thing to do... Any
> best-practice on this (well mostly for business services) ?
>
> Hope I was clear enough...
> Thanks again for your explanations, it really helps.
>
> Christophe.
> http://www.nextep-softwares.com
>
>
>
Re: [e4] How to get ready ? [message #535177 is a reply to message #535168] Fri, 21 May 2010 09:35 Go to previous messageGo to next message
Christophe Fondacci is currently offline Christophe Fondacci
Messages: 95
Registered: July 2009
Location: Paris
Member
I think so... but since OSGi services seems to be wrapped by "eclipse services" in the UI layer (the org.eclipse.ui.services extension point and service factories which Paul mentioned), I wanted to know what was the best way to declare my services...

...for now (3.x) and for e4 "portability".

Thanks,
Christophe
http://www.nextep-softwares.com
Re: [e4] How to get ready ? [message #535197 is a reply to message #535177] Fri, 21 May 2010 09:55 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5296
Registered: July 2009
Senior Member
Declare them as Declarative Services and consume them through:
* OSGi-Service-API
* Set up your own Eclipse 4 DI-Container which injects them.

Setting up an Eclipse DI-Container and context is really very easy.

Take a look here how to bootstrap such a container from scratch:

0. Assuming your class looks like this:
--------8<--------
package com.project.my

import javax.inject.Inject;

public class Bla {
@Inject
public void setService(IMyOSGiService service) {
// ...
}
}

--------8<--------


1. Setup DI-Container
--------8<--------
> Bundle bundle = FrameworkUtil.getBundle(IEclipseContextServiceFactory.class) ;
> BundleContext bundleContext = bundle.getBundleContext();
> IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(bundleContext);
>
> final IEclipseContext appContext = serviceContext.createChild("WorkbenchContext"); //$NON-NLS-1$
> IExtensionRegistry registry = RegistryFactory.getRegistry();
> ReflectionContributionFactory contributionFactory = new ReflectionContributionFactory(registry);
> appContext.set(IContributionFactory.class.getName(),contribu tionFactory);
>
--------8<--------

2. Create an instance
--------8<--------
> IContributionFactory factory = (IContributionFactory) appContext.get(IContributionFactory.class);
> instance = factory.create("platform:/plugin/com.project.my/com.project.my.Bla ", appContext);
--------8<--------

You get an service which is in the OSGi-Service registry injected
automagically.

Tom

You can see this is a more generic action here:
http://dev.eclipse.org/viewcvs/index.cgi/e4/org.eclipse.e4.t ools/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclip se/e4/tools/emf/editor3x/compat/



Am 21.05.10 15:35, schrieb Christophe Fondacci:
> I think so... but since OSGi services seems to be wrapped by "eclipse
> services" in the UI layer (the org.eclipse.ui.services extension point
> and service factories which Paul mentioned), I wanted to know what was
> the best way to declare my services...
>
> ..for now (3.x) and for e4 "portability".
>
> Thanks,
> Christophe
> http://www.nextep-softwares.com
Re: [e4] How to get ready ? [message #536526 is a reply to message #535197] Fri, 28 May 2010 11:06 Go to previous messageGo to next message
Christophe Fondacci is currently offline Christophe Fondacci
Messages: 95
Registered: July 2009
Location: Paris
Member
Thank you very much Tom,
I'll declare all my services through DS for now, and i'll see the e4 port when I'll switch to this release.

But now I am confident on writing portable code and that was the purpose.

Again, thanks for your time to you and Paul and your clear explanations, that helps a lot!

Christophe.
http://www.nextep-softwares.com
Re: [e4] How to get ready ? [message #536644 is a reply to message #536526] Sat, 29 May 2010 04:35 Go to previous messageGo to next message
Christophe Fondacci is currently offline Christophe Fondacci
Messages: 95
Registered: July 2009
Location: Paris
Member
Hello again,

I started wiring everything from OSGi DS.
Now I am getting into troubles at the "2 worlds" frontiers :
* I declare my DS components and it works great, injection works like a charm
* Now I need to "consume" one of my service in a Eclipse UI handler.

I found something which works but I am not satified with :
* Service A is declared as OSGi component
* I declare a UI service as a OSGi component which depend on service A (injection)
* I use the org.eclipse.ui.services to declare a service factory able to create my UI Service
* This factory relies on the OSGi BundleContext registry to lookup for the UI service and returns it.

I created a helper method for this :
	public static <T> T getService(Class<T> serviceInterface) {
		final BundleContext context = getDefault().getBundle().getBundleContext();
		final ServiceReference ref = context.getServiceReference(serviceInterface.getName());
		if (ref != null) {
			Object o = context.getService(ref);
			if (o != null && serviceInterface.isAssignableFrom(o.getClass())) {
				return (T) o;
			}
		}
		throw new ErrorException("Unable to locate requested service " + serviceInterface.getName());
	}


The problem is that I would like injection everywhere up to my handler. Isn't there a way (I mean in 3.x) to inject a component in a eclipse ui service factory, in a ui handler, or even in the bundle activator so that I would not need to have a place where I manually lookup for services ?

Thank you,
Ah yes and another thing : each time I change my component XML file and restart my product, the change is not made. The only way to make it works is to remove from manifest, compile, run, stop, re-add to the manifest.
Weird ? Is there something I am missing ?

Christophe.
http://www.nextep-softwares.com
Re: [e4] How to get ready ? [message #536649 is a reply to message #536644] Sat, 29 May 2010 05:26 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5296
Registered: July 2009
Senior Member
Am 29.05.10 10:35, schrieb Christophe Fondacci:
> Hello again,
> I started wiring everything from OSGi DS.
> Now I am getting into troubles at the "2 worlds" frontiers :
> * I declare my DS components and it works great, injection works like a
> charm
> * Now I need to "consume" one of my service in a Eclipse UI handler.
>

When you talk about UI-Handler are you talking about a CommandHandler or
an View/Editor Component?

> I found something which works but I am not satified with :
> * Service A is declared as OSGi component
> * I declare a UI service as a OSGi component which depend on service A
> (injection)
> * I use the org.eclipse.ui.services to declare a service factory able to
> create my UI Service
> * This factory relies on the OSGi BundleContext registry to lookup for
> the UI service and returns it.
>
> I created a helper method for this :
>
> public static <T> T getService(Class<T> serviceInterface) {
> final BundleContext context =
> getDefault().getBundle().getBundleContext();
> final ServiceReference ref =
> context.getServiceReference(serviceInterface.getName());
> if (ref != null) {
> Object o = context.getService(ref);
> if (o != null &&
> serviceInterface.isAssignableFrom(o.getClass())) {
> return (T) o;
> }
> }
> throw new ErrorException("Unable to locate requested service " +
> serviceInterface.getName());
> }
>
>
> The problem is that I would like injection everywhere up to my handler.
> Isn't there a way (I mean in 3.x) to inject a component in a eclipse ui
> service factory, in a ui handler, or even in the bundle activator so
> that I would not need to have a place where I manually lookup for
> services ?

As outlined one my answer you should not create your instances using DI
coming with e4. Then you get your services injected. If you are talking
about Command-Handlers the situation is quite similar but without
knowing wheter you currently talk about View/Editor Components or
Command-Handlers it might not make sense to go into detail with it.

For UI-Component injection you can take a look at my e4-ModelEditor
which does provide OSGi-Service injection to the View/Editor Component
level.

I hope I find some time to publish a minimal 3.x single sourcing example
on my blog http://tomsondev.bestsolution.at/ (simply subscribe to get
notified when I publish an article)

>
> Thank you,
> Ah yes and another thing : each time I change my component XML file and
> restart my product, the change is not made. The only way to make it
> works is to remove from manifest, compile, run, stop, re-add to the
> manifest.
> Weird ? Is there something I am missing ?

What does restart mean? Is it stop and start or really restart as known
in the Eclipse IDE? Anyways it is strange because normally you should
not even have to bring down your product at all but update only the
OSGi-Bundle and you'll get stuff uninjected/rejected :-)

Tom
Re: [e4] How to get ready ? [message #536700 is a reply to message #536649] Sun, 30 May 2010 02:13 Go to previous messageGo to next message
Christophe Fondacci is currently offline Christophe Fondacci
Messages: 95
Registered: July 2009
Location: Paris
Member
Hello,

Thanks for your reply.

I was talking about UI command handlers actually.

Looked at your model editor and at your blog for your last post "Use D4-DI for 3.x" but I could not find any kind of "injection" at the UI layer. I saw that you retrieve the instance from the bundle context, which insipired the static method I detailed in my last post.

But this is not literally "injection", as doing this should also implies monitoring the lifecycle of the services, writing some code, etc. If I understand well, I'll be able to work with pure injection in e4 (which also implies no direct creation of new instances to my point of view [coming from the spring world]), and make some kind of "glue code" in 3.x to be able to access DS components at some places.

Am I right ? Or is it already possible to inject on the UI layer ?
I was thinking that maybe the bundle activator, which is actually already managed by OSGi would be able to get injected components on it. This would solve my problems as I can inject all services that I need to access in the UI and then this activator would act as a bridge and I would not create any OSGi-dependant code to retrieve service from the bundle context...


Christophe
http://www.nextep-softwares.com
Re: [e4] How to get ready ? [message #536703 is a reply to message #536700] Sun, 30 May 2010 02:42 Go to previous messageGo to next message
Christophe Fondacci is currently offline Christophe Fondacci
Messages: 95
Registered: July 2009
Location: Paris
Member
Regarding the restart problem, after spending hours on this I found the environment parameter :

osgi.clean=true

Which solved everything ! OSGi was always keeping a cache of old definition at each restart of my app. This is VERY confusing as it seems not to be documented very explicitly and this is definitly not the default behaviour I would have expected.

Christophe
http://www.nextep-softwares.com
Re: [e4] How to get ready ? [message #536718 is a reply to message #536700] Sun, 30 May 2010 05:35 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5296
Registered: July 2009
Senior Member
Am 30.05.10 08:13, schrieb Christophe Fondacci:
> Hello,
>
> Thanks for your reply.
>
> I was talking about UI command handlers actually.
>
> Looked at your model editor and at your blog for your last post "Use
> D4-DI for 3.x" but I could not find any kind of "injection" at the UI
> layer. I saw that you retrieve the instance from the bundle context,
> which insipired the static method I detailed in my last post.
>
> But this is not literally "injection", as doing this should also implies
> monitoring the lifecycle of the services, writing some code, etc. If I
> understand well, I'll be able to work with pure injection in e4 (which
> also implies no direct creation of new instances to my point of view
> [coming from the spring world]), and make some kind of "glue code" in
> 3.x to be able to access DS components at some places.
>
> Am I right ? Or is it already possible to inject on the UI layer ? I was
> thinking that maybe the bundle activator, which is actually already
> managed by OSGi would be able to get injected components on it. This
> would solve my problems as I can inject all services that I need to
> access in the UI and then this activator would act as a bridge and I
> would not create any OSGi-dependant code to retrieve service from the
> bundle context...

yes in e4 the workbench acts as the injection container so the task in a
3.x world is to write such a container ontop of the 3.x API (the stuff
presented in my blog and my model editor is a first start) so that
people can consume it and don't have to worry about it.

I think what we would need is a DIViewPart, DIEditorPart and
DICommandHandler which acts as the injection container.

Tom
Re: [e4] How to get ready ? [message #536720 is a reply to message #536718] Sun, 30 May 2010 05:47 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5296
Registered: July 2009
Senior Member
Am 30.05.10 11:35, schrieb Tom Schindl:
> Am 30.05.10 08:13, schrieb Christophe Fondacci:
>> Hello,
>>
>> Thanks for your reply.
>>
>> I was talking about UI command handlers actually.
>>
>> Looked at your model editor and at your blog for your last post "Use
>> D4-DI for 3.x" but I could not find any kind of "injection" at the UI
>> layer. I saw that you retrieve the instance from the bundle context,
>> which insipired the static method I detailed in my last post.
>>
>> But this is not literally "injection", as doing this should also implies
>> monitoring the lifecycle of the services, writing some code, etc. If I
>> understand well, I'll be able to work with pure injection in e4 (which
>> also implies no direct creation of new instances to my point of view
>> [coming from the spring world]), and make some kind of "glue code" in
>> 3.x to be able to access DS components at some places.
>>
>> Am I right ? Or is it already possible to inject on the UI layer ? I was
>> thinking that maybe the bundle activator, which is actually already
>> managed by OSGi would be able to get injected components on it. This
>> would solve my problems as I can inject all services that I need to
>> access in the UI and then this activator would act as a bridge and I
>> would not create any OSGi-dependant code to retrieve service from the
>> bundle context...
>
> yes in e4 the workbench acts as the injection container so the task in a
> 3.x world is to write such a container ontop of the 3.x API (the stuff
> presented in my blog and my model editor is a first start) so that
> people can consume it and don't have to worry about it.
>
> I think what we would need is a DIViewPart, DIEditorPart and
> DICommandHandler which acts as the injection container.
>

Once 4.0 is shipped I think about setting up a project providing those 3
things to people in an 3.x/4.0-compat world. So ideally in a few months
you don't have to worry about the glue code I presented in my blog but
create views and editor e.g. like this:

public class MyEditor extends DIEditor {
public MyEditor() {
super(MyComponent.class);
}
}

and DIEditor acts as the DI-Container just like the Workbench does in e4
world

Tom
Re: [e4] How to get ready ? [message #536909 is a reply to message #536700] Mon, 31 May 2010 09:20 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Christophe Fondacci wrote:
> Hello,
>
> Thanks for your reply.
>
> I was talking about UI command handlers actually.

Just a note. In e4, services and most other contributions are created
using DI.

Handlers for commands are not created with DI (at least they won't be by
the time we ship). Instead, they annotate 2 methods with @CanExecute
and @Execute, and the parameters of those method are provided using the
same algorithm as an object that's create with DI (the parameters are
provided from the executing context, and honour @Named, @Optional etc).

To bridge to the 3.x world would imply using the appropriate context for
your handler and extracting the needed values in the
org.eclipse.core.commands.AbstractHandler.setEnabled(Object) and
org.eclipse.core.commands.IHandler.execute(ExecutionEvent) methods.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: [e4] How to get ready ? [message #537863 is a reply to message #536718] Thu, 03 June 2010 17:51 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5296
Registered: July 2009
Senior Member
Hi Christophe,

Just to inform you on my progress on this. I just announced on the
e4-dev list that the first bits of a Forward Compat Layer are available.

The Forward Compat Layer allows at the moment to use the e4-Programming
model for Views and Editors.

The 3.x integration is done by subclassing DIEditor/DIViewPart like this
(example taken from the my Translator-Demo):

---------------8<---------------
public class TranslatorView extends DIViewPart<TranslatorComponent> {

public static final String ID =
"at.bestsolution.translate.view.views.TranslatorView";

public TranslatorView() {
super(TranslatorComponent.class);
}


/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
getComponent().setFocus();
}

}
---------------8<---------------

TranslatorComponent is an POJO which gets injected all needed
informations available in the Editor-Context.

Tom

Am 30.05.10 11:35, schrieb Tom Schindl:
> Am 30.05.10 08:13, schrieb Christophe Fondacci:
>> Hello,
>>
>> Thanks for your reply.
>>
>> I was talking about UI command handlers actually.
>>
>> Looked at your model editor and at your blog for your last post "Use
>> D4-DI for 3.x" but I could not find any kind of "injection" at the UI
>> layer. I saw that you retrieve the instance from the bundle context,
>> which insipired the static method I detailed in my last post.
>>
>> But this is not literally "injection", as doing this should also implies
>> monitoring the lifecycle of the services, writing some code, etc. If I
>> understand well, I'll be able to work with pure injection in e4 (which
>> also implies no direct creation of new instances to my point of view
>> [coming from the spring world]), and make some kind of "glue code" in
>> 3.x to be able to access DS components at some places.
>>
>> Am I right ? Or is it already possible to inject on the UI layer ? I was
>> thinking that maybe the bundle activator, which is actually already
>> managed by OSGi would be able to get injected components on it. This
>> would solve my problems as I can inject all services that I need to
>> access in the UI and then this activator would act as a bridge and I
>> would not create any OSGi-dependant code to retrieve service from the
>> bundle context...
>
> yes in e4 the workbench acts as the injection container so the task in a
> 3.x world is to write such a container ontop of the 3.x API (the stuff
> presented in my blog and my model editor is a first start) so that
> people can consume it and don't have to worry about it.
>
> I think what we would need is a DIViewPart, DIEditorPart and
> DICommandHandler which acts as the injection container.
>
> Tom
Re: [e4] How to get ready ? [message #537886 is a reply to message #537863] Fri, 04 June 2010 01:03 Go to previous messageGo to next message
Christophe Fondacci is currently offline Christophe Fondacci
Messages: 95
Registered: July 2009
Location: Paris
Member
Nice, thank you Tom !

Paul, regarding your answer, even if handlers won't be instantiated by the DI container, is there a chance that the :
getSite().getService(MyService.class)

ends up by looking in the DI container to return an appropriate implementation ? If so there would be no big deal of not having handlers injected since they could access services from the DI container in an abstract way.

That leads to a pattern in 3.X of creating org.eclipse.ui.services extension which make the bridge with OSGi Declarative Services so that my 3.X handlers can call getSite().getService(...). In e4, I would remove those extensions and keep the same handler code if the getSite().getService(...) performs a OSGi DS lookup...
Is there any problem of doing this ?
Will the service locator of the part site play well will DS ?

Thanks

Christophe
http://www.nextep-softwares.com
Re: [e4] How to get ready ? [message #537991 is a reply to message #537886] Fri, 04 June 2010 08:36 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Christophe Fondacci wrote:
> Nice, thank you Tom !
>
> Paul, regarding your answer, even if handlers won't be instantiated by
> the DI container, is there a chance that the :
>
> getSite().getService(MyService.class)
>
> ends up by looking in the DI container to return an appropriate
> implementation ? If so there would be no big deal of not having handlers
> injected since they could access services from the DI container in an
> abstract way.

In e4 the handler object itself is not injected when it is created,
because the context it is created in might not be the same as the
context it is executed in.

But the canExecute(*) and execute(*) method are run through the same DI
mechanism, just as a single-shot invoke instead of a permanent link.

ex: a handler that was to operate on a part wouldn't use @Inject like this:

@Inject private MPart part;
@Inject private EPartService partService;

Instead they would request the visible part from the context they are
executing in:

@Execute
public void execute(@Optional MPart part, EPartService partService)

That way they will always get the part service relevant to its execution
context.


In e4 with the compatibility layer,
getSite().getService(MyService.class) is simply a pass-through to
e4Context.get(key.getName()); In e4 with the compatibility layer, an
ExeuctionEvent IEvaluationContext is backed by an IEclipseContext as
well, so technically HandlerUtil.getVariable(event,
MyService.class.getName()) would return any applicable e4 service as
well. I'm not sure if our 3.x support that Tom is working on should
offer a DS source provider or not.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Previous Topic:Updating Status bar like TextEditor does
Next Topic:Retrieving Menu Contributions programmatically
Goto Forum:
  


Current Time: Sat Aug 30 02:34:01 EDT 2014

Powered by FUDForum. Page generated in 0.03014 seconds