Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » efxclipse AdapterService vs e4 IAdapterManager(Which one to choose?)
efxclipse AdapterService vs e4 IAdapterManager [message #1711904] Tue, 20 October 2015 09:32 Go to next message
Ali Karimi is currently offline Ali KarimiFriend
Messages: 36
Registered: October 2015
Member
Hey there,

i am developing an eclipse rcp 4 efxclipse application and currently i am a bit confused about the adapter mechanisms e4 and efxclipse provide. One the hand, the one provided by efxclipse as describes here

https://wiki.eclipse.org/Efxclipse/Runtime/Recipes#Adapter_System

and on the other hand the one provided by the eclipse e4 system described here:

https://wiki.eclipse.org/E4/EAS/Adapting_Objects#e4_.28Java.29

As far as i understood, if i want to inject my own objects with DI (using @ContextValue annotation) i should go with the efxclipse approach.

Whereas the e4 approach seems to me to be a little bit more flexible, as it allows to adapt the source type to multiple target types by only using one implementation class acting as a factory. When using the efxlipse OSGI service i have to declare and register a new AdapterProvider for each adaption. I am thinking of a scenario where classA can be adopted to classB and classC.

Maybe someone can sum up, why to choose the one approach over the other. Thanks in advance.

P.S.: The AdapterProvider interface of efxclipse has a method adapt with the following signature:
public T adapt(@NonNull S sourceObject, @NonNull Class<T> targetType, ValueAccess... valueAccess);


Can anyone explain how the class ValueAccess works or provide a working example with full source code of the adapt method?
Re: efxclipse AdapterService vs e4 IAdapterManager [message #1711922 is a reply to message #1711904] Tue, 20 October 2015 10:01 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Yes only the efxclipse adapter service works with our @ContextValue (you
could file a bug report asking us to query the other system as well)

On the way: It is my personal believe that it should be possible to
write components without any dependency on other Eclipse
stuff while equinox-common in general is not that bad it
still is not as lightweight as org.eclipse.fx.core.

On the overhead of creating AdapterProviders for each type: I'd say if
you use @Component annotations this overhead is acceptable.

On ValueAccess: This allows you to retrieve extra information. Eg if the
adaption his happening through the DI-System you can access
IEclipseContext-Values through it.

Tom

On 20.10.15 11:32, Ali Karimi wrote:
> Hey there,
>
> i am developing an eclipse rcp 4 efxclipse application and currently i
> am a bit confused about the adapter mechanisms e4 and efxclipse provide.
> One the hand, the one provided by efxclipse as describes here
> https://wiki.eclipse.org/Efxclipse/Runtime/Recipes#Adapter_System
>
> and on the other hand the one provided by the eclipse e4 system
> described here:
> https://wiki.eclipse.org/E4/EAS/Adapting_Objects#e4_.28Java.29
>
> As far as i understood, if i want to inject my own objects with DI
> (using @ContextValue annotation) i should go with the efxclipse approach.
> Whereas the e4 approach seems to me to be a little bit more flexible, as
> it allows to adapt the source type to multiple target types by only
> using one implementation class acting as a factory. When using the
> efxlipse OSGI service i have to declare and register a new
> AdapterProvider for each adaption. I am thinking of a scenario where
> classA can be adopted to classB and classC.
>
> Maybe someone can sum up, why to choose the one approach over the other.
> Thanks in advance.
>
> P.S.: The AdapterProvider interface of efxclipse has a method adapt with
> the following signature:
>
> public T adapt(@NonNull S sourceObject, @NonNull Class<T> targetType,
> ValueAccess... valueAccess);
>
>
> Can anyone explain how the class ValueAccess works or provide a working
> example with full source code of the adapt method?
Re: efxclipse AdapterService vs e4 IAdapterManager [message #1711937 is a reply to message #1711922] Tue, 20 October 2015 10:56 Go to previous messageGo to next message
Ali Karimi is currently offline Ali KarimiFriend
Messages: 36
Registered: October 2015
Member
Hey,

thank you very much for these explanation. However, unfortunately i have problems in understanding how the
@Component annotation could help me in reducing the overhead of AdapterProvider classes ? Maybe you could give me a small example?
Thanks in advance
Re: efxclipse AdapterService vs e4 IAdapterManager [message #1711947 is a reply to message #1711937] Tue, 20 October 2015 11:55 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
All you need to write is

> package blim;
>
> import org.eclipse.fx.core.adapter.AdapterProvider;
> import org.eclipse.fx.core.adapter.AdapterService.ValueAccess;
> import org.osgi.service.component.annotations.Component;
>
> public abstract class IntegerLongAdapter<T> implements AdapterProvider<String, T> {
> @Override
> public Class<String> getSourceType() {
> return String.class;
> }
>
> @Override
> public boolean canAdapt(String sourceObject, Class<T> targetType) {
> return targetType == Long.class || targetType == Integer.class;
> }
>
> @Override
> public T adapt(String sourceObject, Class<T> targetType, ValueAccess... valueAccess) {
> if( targetType == Long.class ) {
> return (T) Long.valueOf(sourceObject);
> } else {
> return (T) Integer.valueOf(sourceObject);
> }
> }
>
> @Component
> public static class IntProvider extends IntegerLongAdapter<Integer> {
> @Override
> public Class<Integer> getTargetType() {
> return Integer.class;
> }
> }
>
> @Component
> public static class LongProvider extends IntegerLongAdapter<Integer> {
> @Override
> public Class<Integer> getTargetType() {
> return Integer.class;
> }
> }
> }

The whole service registration stuff is generated for you from the
@Component annotation if you have the correct annotation processing
plugin installed.

I think this is an justifiable overhead.

Tom

On 20.10.15 12:56, Ali Karimi wrote:
> Hey,
>
> thank you very much for these explanation. However, unfortunately i have
> problems in understanding how the @Component annotation could help me in
> reducing the overhead of AdapterProvider classes ? Maybe you could give
> me a small example? Thanks in advance
Re: efxclipse AdapterService vs e4 IAdapterManager [message #1712007 is a reply to message #1711947] Tue, 20 October 2015 17:34 Go to previous message
Ali Karimi is currently offline Ali KarimiFriend
Messages: 36
Registered: October 2015
Member
Hey,

thanks for the clarification. Indeed, this minimizes the overload of creating the xml component descriptors to a minimum. For other coming to this threat, what i did is the following:



  1. Install this plugin https://marketplace.eclipse.org/content/declarative-services-annotations-support
  2. Import org.osgi.service.component.annotations in your plugins classpath
  3. create an annotated class in the way described by Tom above
  4. this will automatically generate the corresponding xml service descriptor. Default location is OSGI-INF directory in the plugins root directory.


Regarding the adapter system, i think will go the efxclipse way.
Previous Topic:Binding code.editor.fx.services
Next Topic:P2 check for updates doesn't work
Goto Forum:
  


Current Time: Fri Apr 19 00:54:32 GMT 2024

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

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

Back to the top