• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package autotest.common.ui;
2 
3 
4 import autotest.common.ui.TableSelectionPanel.SelectionPanelListener;
5 
6 import com.google.gwt.event.dom.client.ClickEvent;
7 import com.google.gwt.event.dom.client.ClickHandler;
8 import com.google.gwt.event.logical.shared.CloseEvent;
9 import com.google.gwt.event.logical.shared.CloseHandler;
10 import com.google.gwt.user.client.ui.Anchor;
11 import com.google.gwt.user.client.ui.Composite;
12 import com.google.gwt.user.client.ui.HorizontalPanel;
13 import com.google.gwt.user.client.ui.Panel;
14 import com.google.gwt.user.client.ui.PopupPanel;
15 import com.google.gwt.user.client.ui.ToggleButton;
16 
17 public class TableActionsPanel extends Composite implements ClickHandler, CloseHandler<PopupPanel>{
18     public static interface TableActionsListener {
getActionMenu()19         public ContextMenu getActionMenu();
20     }
21 
22     public static interface TableActionsWithExportCsvListener extends TableActionsListener {
onExportCsv()23         public void onExportCsv();
24     }
25 
26     private TableActionsListener listener;
27     private TableActionsWithExportCsvListener csvListener;
28     private ToggleButton actionsButton = new ToggleButton("Actions ▾");
29     private TableSelectionPanel selectionPanel;
30     private Anchor exportCsvLink = new Anchor("Export to CSV");
31 
TableActionsPanel(boolean wantSelectVisible)32     public TableActionsPanel(boolean wantSelectVisible) {
33         selectionPanel = new TableSelectionPanel(wantSelectVisible);
34         actionsButton.addClickHandler(this);
35         exportCsvLink.addClickHandler(this);
36         exportCsvLink.setVisible(false);
37         exportCsvLink.getElement().getStyle().setProperty("marginLeft", "1em");
38 
39         Panel mainPanel = new HorizontalPanel();
40         mainPanel.add(selectionPanel);
41         mainPanel.add(actionsButton);
42         mainPanel.add(exportCsvLink);
43         initWidget(mainPanel);
44     }
45 
setActionsListener(TableActionsListener listener)46     public void setActionsListener(TableActionsListener listener) {
47         this.listener = listener;
48     }
49 
50     /**
51      * This automatically enables the Export CSV link, which is disabled by default.
52      */
setActionsWithCsvListener(TableActionsWithExportCsvListener listener)53     public void setActionsWithCsvListener(TableActionsWithExportCsvListener listener) {
54         csvListener = listener;
55         this.listener = listener;
56         exportCsvLink.setVisible(true);
57     }
58 
setSelectionListener(SelectionPanelListener listener)59     public void setSelectionListener(SelectionPanelListener listener) {
60         selectionPanel.setListener(listener);
61     }
62 
onClick(ClickEvent event)63     public void onClick(ClickEvent event) {
64         if (event.getSource() == exportCsvLink) {
65             assert csvListener != null;
66             csvListener.onExportCsv();
67         } else {
68             assert event.getSource() == actionsButton;
69             ContextMenu menu = listener.getActionMenu();
70             menu.addCloseHandler(this);
71             menu.showAt(actionsButton.getAbsoluteLeft(),
72                         actionsButton.getAbsoluteTop() + actionsButton.getOffsetHeight());
73         }
74     }
75 
76     @Override
onClose(CloseEvent<PopupPanel> event)77     public void onClose(CloseEvent<PopupPanel> event) {
78         actionsButton.setDown(false);
79     }
80 }
81