Book Image

Eclipse 4 Plug-in Development by Example : Beginner's Guide

By : Dr Alex Blewitt
Book Image

Eclipse 4 Plug-in Development by Example : Beginner's Guide

By: Dr Alex Blewitt

Overview of this book

<p>As a highly extensible platform, Eclipse is used by everyone from independent software developers to NASA. Key to this is Eclipse’s plug-in ecosystem, which allows applications to be developed in a modular architecture and extended through its use of plug-ins and features.<br /><br />"Eclipse 4 Plug-in Development by Example Beginner's Guide" takes the reader through the full journey of plug-in development, starting with an introduction to Eclipse plug-ins, continued through packaging and culminating in automated testing and deployment. The example code provides simple snippets which can be developed and extended to get you going quickly.</p> <p>This book covers basics of plug-in development, creating user interfaces with both SWT and JFace, and interacting with the user and execution of long-running tasks in the background.</p> <p>Example-based tasks such as creating and working with preferences and advanced tasks such as well as working with Eclipse’s files and resources. A specific chapter on the differences between Eclipse 3.x and Eclipse 4.x presents a detailed view of the changes needed by applications and plug-ins upgrading to the new model. Finally, the book concludes on how to package plug-ins into update sites, and build and test them automatically.</p>
Table of Contents (19 chapters)
Eclipse 4 Plug-in Development by Example Beginner's Guide
Credits
About the Author
Acknowledgement
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 IContextFuction. 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.IContextFunction;
    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. This could be done within the Activator, but currently a bug prevents this from happening. Instead, register it using declarative services. Create a file called random.xml in a folder called...