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 – dealing with cancellation


Sometimes the user will change their mind; they may have selected the wrong option, or something more important may have come up. The progress monitor allows for two-way communication; the user can signify when they want to cancel as well. There is a method, isCancelled, which returns true if the user has signified in some way that they want the job to finish early.

Periodically checking this during the operation of the Job allows the user to cancel a long-running job before it reaches the end.

  1. Modify the for loop in the HelloHandler to check on each iteration whether the monitor is cancelled:

    for (int i = 0; i < 50 && !monitor.isCanceled(); i++) {
      ...
    }
    if (!monitor.isCancelled()) {
      display.asyncExec(() -> {...});
    }
  2. Run the Eclipse instance and click on the Hello command. This time, go into the Progress view and click on the red stop square next to the job; the job should cancel and the dialog showing the message shouldn't be shown...