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.GWT;
19 import com.google.gwt.event.dom.client.ClickEvent;
20 import com.google.gwt.uibinder.client.UiBinder;
21 import com.google.gwt.uibinder.client.UiField;
22 import com.google.gwt.uibinder.client.UiHandler;
23 import com.google.gwt.user.client.Window;
24 import com.google.gwt.user.client.ui.DialogBox;
25 import com.google.gwt.user.client.ui.TextArea;
26 
27 import java.util.logging.Handler;
28 import java.util.logging.Level;
29 import java.util.logging.LogRecord;
30 
31 /**
32  * A simple glasspanel popup that terminates interaction with the application.
33  */
34 class ErrorDialog {
35   interface Binder extends UiBinder<DialogBox, ErrorDialog> {
36   }
37 
38   @UiField
39   DialogBox errorDialog;
40 
41   @UiField
42   TextArea errorMessage;
43 
ErrorDialog()44   public ErrorDialog() {
45     GWT.<Binder> create(Binder.class).createAndBindUi(this);
46   }
47 
48   /**
49    * @return
50    */
getHandler()51   public Handler getHandler() {
52     return new Handler() {
53       {
54         setLevel(Level.SEVERE);
55       }
56 
57       @Override
58       public void close() {
59       }
60 
61       @Override
62       public void flush() {
63       }
64 
65       @Override
66       public void publish(LogRecord record) {
67         if (isLoggable(record)) {
68           errorMessage.setText(record.getMessage());
69           errorDialog.center();
70         }
71       }
72     };
73   }
74 
75   @UiHandler("dismiss")
76   void onDismiss(ClickEvent event) {
77     errorDialog.hide();
78   }
79 
80   @UiHandler("reload")
81   void onReload(ClickEvent event) {
82     Window.Location.reload();
83   }
84 }