• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.RecurringView.RecurringSelectListener;
8 import autotest.afe.UserPreferencesView.UserPreferencesListener;
9 import autotest.afe.create.CreateJobViewPresenter.JobCreateListener;
10 import autotest.afe.create.CreateJobViewTab;
11 import autotest.common.CustomHistory;
12 import autotest.common.JsonRpcProxy;
13 import autotest.common.SiteCommonClassFactory;
14 import autotest.common.StaticDataRepository;
15 import autotest.common.ui.CustomTabPanel;
16 import autotest.common.ui.NotifyManager;
17 import autotest.common.ui.TabView;
18 
19 import com.google.gwt.core.client.EntryPoint;
20 import com.google.gwt.dom.client.Document;
21 import com.google.gwt.json.client.JSONValue;
22 import com.google.gwt.user.client.ui.RootPanel;
23 import com.google.gwt.user.client.Window.Location;
24 
25 
26 public class AfeClient implements EntryPoint {
27     private JobListView jobList;
28     private JobDetailView jobDetail;
29     private RecurringView recurringView;
30     private CreateJobViewTab createJob;
31     private HostListView hostListView;
32     private HostDetailView hostDetailView;
33     private UserPreferencesView userPreferencesView;
34 
35     public CustomTabPanel mainTabPanel = new CustomTabPanel();
36 
37     /**
38      * Application entry point.
39      */
onModuleLoad()40     public void onModuleLoad() {
41         JsonRpcProxy.setDefaultBaseUrl(JsonRpcProxy.AFE_BASE_URL);
42         NotifyManager.getInstance().initialize();
43 
44         // initialize static data, and don't show main UI until that's done
45         StaticDataRepository.getRepository().refresh(
46                                  new StaticDataRepository.FinishedCallback() {
47             public void onFinished() {
48                 finishLoading();
49             }
50         });
51     }
52 
53     private JobCreateListener jobCreateListener = new JobCreateListener() {
54         public void onJobCreated(int jobId) {
55             showJob(jobId);
56         }
57     };
58 
finishLoading()59     protected void finishLoading() {
60         SiteCommonClassFactory.globalInitialize();
61 
62         String wmatrixUrl = StaticDataRepository.getRepository().getData(
63             "wmatrix_url").isString().stringValue();
64         if (!wmatrixUrl.equals("")) {
65             Document.get().getElementById("wmatrix-link").setAttribute(
66                 "href", wmatrixUrl);
67             Document.get().getElementById("wmatrix").removeClassName("hidden");
68         }
69         boolean is_moblab = StaticDataRepository.getRepository().getData(
70             "is_moblab").isBoolean().booleanValue();
71         if (is_moblab) {
72             Document.get().getElementById("moblab_setup").removeClassName("hidden");
73             Document.get().getElementById("mobmonitor_link").setAttribute("href",
74                 "http://" + Location.getHostName() + ":9991");
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                 createJob.cloneJob(cloneInfo);
90                 mainTabPanel.selectTabView(createJob);
91             }
92 
93             public void onCreateRecurringJob(int jobId) {
94                 recurringView.ensureInitialized();
95                 recurringView.createRecurringJob(jobId);
96                 mainTabPanel.selectTabView(recurringView);
97             }
98         });
99 
100         recurringView = new RecurringView(new RecurringSelectListener() {
101             public void onRecurringSelected(int jobId) {
102                 showJob(jobId);
103             }
104         });
105 
106         createJob = AfeUtils.factory.getCreateJobView(jobCreateListener);
107 
108         hostListView = new HostListView(new HostListListener() {
109             public void onHostSelected(String hostId) {
110                 showHost(hostId);
111             }
112         }, jobCreateListener);
113 
114         hostDetailView = new HostDetailView(new HostDetailListener() {
115             public void onJobSelected(int jobId) {
116                 showJob(jobId);
117             }
118         }, jobCreateListener);
119 
120         userPreferencesView = new UserPreferencesView(new UserPreferencesListener() {
121             public void onPreferencesChanged() {
122                 createJob.onPreferencesChanged();
123             }
124         });
125 
126         TabView[] tabViews = new TabView[] {jobList, jobDetail, recurringView, createJob,
127                                             hostListView, hostDetailView, userPreferencesView};
128         for (TabView tabView : tabViews) {
129             mainTabPanel.addTabView(tabView);
130         }
131 
132         final RootPanel tabsRoot = RootPanel.get("tabs");
133         tabsRoot.add(mainTabPanel);
134         CustomHistory.processInitialToken();
135         mainTabPanel.initialize();
136         tabsRoot.setStyleName("");
137     }
138 
showJob(int jobId)139     protected void showJob(int jobId) {
140         jobDetail.ensureInitialized();
141         jobDetail.updateObjectId(Integer.toString(jobId));
142         mainTabPanel.selectTabView(jobDetail);
143     }
144 
showHost(String hostId)145     protected void showHost(String hostId) {
146         hostDetailView.ensureInitialized();
147         hostDetailView.updateObjectId(hostId);
148         mainTabPanel.selectTabView(hostDetailView);
149     }
150 }
151