1 package autotest.moblab.wizard; 2 3 import com.google.gwt.user.client.ui.FlexTable; 4 import com.google.gwt.user.client.ui.Label; 5 import com.google.gwt.user.client.ui.PasswordTextBox; 6 import com.google.gwt.user.client.ui.TextBox; 7 import com.google.gwt.user.client.ui.Widget; 8 9 import java.util.HashMap; 10 import java.util.Map; 11 12 /** 13 * The base class for a card with flex table layout. 14 */ 15 abstract class FlexWizardCard extends WizardCard { 16 /** 17 * The layout table. 18 */ 19 protected FlexTable layoutTable; 20 21 /** 22 * The card maintains a map from field id string to {@code TextBox}. 23 */ 24 private Map<String, TextBox> fieldMap; 25 FlexWizardCard()26 protected FlexWizardCard() { 27 super(); 28 createCardLayout(); 29 fieldMap = new HashMap<String, TextBox>(); 30 } 31 createCardLayout()32 protected void createCardLayout() { 33 layoutTable = new FlexTable(); 34 layoutTable.getColumnFormatter().addStyleName(0, "wizard-card-property-name-col"); 35 layoutTable.getColumnFormatter().addStyleName(1, "wizard-card-property-value-col"); 36 setCardContentWidget(layoutTable); 37 } 38 39 /** 40 * Creates a widget for String value field based on mode. 41 */ createValueFieldWidget(String fieldId, String value)42 protected Widget createValueFieldWidget(String fieldId, String value) { 43 return createStringValueFieldWidget(fieldId, value, false); 44 } 45 createStringValueFieldWidget(String fieldId, String value, boolean passwordProtected)46 protected Widget createStringValueFieldWidget(String fieldId, String value, 47 boolean passwordProtected) { 48 Widget widget; 49 if (ConfigWizard.Mode.Edit == getMode()) { 50 TextBox textBox = createTextBox(value, passwordProtected); 51 fieldMap.put(fieldId, textBox); 52 widget = textBox; 53 } else { 54 if (value != null && passwordProtected) { 55 value = "********"; 56 } 57 widget = createLabel(value); 58 } 59 widget.setStyleName("wizard-card-property-value"); 60 return widget; 61 } 62 createLabel(String value)63 protected Widget createLabel(String value) { 64 if (value != null) { 65 return new Label(value); 66 } 67 return new Label(); 68 } 69 createTextBox(String value, boolean passwordProtected)70 protected TextBox createTextBox(String value, boolean passwordProtected) { 71 TextBox textBox = passwordProtected ? new PasswordTextBox() : new TextBox(); 72 if (value != null) { 73 textBox.setText(value); 74 } 75 return textBox; 76 } 77 78 @Override resetUI()79 protected void resetUI() { 80 layoutTable.removeAllRows(); 81 fieldMap.clear(); 82 super.resetUI(); 83 } 84 getValueFieldEditor(String fieldId)85 protected TextBox getValueFieldEditor(String fieldId) { 86 return fieldMap.get(fieldId); 87 } 88 }