1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 package com.google.gwt.sample.dynatablerf.client;
17 
18 import com.google.gwt.core.client.EntryPoint;
19 import com.google.gwt.core.client.GWT;
20 import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
21 import com.google.gwt.event.shared.EventBus;
22 import com.google.gwt.event.shared.SimpleEventBus;
23 import com.google.gwt.sample.dynatablerf.client.widgets.DayFilterWidget;
24 import com.google.gwt.sample.dynatablerf.client.widgets.FavoritesWidget;
25 import com.google.gwt.sample.dynatablerf.client.widgets.SummaryWidget;
26 import com.google.gwt.sample.dynatablerf.shared.DynaTableRequestFactory;
27 import com.google.gwt.uibinder.client.UiBinder;
28 import com.google.gwt.uibinder.client.UiField;
29 import com.google.gwt.user.client.ui.RootLayoutPanel;
30 import com.google.gwt.user.client.ui.Widget;
31 import com.google.web.bindery.requestfactory.gwt.client.RequestFactoryLogHandler;
32 import com.google.web.bindery.requestfactory.shared.LoggingRequest;
33 
34 import java.util.ArrayList;
35 import java.util.logging.Level;
36 import java.util.logging.Logger;
37 
38 /**
39  * The entry point class which performs the initial loading of the DynaTableRf
40  * application.
41  */
42 public class DynaTableRf implements EntryPoint {
43   interface Binder extends UiBinder<Widget, DynaTableRf> {
44   }
45 
46   private static final Logger log = Logger.getLogger(DynaTableRf.class.getName());
47 
48   @UiField(provided = true)
49   SummaryWidget calendar;
50 
51   EventBus eventBus = new SimpleEventBus();
52 
53   @UiField(provided = true)
54   FavoritesWidget favorites;
55 
56   @UiField(provided = true)
57   DayFilterWidget filter;
58 
59   /**
60    * This method sets up the top-level services used by the application.
61    */
onModuleLoad()62   public void onModuleLoad() {
63     GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
64       public void onUncaughtException(Throwable e) {
65         log.log(Level.SEVERE, e.getMessage(), e);
66       }
67     });
68 
69     final DynaTableRequestFactory requests = GWT.create(DynaTableRequestFactory.class);
70     requests.initialize(eventBus);
71 
72     // Add remote logging handler
73     RequestFactoryLogHandler.LoggingRequestProvider provider = new RequestFactoryLogHandler.LoggingRequestProvider() {
74       public LoggingRequest getLoggingRequest() {
75         return requests.loggingRequest();
76       }
77     };
78     Logger.getLogger("").addHandler(new ErrorDialog().getHandler());
79     Logger.getLogger("").addHandler(
80         new RequestFactoryLogHandler(provider, Level.WARNING,
81             new ArrayList<String>()));
82     FavoritesManager manager = new FavoritesManager(requests);
83     PersonEditorWorkflow.register(eventBus, requests, manager);
84 
85     calendar = new SummaryWidget(eventBus, requests, 15);
86     favorites = new FavoritesWidget(eventBus, requests, manager);
87     filter = new DayFilterWidget(eventBus);
88 
89     RootLayoutPanel.get().add(
90         GWT.<Binder> create(Binder.class).createAndBindUi(this));
91 
92     // Fast test to see if the sample is not being run from devmode
93     if (GWT.getHostPageBaseURL().startsWith("file:")) {
94       log.log(Level.SEVERE, "The DynaTableRf sample cannot be run without its"
95           + " server component.  If you are running the sample from a"
96           + " GWT distribution, use the 'ant devmode' target to launch"
97           + " the DTRF server.");
98     }
99   }
100 }
101