官术网_书友最值得收藏!

Time for action – getting in focus

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.

  1. Create a timeZones field in the ClockView class:
    private Combo timeZones;
  2. At the end of the 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);
      }
    }
  3. Run the target Eclipse and open the Clock View again; a list of time zone names will be shown in a drop-down:
  4. It's conventional to set the focus on a particular widget when a view is opened. Implement the appropriate call in the ClockView method setFocus:
    public void setFocus() {
      timeZones.setFocus();
    }
  5. Run Eclipse and show the Clock View; the time zone drop-down widget will be focused automatically.

What just happened?

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.

Note

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.

主站蜘蛛池模板: 凉城县| 磐石市| 西安市| 通许县| 丽江市| 陆良县| 桑日县| 无极县| 澄江县| 周口市| 武乡县| 宣汉县| 博罗县| 平定县| 金川县| 怀仁县| 静宁县| 贡山| 六盘水市| 印江| 辰溪县| 望奎县| 忻州市| 肥城市| 建水县| 高邮市| 延长县| 黔南| 高清| 龙南县| 桓仁| 曲麻莱县| 建阳市| 兴仁县| 五家渠市| 固阳县| 徐州市| 新泰市| 如皋市| 清远市| 华容县|