1package autotest.tko;
2
3import autotest.common.ui.DoubleListSelector;
4import autotest.common.ui.ExtendedListBox;
5import autotest.common.ui.MultiListSelectPresenter;
6import autotest.common.ui.SimplifiedList;
7import autotest.common.ui.ToggleControl;
8import autotest.common.ui.ToggleLink;
9import autotest.common.ui.MultiListSelectPresenter.DoubleListDisplay;
10import autotest.common.ui.MultiListSelectPresenter.ToggleDisplay;
11
12import com.google.gwt.user.client.ui.Composite;
13import com.google.gwt.user.client.ui.HasText;
14import com.google.gwt.user.client.ui.Panel;
15import com.google.gwt.user.client.ui.StackPanel;
16import com.google.gwt.user.client.ui.TextArea;
17import com.google.gwt.user.client.ui.VerticalPanel;
18
19public class SpreadsheetHeaderSelectorView extends Composite
20                                           implements MultiListSelectPresenter.ToggleDisplay,
21                                                      SpreadsheetHeaderSelect.Display {
22    protected final static String SWITCH_TO_SINGLE = "Switch to single";
23    protected final static String SWITCH_TO_MULTIPLE = "Switch to multiple";
24    static final String CANCEL_FIXED_VALUES = "Don't use fixed values";
25    static final String USE_FIXED_VALUES = "Fixed values...";
26
27    private ToggleLink fixedValuesToggle = new ToggleLink(USE_FIXED_VALUES, CANCEL_FIXED_VALUES);
28    private TextArea fixedValues = new TextArea();
29    private ExtendedListBox listBox = new ExtendedListBox();
30    private DoubleListSelector doubleListDisplay = new DoubleListSelector();
31    private StackPanel stack = new StackPanel();
32    private ToggleLink multipleSelectToggle = new ToggleLink(SWITCH_TO_MULTIPLE, SWITCH_TO_SINGLE);
33
34    public SpreadsheetHeaderSelectorView() {
35        Panel singleHeaderOptions = new VerticalPanel();
36        singleHeaderOptions.add(listBox);
37
38        stack.add(singleHeaderOptions);
39        stack.add(doubleListDisplay);
40
41        Panel fixedValuePanel = new VerticalPanel();
42        fixedValuePanel.add(fixedValuesToggle);
43        fixedValuePanel.add(fixedValues);
44
45        Panel panel = new VerticalPanel();
46        panel.add(stack);
47        panel.add(fixedValuePanel);
48        panel.add(multipleSelectToggle);
49        initWidget(panel);
50
51        fixedValues.setVisible(false);
52        fixedValues.addStyleName("fixed-headers-input");
53    }
54
55    @Override
56    public HasText getFixedValuesInput() {
57        return fixedValues;
58    }
59
60    @Override
61    public ToggleLink getFixedValuesToggle() {
62        return fixedValuesToggle;
63    }
64
65    @Override
66    public void setFixedValuesVisible(boolean visible) {
67        fixedValues.setVisible(visible);
68    }
69
70    @Override
71    public DoubleListDisplay getDoubleListDisplay() {
72        return doubleListDisplay;
73    }
74
75    @Override
76    public ToggleDisplay getToggleDisplay() {
77        return this;
78    }
79
80    @Override
81    public SimplifiedList getSingleSelector() {
82        return listBox;
83    }
84
85    @Override
86    public ToggleControl getToggleMultipleLink() {
87        return multipleSelectToggle;
88    }
89
90    @Override
91    public void setDoubleListVisible(boolean doubleListVisible) {
92        stack.showStack(doubleListVisible ? 1 : 0);
93    }
94}
95