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 – running on the UI thread


To execute code on the UI thread, Runnable instances must be posted to the Display via one of two methods, syncExec or asyncExec. The syncExec method runs the code synchronously (the caller blocks until the code has been run) while the asyncExec method runs the code asynchronously (the caller continues while the code is run in the background).

The Display class is SWT's handle to a monitor (so a runtime may have more than one Display object, and each may have its own resolution). To get hold of an instance, call either Display.getCurrent() or Display.getDefault(). However, it's much better to get a Display from an associated view or widget. In this case, the Canvas has an associated Display.

  1. Go to the TickTock thread inside the createPartControl method of the ClockView class.

  2. Inside the redraw lambda, replace the call to clock.redraw() with this:

    // clock.redraw();
    clock.getDisplay().asyncExec(() -> clock.redraw());
  3. Run the target Eclipse instance...