1 package autotest.tko; 2 3 import autotest.common.ui.ExtendedListBox; 4 import autotest.common.ui.SimplifiedList; 5 import autotest.tko.ParameterizedFieldListPresenter.Display; 6 7 import com.google.gwt.event.dom.client.HasClickHandlers; 8 import com.google.gwt.user.client.ui.Anchor; 9 import com.google.gwt.user.client.ui.Composite; 10 import com.google.gwt.user.client.ui.FlexTable; 11 import com.google.gwt.user.client.ui.HasText; 12 import com.google.gwt.user.client.ui.HorizontalPanel; 13 import com.google.gwt.user.client.ui.Label; 14 import com.google.gwt.user.client.ui.Panel; 15 import com.google.gwt.user.client.ui.TextBox; 16 import com.google.gwt.user.client.ui.VerticalPanel; 17 18 public class ParameterizedFieldListDisplay extends Composite implements Display { 19 private static class FieldWidget implements Display.FieldWidget { 20 private String label; 21 private Anchor deleteLink = new Anchor("[X]"); 22 FieldWidget(String label)23 public FieldWidget(String label) { 24 this.label = label; 25 } 26 getLabel()27 public String getLabel() { 28 return label; 29 } 30 31 @Override getDeleteLink()32 public HasClickHandlers getDeleteLink() { 33 return deleteLink; 34 } 35 } 36 37 private ExtendedListBox typeSelect = new ExtendedListBox(); 38 private TextBox valueInput = new TextBox(); 39 private Anchor addLink = new Anchor("Add"); 40 private FlexTable fieldTable = new FlexTable(); 41 ParameterizedFieldListDisplay()42 public ParameterizedFieldListDisplay() { 43 Panel addFieldPanel = new HorizontalPanel(); 44 addFieldPanel.add(new Label("Add custom field:")); 45 addFieldPanel.add(typeSelect); 46 addFieldPanel.add(valueInput); 47 addFieldPanel.add(addLink); 48 49 fieldTable.setText(0, 0, "Field name"); 50 fieldTable.setText(0, 1, "Filtering name"); 51 fieldTable.setCellSpacing(0); 52 fieldTable.setStylePrimaryName("data-table"); 53 fieldTable.getRowFormatter().setStyleName(0, "data-row-header"); 54 setFieldTableVisible(); 55 56 Panel container = new VerticalPanel(); 57 container.add(fieldTable); 58 container.add(addFieldPanel); 59 initWidget(container); 60 } 61 setFieldTableVisible()62 private void setFieldTableVisible() { 63 boolean visible = (fieldTable.getRowCount() > 1); 64 fieldTable.setVisible(visible); 65 } 66 67 @Override getAddLink()68 public HasClickHandlers getAddLink() { 69 return addLink; 70 } 71 72 @Override getTypeSelect()73 public SimplifiedList getTypeSelect() { 74 return typeSelect; 75 } 76 77 @Override getValueInput()78 public HasText getValueInput() { 79 return valueInput; 80 } 81 82 @Override addFieldWidget(String name, String filteringName)83 public Display.FieldWidget addFieldWidget(String name, String filteringName) { 84 int row = fieldTable.getRowCount(); 85 FieldWidget widget = new FieldWidget(name); 86 fieldTable.setText(row, 0, name); 87 fieldTable.setText(row, 1, filteringName); 88 fieldTable.setWidget(row, 2, widget.deleteLink); 89 setFieldTableVisible(); 90 return widget; 91 } 92 93 @Override removeFieldWidget(Display.FieldWidget widget)94 public void removeFieldWidget(Display.FieldWidget widget) { 95 FieldWidget fieldWidget = (FieldWidget) widget; 96 for (int row = 1; row < fieldTable.getRowCount(); row++) { 97 if (fieldTable.getText(row, 0).equals(fieldWidget.getLabel())) { 98 fieldTable.removeRow(row); 99 setFieldTableVisible(); 100 return; 101 } 102 } 103 104 throw new IllegalArgumentException("Unable to find field widget " + widget); 105 } 106 } 107