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 – responding to input


To show the effect of changing the TimeZone, it is necessary to add an hour hand to the clock. When the TimeZone is changed in the drop-down, the hour hand will be updated.

  1. Add a zone field to the ClockWidget along with a setter:

    private ZoneId zone = ZoneId.systemDefault();
    public void setZone(ZoneId zone) {
      this.zone = zone;
    }
  2. Getters and setters can be generated automatically. Once the field is added, navigate to Source | Generate Getters and Setters. It can be used to generate all missing getters and/or setters; in addition, a single getter/setter can be generated by typing set in the class body, followed by Ctrl + Space (Cmd + Space on macOS).

  3. Add an hour hand in the drawClock method using the following:

    e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_BLACK));
    ZonedDateTime now = ZonedDateTime.now(zone);
    int hours = now.getHour();
    arc = (3 - hours) * 30 % 360;
    e.gc.fillArc(e.x, e.y, e.width-1, e.height-1, arc - 5, 10);
  4. To update the clock when...