Time for action – calculating values on demand

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.

  1. Create a class called RandomFunction, which extends ContextFunction 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();
      }
    }
  2. To allow E4 to recognize the function, ...

Get Eclipse Plug-in Development Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.