1 package autotest.common.ui; 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.Anchor; 6 import com.google.gwt.user.client.ui.Composite; 7 import com.google.gwt.user.client.ui.HTML; 8 import com.google.gwt.user.client.ui.HorizontalPanel; 9 import com.google.gwt.user.client.ui.Panel; 10 11 public class TableSelectionPanel extends Composite implements ClickHandler { 12 public static interface SelectionPanelListener { onSelectAll(boolean visibleOnly)13 public void onSelectAll(boolean visibleOnly); onSelectNone()14 public void onSelectNone(); 15 } 16 17 private SelectionPanelListener listener; 18 private Anchor selectAll = new Anchor("all"); 19 private Anchor selectVisible; 20 private Anchor selectNone = new Anchor("none"); 21 TableSelectionPanel(boolean wantSelectVisible)22 public TableSelectionPanel(boolean wantSelectVisible) { 23 selectAll.addClickHandler(this); 24 selectNone.addClickHandler(this); 25 26 Panel selectPanel = new HorizontalPanel(); 27 selectPanel.add(new HTML("Select: ")); 28 selectPanel.add(selectAll); 29 selectPanel.add(new HTML(", ")); 30 if (wantSelectVisible) { 31 selectVisible = new Anchor("visible"); 32 selectVisible.addClickHandler(this); 33 selectPanel.add(selectVisible); 34 selectPanel.add(new HTML(", ")); 35 } 36 selectPanel.add(selectNone); 37 selectPanel.add(new HTML(" ")); 38 initWidget(selectPanel); 39 } 40 setListener(SelectionPanelListener listener)41 public void setListener(SelectionPanelListener listener) { 42 this.listener = listener; 43 } 44 onClick(ClickEvent event)45 public void onClick(ClickEvent event) { 46 if (event.getSource() == selectAll) { 47 listener.onSelectAll(false); 48 } else if (event.getSource() == selectVisible) { 49 listener.onSelectAll(true); 50 } else { 51 assert event.getSource() == selectNone; 52 listener.onSelectNone(); 53 } 54 } 55 } 56