Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Eclipse4/RCP/EAS/Common Services"
(New page: Besides OSGi services, the E4AP also exposes other services that can be consumed by clients. ==Logging== The <tt>org.eclipse.e4.core.services.log.Logger</tt> class provides clients with a...) |
(→Logging) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
==Logging== | ==Logging== | ||
The <tt>org.eclipse.e4.core.services.log.Logger</tt> class provides clients with a number of convenience methods for logging information. Some of its methods takes <tt>Object[]</tt> arrays and will perform binding internally to format the message appropriately. | The <tt>org.eclipse.e4.core.services.log.Logger</tt> class provides clients with a number of convenience methods for logging information. Some of its methods takes <tt>Object[]</tt> arrays and will perform binding internally to format the message appropriately. | ||
+ | |||
+ | <source lang="java"> | ||
+ | void debug(String message); | ||
+ | |||
+ | void info(Throwable t); | ||
+ | |||
+ | void trace(String message, Object[] args); | ||
+ | </source> | ||
+ | |||
+ | ==Adapter Pattern== | ||
+ | The <tt>org.eclipse.e4.core.services.adapter.Adapter</tt> interface provides a way for clients to adapt an object to another type. This is akin to the <tt>org.eclipse.core.runtime.IAdapterFactory</tt> and <tt>org.eclipse.core.runtime.IAdaptable</tt> interfaces from Eclipse 3.x. | ||
+ | |||
+ | ===API Comparison=== | ||
+ | <table border=0> | ||
+ | |||
+ | <!-- ===================================================================== --> | ||
+ | <tr> | ||
+ | <td colspan=2> | ||
+ | <h3>Adapt an object</h3> | ||
+ | </td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td style="background:#ebd3d2;">Eclipse 3.x</td> | ||
+ | <td style="background:#dbf1d2;">Eclipse 4.x</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td style="background:#ebd3d2;"> | ||
+ | <source lang="java"> | ||
+ | public class Consumer { | ||
+ | |||
+ | private Model model; | ||
+ | |||
+ | public void update(Object object) { | ||
+ | IModelProvider provider = (IModelProvider) | ||
+ | Platform.getAdapterManager(object, IModelProvider.class); | ||
+ | if (provider != null) { | ||
+ | model = provider.getModel(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | </td> | ||
+ | <td style="background:#dbf1d2;"> | ||
+ | <source lang="java"> | ||
+ | public class Consumer { | ||
+ | |||
+ | @Inject | ||
+ | private Adapter adapter; | ||
+ | |||
+ | private Model model; | ||
+ | |||
+ | public void update(Object object) { | ||
+ | IModelProvider provider = | ||
+ | adapter.adapt(object, IModelProvider.class); | ||
+ | if (provider != null) { | ||
+ | model = provider.getModel(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | </td> | ||
+ | </tr> | ||
+ | |||
+ | </table> |
Latest revision as of 14:13, 14 April 2011
Besides OSGi services, the E4AP also exposes other services that can be consumed by clients.
Logging
The org.eclipse.e4.core.services.log.Logger class provides clients with a number of convenience methods for logging information. Some of its methods takes Object[] arrays and will perform binding internally to format the message appropriately.
void debug(String message); void info(Throwable t); void trace(String message, Object[] args);
Adapter Pattern
The org.eclipse.e4.core.services.adapter.Adapter interface provides a way for clients to adapt an object to another type. This is akin to the org.eclipse.core.runtime.IAdapterFactory and org.eclipse.core.runtime.IAdaptable interfaces from Eclipse 3.x.
API Comparison
Adapt an object |
|
Eclipse 3.x | Eclipse 4.x |
public class Consumer { private Model model; public void update(Object object) { IModelProvider provider = (IModelProvider) Platform.getAdapterManager(object, IModelProvider.class); if (provider != null) { model = provider.getModel(); } } } |
public class Consumer { @Inject private Adapter adapter; private Model model; public void update(Object object) { IModelProvider provider = adapter.adapt(object, IModelProvider.class); if (provider != null) { model = provider.getModel(); } } } |