1package autotest.tko;
2
3import autotest.common.CustomHistory;
4import autotest.common.JsonRpcProxy;
5import autotest.common.SiteCommonClassFactory;
6import autotest.common.StaticDataRepository;
7import autotest.common.CustomHistory.HistoryToken;
8import autotest.common.ui.CustomTabPanel;
9import autotest.common.ui.NotifyManager;
10import autotest.common.ui.TabView;
11import autotest.tko.TableView.TableSwitchListener;
12import autotest.tko.TableView.TableViewConfig;
13
14import com.google.gwt.core.client.EntryPoint;
15import com.google.gwt.user.client.History;
16import com.google.gwt.user.client.ui.RootPanel;
17
18public class TkoClient implements EntryPoint, TableSwitchListener {
19    private CommonPanel commonPanel;
20    private TabView spreadsheetView;
21    private TableView tableView;
22    private GraphingView graphingView;
23    private TestDetailView detailView;
24
25    private CustomTabPanel mainTabPanel = new CustomTabPanel();
26    private SavedQueriesControl savedQueriesControl;
27
28    public void onModuleLoad() {
29        JsonRpcProxy.setDefaultBaseUrl(JsonRpcProxy.TKO_BASE_URL);
30
31        NotifyManager.getInstance().initialize();
32
33        StaticDataRepository.getRepository().refresh(
34                                 new StaticDataRepository.FinishedCallback() {
35            public void onFinished() {
36                finishLoading();
37            }
38        });
39    }
40
41    protected void finishLoading() {
42        SiteCommonClassFactory.globalInitialize();
43
44        commonPanel = CommonPanel.getPanel();
45        spreadsheetView = new SpreadsheetView(this);
46        tableView = new TableView(this);
47        graphingView = new GraphingView(this);
48        detailView = TkoUtils.factory.getTestDetailView();
49
50        mainTabPanel.getCommonAreaPanel().add(commonPanel);
51        mainTabPanel.addTabView(spreadsheetView);
52        mainTabPanel.addTabView(tableView);
53        mainTabPanel.addTabView(graphingView);
54        mainTabPanel.addTabView(detailView);
55
56        savedQueriesControl = new SavedQueriesControl();
57        mainTabPanel.getOtherWidgetsPanel().add(savedQueriesControl);
58
59        final RootPanel tabsRoot = RootPanel.get("tabs");
60        tabsRoot.add(mainTabPanel);
61        commonPanel.initialize();
62        CustomHistory.processInitialToken();
63        mainTabPanel.initialize();
64        tabsRoot.removeStyleName("hidden");
65    }
66
67    public void onSwitchToTable(TableViewConfig config) {
68        tableView.ensureInitialized();
69        switch (config) {
70            case TRIAGE:
71                tableView.setupJobTriage();
72                break;
73            case PASS_RATE:
74                tableView.setupPassRate();
75                break;
76            default:
77                tableView.setupDefaultView();
78                break;
79        }
80        tableView.doQuery();
81        mainTabPanel.selectTabView(tableView);
82    }
83
84    public void onSelectTest(int testId) {
85        History.newItem(getSelectTestHistoryToken(testId).toString());
86    }
87
88    public HistoryToken getSelectTestHistoryToken(int testId) {
89        detailView.ensureInitialized();
90        detailView.updateObjectId(Integer.toString(testId));
91        return detailView.getHistoryArguments();
92    }
93}
94