Time for action – drawing a custom view

An SWT Canvas can be used to provide custom rendering for a view. As a starting point for drawing a clock, the Canvas will use drawArc to create a circle.

  1. Remove the content of the ClockView, leaving behind an empty implementation of the setFocus and createPartControl methods.
  2. Run the target Eclipse instance and you will see that the ClockView is now empty.
  3. Create a new method called drawClock that takes a PaintEvent, and use the graphics context gc from the event to draw the circle.
  4. In the createPartControl method, do the following:
    1. Create a new Canvas, which is a drawable widget.
    2. Add a PaintListener to the Canvas that uses a method reference to the drawClock method.
  5. The code will look like this:
    package com.packtpub.e4.clock.ui.views; ...

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.