To allow the time zone of the clock widgets to be changed, a drop-down box (known as Combo
) as well as a Button
will be added to the view. The Combo
will be created from a set of ZoneId
instances.
timeZones
field in the ClockView
class:private Combo timeZones;
createPartControl
method, add this snippet to create the drop-down list:public void createPartControl(Composite parent) { ... timeZones = new Combo(parent, SWT.DROP_DOWN); timeZones.setVisibleItemCount(5); for (String zone : ZoneId.getAvailableZoneIds()) { timeZones.add(zone); } }
ClockView
method setFocus
:public void setFocus() { timeZones.setFocus(); }
Every SWT Control
has a setFocus
method, which is used to switch focus for the application to that particular widget. When the view is focused (which happens both when it's opened and also when the user switches to it after being in a different view), its setFocus
method is called.
As will be discussed in Chapter 7, Creating Eclipse 4 Applications, in E4 the method may be called anything and annotated with the @Focus
annotation. Conventionally, and to save sanity, it helps to call this method setFocus
.
3.145.111.183