Home | History | Annotate | Download | only in afe
      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      */
     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 
     55     protected void finishLoading() {
     56         SiteCommonClassFactory.globalInitialize();
     57 
     58         String wmatrixUrl = StaticDataRepository.getRepository().getData(
     59             "wmatrix_url").isString().stringValue();
     60         if (!wmatrixUrl.equals("")) {
     61             Document.get().getElementById("wmatrix-link").setAttribute(
     62                 "href", wmatrixUrl);
     63             Document.get().getElementById("wmatrix").removeClassName("hidden");
     64         }
     65         String stainlessUrl = StaticDataRepository.getRepository().getData(
     66             "stainless_url").isString().stringValue();
     67         if (!stainlessUrl.equals("")) {
     68             Document.get().getElementById("stainless-link").setAttribute(
     69                 "href", stainlessUrl);
     70             Document.get().getElementById("stainless").removeClassName(
     71                 "hidden");
     72         }
     73         boolean is_moblab = StaticDataRepository.getRepository().getData(
     74             "is_moblab").isBoolean().booleanValue();
     75         mainTabPanel = new CustomTabPanel(is_moblab);
     76         if (is_moblab) {
     77             Document.get().getElementById("moblab_setup").removeClassName("hidden");
     78             Document.get().getElementById("mobmonitor_link").setAttribute("href",
     79                 "http://" + Location.getHostName() + ":9991");
     80         }
     81 
     82         jobList = new JobListView(new JobSelectListener() {
     83             public void onJobSelected(int jobId) {
     84                 showJob(jobId);
     85             }
     86         });
     87         jobDetail = new JobDetailView(new JobDetailListener() {
     88             public void onHostSelected(String hostId) {
     89                 showHost(hostId);
     90             }
     91 
     92             public void onCloneJob(JSONValue cloneInfo) {
     93                 createJob.ensureInitialized();
     94                 mainTabPanel.selectTabView(createJob);
     95                 // Makes sure we set cloning mode after the tab is selected. Otherwise,
     96                 // the mode will be reset.
     97                 createJob.cloneJob(cloneInfo);
     98             }
     99         });
    100 
    101         createJob = AfeUtils.factory.getCreateJobView(jobCreateListener);
    102 
    103         hostListView = new HostListView(new HostListListener() {
    104             public void onHostSelected(String hostId) {
    105                 showHost(hostId);
    106             }
    107         }, jobCreateListener);
    108 
    109         hostDetailView = new HostDetailView(new HostDetailListener() {
    110             public void onJobSelected(int jobId) {
    111                 showJob(jobId);
    112             }
    113         }, jobCreateListener);
    114 
    115         TabView[] tabViews = new TabView[] {jobList, jobDetail, createJob,
    116                                             hostListView, hostDetailView};
    117         for (TabView tabView : tabViews) {
    118             mainTabPanel.addTabView(tabView);
    119         }
    120 
    121         final RootPanel tabsRoot = RootPanel.get("tabs");
    122         tabsRoot.add(mainTabPanel);
    123         CustomHistory.processInitialToken();
    124         mainTabPanel.initialize();
    125         tabsRoot.setStyleName("");
    126     }
    127 
    128     protected void showJob(int jobId) {
    129         jobDetail.ensureInitialized();
    130         jobDetail.updateObjectId(Integer.toString(jobId));
    131         mainTabPanel.selectTabView(jobDetail);
    132     }
    133 
    134     protected void showHost(String hostId) {
    135         hostDetailView.ensureInitialized();
    136         hostDetailView.updateObjectId(hostId);
    137         mainTabPanel.selectTabView(hostDetailView);
    138     }
    139 }
    140