PageRenderTime 23ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/webccr/src/com/emis/caesarui/webccr/listener/TPhoneNumberKeyPressHandler.java

https://bitbucket.org/sanliou/synccr
Java | 91 lines | 68 code | 14 blank | 9 comment | 14 complexity | 987122345cb404553e5abff08bf9fdba MD5 | raw file
 1package com.emis.caesarui.webccr.listener;
 2
 3import com.emis.caesar.emisComponents;
 4import com.emis.caesarui.webccr.webccr;
 5import com.vaadin.event.Action;
 6import com.vaadin.event.ShortcutAction;
 7import com.vaadin.ui.Button;
 8import com.vaadin.ui.CheckBox;
 9import com.vaadin.ui.UI;
10
11/**
12 *  門號申辦 / 固網申辦 鍵盤監聽
13 */
14public class TPhoneNumberKeyPressHandler implements Action.Handler {
15  Action F1 = new ShortcutAction("F1", ShortcutAction.KeyCode.F1, null);
16  Action F2 = new ShortcutAction("F2", ShortcutAction.KeyCode.F2, null);
17  Action AlphaX = new ShortcutAction("X", 88,new int[]{ShortcutAction.ModifierKey.ALT});
18  Action AlphaS = new ShortcutAction("S", 83,new int[]{ShortcutAction.ModifierKey.ALT});
19
20  private emisComponents bindComponent = null;
21
22  public TPhoneNumberKeyPressHandler() {
23  }
24
25  /**
26   * 綁定當鍵盤輸入資料時,同步顯示的元件
27   *
28   * @param bindcomponent 同步顯示的元件物件
29   */
30  public void bindComponent(emisComponents bindcomponent) {
31    bindComponent = bindcomponent;
32  }
33
34  @Override
35  public Action[] getActions(Object target, Object sender) {
36    return new Action[] {
37        F1, F2, AlphaX, AlphaS
38    };
39  }
40
41  @Override
42  public void handleAction(Action action, Object sender, Object target) {
43    try {
44      ((webccr) UI.getCurrent()).getlog().info(webccr.class, "PhoneNumber HotKey Action = " + action.getCaption());
45      onFunction(action.getCaption());
46    } catch (Exception e) {
47      ((webccr) UI.getCurrent()).getlog().error(webccr.class, e);
48    }
49  }
50
51  private void onFunction(String caption) throws Exception {
52
53    if (bindComponent == null) return;
54    Button _oBtn = null;
55
56    //X單銷卡片
57    CheckBox _oChk = null;
58
59    if ("F1".equalsIgnoreCase(caption)) {
60      _oBtn = (Button) bindComponent.getComponent("btnOK");
61      if (_oBtn != null) {
62        _oBtn.click();
63        return;
64      }
65    }
66
67    if ("F2".equalsIgnoreCase(caption)) {
68      _oBtn = (Button) bindComponent.getComponent("btnOldRenewal");
69      if (_oBtn != null) {
70        _oBtn.click();
71        return;
72      }
73    }
74
75    if ("X".equalsIgnoreCase(caption)) {
76      _oChk = (CheckBox) bindComponent.getComponent("chkCard");
77      if (_oChk != null) {
78        _oChk.setValue(!_oChk.getValue());
79        return;
80      }
81    }
82
83    if ("S".equalsIgnoreCase(caption)) {
84      _oBtn = (Button) bindComponent.getComponent("btnQueryPno");
85      if (_oBtn != null) {
86        _oBtn.click();
87        return;
88      }
89    }
90  }
91}