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 – getting the window


In an Eclipse 3.x application, the main window is typically accessed via a static accessor such as Display.getDisplay() or workbench.getWorkbenchWindows(). Both of these assume that there is a way of getting to this global list in the first place, often through tightly coupled code references. As well as OSGi services, E4 can also be used to inject references to GUI components. However, rather than accessing the GUI components directly, models are used instead. As a result, components in E4 tend to start with M (for Model)—such as MPart, MWindow, and MPerspective.

  1. To obtain the reference to the window, add a private field MWindow window to the Hello class, along with an @Inject annotation.

  2. Modify the create method so that the label of the text is taken from the window's title (label). The class will look like:

    import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
    public class Hello {
      @Inject
      private MWindow window;
      @PostConstruct
      public void...