The Eclipse context can supply not only services but also dynamically calculated values. These are supplied via an interface IContextFunction
. By registering a service with that class name and a key name with the service.context.key
, it is possible to create a value upon request.
Create a class called
RandomFunction
, which extendsContextFunction
and which returns a random value:package com.packtpub.e4.application; import org.eclipse.e4.core.contexts.ContextFunction; import org.eclipse.e4.core.contexts.IEclipseContext; public final class RandomFunction extends ContextFunction { @Override public Object compute(final IEclipseContext context) { return Math.random(); } }
To allow E4 to recognize the function, register an instance with the OSGi runtime. Although this could be done within the
Activator
, currently a service ordering bug prevents this from happening. Instead, register it using declarative services.Create a file called
random...