xref: /aosp_15_r20/external/autotest/frontend/client/src/autotest/afe/AfeClient.java (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1 package autotest.afe;
2 
3 import autotest.afe.HostDetailView.HostDetailListener;
4 import autotest.afe.HostListView.HostListListener;
5 import autotest.afe.JobDetailView.JobDetailListener;
6 import autotest.afe.JobListView.JobSelectListener;
7 import autotest.afe.create.CreateJobViewPresenter.JobCreateListener;
8 import autotest.afe.create.CreateJobViewTab;
9 import autotest.common.CustomHistory;
10 import autotest.common.JsonRpcProxy;
11 import autotest.common.SiteCommonClassFactory;
12 import autotest.common.StaticDataRepository;
13 import autotest.common.ui.CustomTabPanel;
14 import autotest.common.ui.NotifyManager;
15 import autotest.common.ui.TabView;
16 
17 import com.google.gwt.core.client.EntryPoint;
18 import com.google.gwt.dom.client.Document;
19 import com.google.gwt.json.client.JSONValue;
20 import com.google.gwt.user.client.ui.RootPanel;
21 import com.google.gwt.user.client.Window.Location;
22 
23 
24 public class AfeClient implements EntryPoint {
25     private JobListView jobList;
26     private JobDetailView jobDetail;
27     private CreateJobViewTab createJob;
28     private HostListView hostListView;
29     private HostDetailView hostDetailView;
30 
31     public CustomTabPanel mainTabPanel;
32 
33     /**
34      * Application entry point.
35      */
onModuleLoad()36     public void onModuleLoad() {
37         JsonRpcProxy.setDefaultBaseUrl(JsonRpcProxy.AFE_BASE_URL);
38         NotifyManager.getInstance().initialize();
39 
40         // initialize static data, and don't show main UI until that's done
41         StaticDataRepository.getRepository().refresh(
42                                  new StaticDataRepository.FinishedCallback() {
43             public void onFinished() {
44                 finishLoading();
45             }
46         });
47     }
48 
49     private JobCreateListener jobCreateListener = new JobCreateListener() {
50         public void onJobCreated(int jobId) {
51             showJob(jobId);
52         }
53     };
54 
finishLoading()55     protected void finishLoading() {
56         SiteCommonClassFactory.globalInitialize();
57 
58         String stainlessUrl = StaticDataRepository.getRepository().getData(
59             "stainless_url").isString().stringValue();
60         if (!stainlessUrl.equals("")) {
61             Document.get().getElementById("stainless-link").setAttribute(
62                 "href", stainlessUrl);
63             Document.get().getElementById("stainless").removeClassName(
64                 "hidden");
65         }
66         boolean is_moblab = StaticDataRepository.getRepository().getData(
67             "is_moblab").isBoolean().booleanValue();
68         mainTabPanel = new CustomTabPanel(is_moblab);
69         if (is_moblab) {
70             Document.get().getElementById("moblab_setup").removeClassName("hidden");
71             Document.get().getElementById("mobmonitor_link").setAttribute("href",
72                 "http://" + Location.getHostName() + ":9991");
73         } else {
74             Document.get().getElementById("hide_on_moblab").removeClassName("hidden");
75         }
76 
77         jobList = new JobListView(new JobSelectListener() {
78             public void onJobSelected(int jobId) {
79                 showJob(jobId);
80             }
81         });
82         jobDetail = new JobDetailView(new JobDetailListener() {
83             public void onHostSelected(String hostId) {
84                 showHost(hostId);
85             }
86 
87             public void onCloneJob(JSONValue cloneInfo) {
88                 createJob.ensureInitialized();
89                 mainTabPanel.selectTabView(createJob);
90                 // Makes sure we set cloning mode after the tab is selected. Otherwise,
91                 // the mode will be reset.
92                 createJob.cloneJob(cloneInfo);
93             }
94         });
95 
96         createJob = AfeUtils.factory.getCreateJobView(jobCreateListener);
97 
98         hostListView = new HostListView(new HostListListener() {
99             public void onHostSelected(String hostId) {
100                 showHost(hostId);
101             }
102         }, jobCreateListener);
103 
104         hostDetailView = new HostDetailView(new HostDetailListener() {
105             public void onJobSelected(int jobId) {
106                 showJob(jobId);
107             }
108         }, jobCreateListener);
109 
110         TabView[] tabViews = new TabView[] {jobList, jobDetail, createJob,
111                                             hostListView, hostDetailView};
112         for (TabView tabView : tabViews) {
113             mainTabPanel.addTabView(tabView);
114         }
115 
116         final RootPanel tabsRoot = RootPanel.get("tabs");
117         tabsRoot.add(mainTabPanel);
118         CustomHistory.processInitialToken();
119         mainTabPanel.initialize();
120         tabsRoot.setStyleName("");
121     }
122 
showJob(int jobId)123     protected void showJob(int jobId) {
124         jobDetail.ensureInitialized();
125         jobDetail.updateObjectId(Integer.toString(jobId));
126         mainTabPanel.selectTabView(jobDetail);
127     }
128 
showHost(String hostId)129     protected void showHost(String hostId) {
130         hostDetailView.ensureInitialized();
131         hostDetailView.updateObjectId(hostId);
132         mainTabPanel.selectTabView(hostDetailView);
133     }
134 }
135