Revision: 8346
Author: unn...@google.com
Date: Thu Jul 1 14:10:00 2010
Log: Update sample to use the latest features
Review at http://gwt-code-reviews.appspot.com/672801
Review by: fre...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=8346
Deleted:
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/server
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/shared
Modified:
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/CustomLogArea.java
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/HandlerController.java
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/HandlerController.ui.xml
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/LogExample.java
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/LoggerController.java
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/OneLoggerController.java
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/OneLoggerController.ui.xml
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/ServerLoggingArea.java
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/ServerLoggingArea.ui.xml
=======================================
---
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/CustomLogArea.java
Fri Jun 18 13:13:05 2010
+++
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/CustomLogArea.java
Thu Jul 1 14:10:00 2010
@@ -1,12 +1,12 @@
/*
* Copyright 2010 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may
not
* use this file except in compliance with the License. You may obtain a
copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -18,6 +18,7 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.logging.client.HasWidgetsLogHandler;
+import com.google.gwt.logging.client.LogConfiguration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.HTMLPanel;
@@ -37,16 +38,21 @@
public CustomLogArea(Logger logger) {
panel = uiBinder.createAndBindUi(this);
-
+
// An example of adding our own custom logging area. Since
VerticalPanel
- // extends HasWidgets, and handles multiple class to add(widget)
gracefully
- // then we simply create a new HasWidgetsLogHandler with it, and add
that
- // handler to a logger. In this case, we added it to a particular
logger in
+ // extends HasWidgets, and handles multiple calls to add(widget)
gracefully
+ // we simply create a new HasWidgetsLogHandler with it, and add that
+ // handler to a logger. In this case, we add it to a particular logger
in
// order to demonstrate how the logger hierarchy works, but adding it
to the
- // root logger would be fine.
- logger.addHandler(new HasWidgetsLogHandler(customLogArea));
- }
-
+ // root logger would be fine. Note that we guard this code with a call
to
+ // LogConfiguration.loggingIsEnabled(). Although this code will
compile out
+ // without this check in web mode, the guard will ensure that the
handler
+ // does not show up in development mode.
+ if (LogConfiguration.loggingIsEnabled()) {
+ logger.addHandler(new HasWidgetsLogHandler(customLogArea));
+ }
+ }
+
public Panel getPanel() {
return panel;
}
=======================================
---
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/HandlerController.java
Mon Jun 28 12:35:42 2010
+++
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/HandlerController.java
Thu Jul 1 14:10:00 2010
@@ -1,12 +1,12 @@
/*
* Copyright 2010 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may
not
* use this file except in compliance with the License. You may obtain a
copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -44,23 +44,23 @@
private class CheckboxHandler implements ValueChangeHandler<Boolean> {
private CheckBox checkbox;
private Handler handler;
-
+
public CheckboxHandler(CheckBox checkbox, Handler handler) {
this.checkbox = checkbox;
this.handler = handler;
}
-
+
public void onValueChange(ValueChangeEvent<Boolean> event) {
if (checkbox.getValue()) {
logger.addHandler(handler);
} else {
logger.removeHandler(handler);
}
- }
- }
-
+ }
+ }
+
interface MyUiBinder extends UiBinder<HTMLPanel, HandlerController> { }
-
+
private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
@UiField CheckBox consoleCheckbox;
@UiField CheckBox devmodeCheckbox;
@@ -71,11 +71,10 @@
private Map<String, Handler> handlers;
private Logger logger;
private Panel panel;
-
+
public HandlerController(final Logger logger) {
this.logger = logger;
panel = uiBinder.createAndBindUi(this);
-
Handler[] handlersArray = logger.getHandlers();
handlers = new HashMap<String, Handler>();
if (handlersArray != null) {
@@ -83,20 +82,20 @@
handlers.put(h.getClass().getName(), h);
}
}
- setupHandler(SystemLogHandler.class.getName(), systemCheckbox);
- setupHandler(ConsoleLogHandler.class.getName(), consoleCheckbox);
- setupHandler(DevelopmentModeLogHandler.class.getName(),
devmodeCheckbox);
- setupHandler(FirebugLogHandler.class.getName(), firebugCheckbox);
- setupHandler(HasWidgetsLogHandler.class.getName(), popupCheckbox);
- setupHandler(SimpleRemoteLogHandler.class.getName(), remoteCheckbox);
- }
-
+ setupHandler(SystemLogHandler.class, systemCheckbox);
+ setupHandler(ConsoleLogHandler.class, consoleCheckbox);
+ setupHandler(DevelopmentModeLogHandler.class, devmodeCheckbox);
+ setupHandler(FirebugLogHandler.class, firebugCheckbox);
+ setupHandler(HasWidgetsLogHandler.class, popupCheckbox);
+ setupHandler(SimpleRemoteLogHandler.class, remoteCheckbox);
+ }
+
public Panel getPanel() {
return panel;
}
-
- void setupHandler(String name, CheckBox checkbox) {
- Handler h = handlers.get(name);
+
+ void setupHandler(Class clazz, CheckBox checkbox) {
+ Handler h = handlers.get(clazz.getName());
if (h == null) {
checkbox.setEnabled(false);
} else {
=======================================
---
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/HandlerController.ui.xml
Mon Jun 28 12:35:42 2010
+++
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/HandlerController.ui.xml
Thu Jul 1 14:10:00 2010
@@ -4,8 +4,8 @@
The Root Logger comes with a set of handlers added by default. You can
configure which handlers are added in the gwt.xml file, and you can
also
add/remove them programatically. Below, we have greyed out any handlers
- which are not being added due to gwt.xml file configuration, and
- checking/unchecking boxes will add/remove them programatically.
+ which are not being added due to gwt.xml file configuration.
+ Checking/unchecking boxes will add/remove them programatically.
<br/>
<g:CheckBox ui:field='systemCheckbox'> System Handler </g:CheckBox>
<g:CheckBox ui:field='consoleCheckbox'> Console Handler </g:CheckBox>
@@ -13,6 +13,6 @@
<br/>
<g:CheckBox ui:field='firebugCheckbox'> Firebug Handler </g:CheckBox>
<g:CheckBox ui:field='popupCheckbox'> Popup Handler </g:CheckBox>
- <g:CheckBox ui:field='remoteCheckbox'> Remote Handler </g:CheckBox>
+ <g:CheckBox ui:field='remoteCheckbox'> Simple Remote Handler
</g:CheckBox>
</g:HTMLPanel>
</ui:UiBinder>
=======================================
---
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/LogExample.java
Fri Jun 18 13:13:05 2010
+++
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/LogExample.java
Thu Jul 1 14:10:00 2010
@@ -1,12 +1,12 @@
/*
* Copyright 2010 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may
not
* use this file except in compliance with the License. You may obtain a
copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -47,7 +47,7 @@
public void onModuleLoad() {
HTMLPanel p = uiBinder.createAndBindUi(this);
RootPanel.get().add(p);
-
+
loggerControls.setWidget(new LoggerController(
rootLogger, parentLogger, childLogger).getPanel());
handlerControls.setWidget(new
HandlerController(rootLogger).getPanel());
@@ -56,15 +56,16 @@
// This is kind of hacky, but we want the user to see this explanation
// in the popup when the page starts up, so we pull out the popup
handler
- // and publish a message directly to it. Most applications should not
need
- // to do this.
+ // and publish a message directly to it. Most applications should not
+ // do this.
Handler[] handlers = Logger.getLogger("").getHandlers();
- for (Handler h : handlers) {
- if (h instanceof HasWidgetsLogHandler) {
- String msg = "This popup can be resized, moved and minimized";
- h.publish(new LogRecord(Level.SEVERE, msg));
+ if (handlers != null) {
+ for (Handler h : handlers) {
+ if (h instanceof HasWidgetsLogHandler) {
+ String msg = "This popup can be resized, moved and minimized";
+ h.publish(new LogRecord(Level.SEVERE, msg));
+ }
}
}
}
}
-
=======================================
---
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/LoggerController.java
Fri Jun 18 13:13:05 2010
+++
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/LoggerController.java
Thu Jul 1 14:10:00 2010
@@ -1,12 +1,12 @@
/*
* Copyright 2010 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may
not
* use this file except in compliance with the License. You may obtain a
copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -40,11 +40,14 @@
public LoggerController(Logger rootLogger, Logger parentLogger,
Logger childLogger) {
panel = uiBinder.createAndBindUi(this);
- rootControls.setWidget(new OneLoggerController(rootLogger).getPanel());
- parentControls.setWidget(new
OneLoggerController(parentLogger).getPanel());
- childControls.setWidget(new
OneLoggerController(childLogger).getPanel());
- }
-
+ rootControls.setWidget(
+ new OneLoggerController(rootLogger, "Root Logger").getPanel());
+ parentControls.setWidget(
+ new OneLoggerController(parentLogger, "ParentLogger").getPanel());
+ childControls.setWidget(
+ new
OneLoggerController(childLogger, "ParentLogger.Child").getPanel());
+ }
+
public Panel getPanel() {
return panel;
}
=======================================
---
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/OneLoggerController.java
Fri Jun 18 13:13:05 2010
+++
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/OneLoggerController.java
Thu Jul 1 14:10:00 2010
@@ -1,12 +1,12 @@
/*
* Copyright 2010 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may
not
* use this file except in compliance with the License. You may obtain a
copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -43,22 +43,18 @@
private Logger logger;
private Panel panel;
- public OneLoggerController(Logger logger) {
+ public OneLoggerController(Logger logger, String name) {
this.logger = logger;
panel = uiBinder.createAndBindUi(this);
- String name = logger.getName();
- if (name.isEmpty()) {
- name = "RootLogger";
- }
loggerName.setInnerText(name);
addLevelButtons();
addLogButtons();
}
-
+
public Panel getPanel() {
return panel;
}
-
+
@UiHandler("levelTextBox")
void handleClick(ChangeEvent e) {
Level level = Level.parse(levelTextBox.getItemText(
@@ -67,14 +63,24 @@
"Setting level to: " + level.getName());
logger.setLevel(level);
}
-
+
@UiHandler("logButton")
void handleLogClick(ClickEvent e) {
Level level = Level.parse(logTextBox.getItemText(
logTextBox.getSelectedIndex()));
logger.log(level, "This is a client log message");
}
-
+
+ @UiHandler("exceptionButton")
+ void handleExceptionClick(ClickEvent e) {
+ try {
+ Level n = null;
+ n.getName();
+ } catch (NullPointerException ex) {
+ logger.log(Level.SEVERE, "Null Exception Hit", ex);
+ }
+ }
+
private void addLevelButtons() {
levelTextBox.addItem("OFF");
levelTextBox.addItem("SEVERE");
@@ -92,7 +98,7 @@
}
}
}
-
+
private void addLogButtons() {
logTextBox.addItem("SEVERE");
logTextBox.addItem("WARNING");
@@ -108,11 +114,14 @@
}
}
}
-
+
private String getLevel(Logger logger) {
- if (logger.getLevel() != null) {
- return logger.getLevel().getName();
- }
- return getLevel(logger.getParent());
+ if (logger != null) {
+ if (logger.getLevel() != null) {
+ return logger.getLevel().getName();
+ }
+ return getLevel(logger.getParent());
+ }
+ return "";
}
}
=======================================
---
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/OneLoggerController.ui.xml
Fri Jun 18 13:13:05 2010
+++
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/OneLoggerController.ui.xml
Thu Jul 1 14:10:00 2010
@@ -5,10 +5,14 @@
<br/>
Level is:
<g:ListBox ui:field='levelTextBox'/>
- <br/>
+ <br/><br/>
Log a message:
<br/>
<g:ListBox ui:field='logTextBox'/>
<g:Button ui:field='logButton'>Log</g:Button>
+ <br/><br/>
+ <g:Button ui:field='exceptionButton'>
+ Trigger Exception
+ </g:Button>
</g:HTMLPanel>
</ui:UiBinder>
=======================================
---
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/ServerLoggingArea.java
Fri Jun 18 13:13:05 2010
+++
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/ServerLoggingArea.java
Thu Jul 1 14:10:00 2010
@@ -1,12 +1,12 @@
/*
* Copyright 2010 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may
not
* use this file except in compliance with the License. You may obtain a
copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -17,10 +17,10 @@
package com.google.gwt.sample.logexample.client;
import com.google.gwt.core.client.GWT;
+import com.google.gwt.sample.logexample.shared.MyService;
+import com.google.gwt.sample.logexample.shared.MyServiceAsync;
+import com.google.gwt.sample.logexample.shared.SharedClass;
import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.sample.logexample.shared.LoggingService;
-import com.google.gwt.sample.logexample.shared.LoggingServiceAsync;
-import com.google.gwt.sample.logexample.shared.SharedLoggingLibrary;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
@@ -28,8 +28,6 @@
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Panel;
-import java.util.logging.Level;
-
/**
* A section allowing the user to experiment with server side logging and
* shared library logging when it is called from server vs client side
code.
@@ -37,48 +35,45 @@
public class ServerLoggingArea {
interface MyUiBinder extends UiBinder<HTMLPanel, ServerLoggingArea> { }
private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
- private final LoggingServiceAsync loggingService =
- GWT.create(LoggingService.class);
+ private final MyServiceAsync myService =
+ GWT.create(MyService.class);
private Panel panel;
public ServerLoggingArea() {
panel = uiBinder.createAndBindUi(this);
}
-
+
public Panel getPanel() {
return panel;
}
-
- @UiHandler("clientSharedLogButton")
- void handleLogClick(ClickEvent e) {
- SharedLoggingLibrary.logUsingSharedLibrary(Level.SEVERE,
- "Message logged by client side code");
+
+ @UiHandler("clientSharedMethodButton")
+ void handleClientSharedMethodButton(ClickEvent e) {
+ SharedClass.doSomething("client");
}
- @UiHandler("serverSharedLogButton")
- void handleServerHaredLogButton(ClickEvent e) {
- loggingService.logOnServerUsingSharedLibrary(Level.SEVERE.toString(),
- "Message logged by server side code", new AsyncCallback<Void>() {
+ @UiHandler("serverSharedMethodButton")
+ void handleServerSharedMethodButton(ClickEvent e) {
+ myService.doSomethingUsingSharedLibrary(new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
- Window.alert("Logging on server failed");
- }
-
+ Window.alert("Call to my service failed");
+ }
+
public void onSuccess(Void result) {
}
});
}
- @UiHandler("serverLogButton")
- void handleServerLogButton(ClickEvent e) {
- loggingService.logOnServer(Level.SEVERE.toString(), "server log",
- new AsyncCallback<Void>() {
+ @UiHandler("serverMethodButton")
+ void handleServerMethodButton(ClickEvent e) {
+ myService.doSomething(new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
- Window.alert("Logging on server failed");
- }
-
+ Window.alert("Call to my service failed");
+ }
+
public void onSuccess(Void result) {
}
});
=======================================
---
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/ServerLoggingArea.ui.xml
Fri Jun 18 13:13:05 2010
+++
/trunk/samples/logexample/src/com/google/gwt/sample/logexample/client/ServerLoggingArea.ui.xml
Thu Jul 1 14:10:00 2010
@@ -3,21 +3,23 @@
<g:HTMLPanel styleName='oneArea'>
<table><tr><td class='centered'>
GWT logging is configured separately from server side logging.
- Clicking this button will trigger a logging call on the server, which
- will be output by the loggers and handlers which are set up on the
server.
+ Clicking this button will trigger a method on the server, which
+ uses loggers and handlers which are set up on the server.
<br/>
- <g:Button ui:field='serverLogButton'>
- Trigger Server Log
+ <g:Button ui:field='serverMethodButton'>
+ Trigger Server Method
</g:Button>
</td><td class='centered'>
In shared code libraries, the log messages will be handled by the
loggers
- and handlers of the calling code. Clicking these buttons will trigger a
- shared logging library from the server or client code.
+ and handlers of the calling code. Clicking these buttons will trigger
+ methods that call a shared library. The loggers and handlers used by
the
+ shared library is determined by whether the library was called from the
+ server or client code.
<br/>
- <g:Button ui:field='serverSharedLogButton'>
+ <g:Button ui:field='serverSharedMethodButton'>
From Server
</g:Button>
- <g:Button ui:field='clientSharedLogButton'>
+ <g:Button ui:field='clientSharedMethodButton'>
From Client
</g:Button>
</td></tr></table>
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors