1 package autotest.moblab.wizard; 2 3 import com.google.gwt.event.dom.client.ClickEvent; 4 import com.google.gwt.event.dom.client.ClickHandler; 5 import com.google.gwt.user.client.ui.Button; 6 import com.google.gwt.user.client.ui.Label; 7 8 import autotest.common.ui.NotifyManager; 9 import autotest.moblab.rpc.MoblabRpcCallbacks; 10 import autotest.moblab.rpc.MoblabRpcHelper; 11 import autotest.moblab.rpc.NetworkInfo; 12 13 /** 14 * Wizard card for network info configuration. 15 */ 16 public class NetworkInfoCard extends FlexWizardCard { 17 // The cached network info. 18 private NetworkInfo networkInfo; 19 20 // Button for network validation. 21 private Button btnValidate; 22 NetworkInfoCard()23 public NetworkInfoCard() { 24 super(); 25 setViewTitle("Moblab Network Information"); 26 setEditTitle("Validate Moblab Network Information"); 27 28 btnValidate = new Button("Query"); 29 btnValidate.addClickHandler(new ClickHandler() { 30 @Override 31 public void onClick(ClickEvent event) { 32 validateNetworkInfo(true); 33 } 34 }); 35 } 36 37 @Override canGoNext()38 public boolean canGoNext() { 39 return networkInfo != null && networkInfo.isConnectedToGoogle(); 40 } 41 42 @Override updateModeUI()43 protected void updateModeUI() { 44 if (networkInfo != null) { 45 resetUI(); 46 int row = 0; 47 layoutTable.setWidget(row, 0, new Label("Server IP")); 48 if (networkInfo.getServerIps().length > 0) { 49 layoutTable.setWidget(row, 1, new Label(networkInfo.getServerIps()[0])); 50 } else { 51 layoutTable.setWidget(row, 1, new Label("Unknown")); 52 } 53 row++; 54 layoutTable.setWidget(row, 0, new Label("Connected to Internet")); 55 layoutTable.setWidget(row, 1, 56 new Label(networkInfo.isConnectedToGoogle() ? "Yes" : "No")); 57 row++; 58 if (getMode() == ConfigWizard.Mode.Edit) { 59 layoutTable.setWidget(row, 0, btnValidate); 60 } 61 } else { 62 validateNetworkInfo(false); 63 } 64 } 65 validateNetworkInfo(final boolean notify)66 protected void validateNetworkInfo(final boolean notify) { 67 MoblabRpcHelper.fetchNetworkInfo(new MoblabRpcCallbacks.FetchNetworkInfoRpcCallback() { 68 @Override 69 public void onNetworkInfoFetched(NetworkInfo info) { 70 networkInfo = info; 71 if (notify) { 72 NotifyManager.getInstance().showMessage("Retrieved netowrk information."); 73 } 74 updateModeUI(); 75 fireDataStatusChanged(); 76 } 77 }); 78 } 79 80 @Override resetData()81 public void resetData() { 82 networkInfo = null; 83 super.resetData(); 84 } 85 } 86