Book Image

Eclipse Plug-in Development Beginner's Guide - Second Edition

By : Alex Blewitt
Book Image

Eclipse Plug-in Development Beginner's Guide - Second Edition

By: Alex Blewitt

Overview of this book

Eclipse is used by everyone from indie devs to NASA engineers. Its popularity is underpinned by its impressive plug-in ecosystem, which allows it to be extended to meet the needs of whoever is using it. This book shows you how to take full advantage of the Eclipse IDE by building your own useful plug-ins from start to finish. Taking you through the complete process of plug-in development, from packaging to automated testing and deployment, this book is a direct route to quicker, cleaner Java development. It may be for beginners, but we're confident that you'll develop new skills quickly. Pretty soon you'll feel like an expert, in complete control of your IDE. Don't let Eclipse define you - extend it with the plug-ins you need today for smarter, happier, and more effective development.
Table of Contents (24 chapters)
Eclipse Plug-in Development Beginner's Guide Second Edition
Credits
Foreword
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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, 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...