1 package autotest.moblab.wizard; 2 3 import com.google.gwt.event.logical.shared.ValueChangeEvent; 4 import com.google.gwt.event.logical.shared.ValueChangeHandler; 5 import com.google.gwt.json.client.JSONObject; 6 import com.google.gwt.user.client.ui.Label; 7 import com.google.gwt.user.client.ui.TextBox; 8 9 import autotest.common.Utils; 10 import autotest.moblab.rpc.WifiInfo; 11 import autotest.moblab.rpc.MoblabRpcCallbacks; 12 import autotest.moblab.rpc.MoblabRpcHelper; 13 14 import java.util.HashMap; 15 16 /** 17 * Wizard card for wifi configuration. 18 */ 19 public class WifiCard extends FlexWizardCard { 20 /** 21 * The cached wifi information. 22 */ 23 private WifiInfo wifiInfo; 24 WifiCard()25 public WifiCard() { 26 super(); 27 setViewTitle("DUT Wifi Configuration"); 28 setEditTitle("Configure DUT Wifi Access Configuration"); 29 } 30 31 @Override updateModeUI()32 protected void updateModeUI() { 33 if (wifiInfo != null) { 34 resetUI(); 35 int row = 0; 36 37 // Row for AP. 38 row++; 39 layoutTable.setWidget(row, 0, new Label("Wifi Access Point Name: ")); 40 layoutTable.setWidget(row, 1, createValueFieldWidget(WifiInfo.JSON_FIELD_AP_NAME, 41 wifiInfo.getApName())); 42 43 // Row for wifi key. 44 row++; 45 layoutTable.setWidget(row, 0, new Label("Wifi Access Point Password: ")); 46 layoutTable.setWidget(row, 1, createStringValueFieldWidget( 47 WifiInfo.JSON_FIELD_AP_PASS, wifiInfo.getApPass(), true)); 48 49 } else { 50 MoblabRpcHelper.fetchWifiInfo(new MoblabRpcCallbacks.FetchWifiInfoCallback() { 51 @Override 52 public void onWifiInfoFetched(WifiInfo info) { 53 wifiInfo = info; 54 updateModeUI(); 55 } 56 }); 57 } 58 } 59 60 @Override validate(final CardValidationCallback callback)61 public void validate(final CardValidationCallback callback) { 62 wifiInfo.setApName(getStringValueFieldValue(WifiInfo.JSON_FIELD_AP_NAME)); 63 wifiInfo.setApPass(getStringValueFieldValue(WifiInfo.JSON_FIELD_AP_PASS)); 64 WifiCard.super.validate(callback); 65 return; 66 } 67 68 /** 69 * Gets the string input field value. 70 */ getStringValueFieldValue(String fieldId)71 protected String getStringValueFieldValue(String fieldId) { 72 TextBox textBox = getValueFieldEditor(fieldId); 73 String value = textBox.getValue(); 74 if (value != null) { 75 value = value.trim(); 76 } 77 78 if (value == null) { 79 return null; 80 } 81 if (value.isEmpty()) { 82 return null; 83 } 84 return value; 85 } 86 87 @Override resetData()88 public void resetData() { 89 wifiInfo = null; 90 super.resetData(); 91 } 92 93 @Override collectConfigData(@uppressWarnings"unused") HashMap<String, JSONObject> map)94 public void collectConfigData(@SuppressWarnings("unused") HashMap<String, JSONObject> map) { 95 if (map != null && wifiInfo != null) { 96 map.put(MoblabRpcHelper.RPC_PARAM_WIFI_INFO, wifiInfo.toJson()); 97 } 98 } 99 } 100