Time for action – responding to the user

When the user clicks on the icon, nothing happens. That's because there is no registered listener on the TrayItem itself. There are two listeners that can be registered; a SelectionListener, called when the icon is clicked, and a MenuDetectListener, which can respond to a context-sensitive menu. The former will be used to present a clock in its own window, which in SWT terms is called a Shell.

  1. Open the Activator class.
  2. Go to the lambda inside the asyncExec in the Activator class's start method.
  3. After the creation of the TrayItem, call addSelectionListener with a new anonymous inner subclass of SelectionListener. In the widgetSelected method, a new Shell should be created with a ClockView and then shown:
    trayItem.addSelectionListener(new ...

Get Eclipse Plug-in Development Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.