diff options
author | Leif Åstrand <leif@vaadin.com> | 2013-04-23 13:12:07 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-04-23 13:33:42 +0000 |
commit | 02d6e3ed61139e23a2ba431001d48c48a1aecc61 (patch) | |
tree | a864c12cebc563e80ea230d5d33396af44d5d9c2 | |
parent | 5ea05ab330a3a68f6bd7042e67b8c3bb60c98721 (diff) | |
download | vaadin-framework-02d6e3ed61139e23a2ba431001d48c48a1aecc61.tar.gz vaadin-framework-02d6e3ed61139e23a2ba431001d48c48a1aecc61.zip |
Remove and deprecate old logging classes (#11658)
* VConsole logs directly to java.util.logging.Logger
* ConsoleAdapter is removed and required parts from the interal package
are instead made public
* Exception notification is displayed by a separate log Handler
Change-Id: I64e778b07c53c16872932b48dc99eff0eafd553c
15 files changed, 200 insertions, 1451 deletions
diff --git a/client/src/com/vaadin/Vaadin.gwt.xml b/client/src/com/vaadin/Vaadin.gwt.xml index 7316a77292..a4eb88d9b4 100644 --- a/client/src/com/vaadin/Vaadin.gwt.xml +++ b/client/src/com/vaadin/Vaadin.gwt.xml @@ -30,10 +30,6 @@ <when-type-is class="com.google.gwt.core.client.impl.SchedulerImpl" /> </replace-with> - <replace-with class="com.vaadin.client.debug.internal.ConsoleAdapter"> - <when-type-is class="com.vaadin.client.Console" /> - </replace-with> - <generate-with class="com.vaadin.server.widgetsetutils.AcceptCriteriaFactoryGenerator"> <when-type-is class="com.vaadin.client.ui.dd.VAcceptCriterionFactory" /> diff --git a/client/src/com/vaadin/client/ApplicationConfiguration.java b/client/src/com/vaadin/client/ApplicationConfiguration.java index e6578fa018..e1f460ff48 100644 --- a/client/src/com/vaadin/client/ApplicationConfiguration.java +++ b/client/src/com/vaadin/client/ApplicationConfiguration.java @@ -20,6 +20,9 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.Logger; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; @@ -28,8 +31,15 @@ import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArrayString; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.logging.client.LogConfiguration; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Window; +import com.vaadin.client.debug.internal.ErrorNotificationHandler; +import com.vaadin.client.debug.internal.HierarchySection; +import com.vaadin.client.debug.internal.LogSection; +import com.vaadin.client.debug.internal.NetworkSection; +import com.vaadin.client.debug.internal.Section; +import com.vaadin.client.debug.internal.VDebugWindow; import com.vaadin.client.metadata.BundleLoadCallback; import com.vaadin.client.metadata.ConnectorBundleLoader; import com.vaadin.client.metadata.NoDataException; @@ -568,32 +578,50 @@ public class ApplicationConfiguration implements EntryPoint { enableIOS6castFix(); } - // Prepare VConsole for debugging + // Prepare the debugging window if (isDebugMode()) { - Console console = GWT.create(Console.class); - console.setQuietMode(isQuietDebugMode()); - console.init(); - VConsole.setImplementation(console); - } else { - VConsole.setImplementation((Console) GWT.create(NullConsole.class)); - } - /* - * Display some sort of error of exceptions in web mode to debug - * console. After this, exceptions are reported to VConsole and possible - * GWT hosted mode. - */ - GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { + /* + * XXX Lots of implementation details here right now. This should be + * cleared up when an API for extending the debug window is + * implemented. + */ + VDebugWindow window = GWT.create(VDebugWindow.class); - @Override - public void onUncaughtException(Throwable e) { - /* - * Note in case of null console (without ?debug) we eat - * exceptions. "a1 is not an object" style errors helps nobody, - * especially end user. It does not work tells just as much. - */ - VConsole.getImplementation().error(e); + if (LogConfiguration.loggingIsEnabled()) { + window.addSection((Section) GWT.create(LogSection.class)); } - }); + window.addSection((Section) GWT.create(HierarchySection.class)); + window.addSection((Section) GWT.create(NetworkSection.class)); + + if (isQuietDebugMode()) { + window.close(); + } else { + window.init(); + } + + // Connect to the legacy API + VConsole.setImplementation(window); + + Handler errorNotificationHandler = GWT + .create(ErrorNotificationHandler.class); + Logger.getLogger("").addHandler(errorNotificationHandler); + } + + if (LogConfiguration.loggingIsEnabled()) { + GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { + + @Override + public void onUncaughtException(Throwable e) { + /* + * If the debug window is not enabled (?debug), this will + * not show anything to normal users. "a1 is not an object" + * style errors helps nobody, especially end user. It does + * not work tells just as much. + */ + getLogger().log(Level.SEVERE, e.getMessage(), e); + } + }); + } Profiler.leave("ApplicationConfiguration.onModuleLoad"); if (SuperDevMode.enableBasedOnParameter()) { @@ -701,4 +729,8 @@ public class ApplicationConfiguration implements EntryPoint { widgetsetVersionSent = true; } + private static final Logger getLogger() { + return Logger.getLogger(ApplicationConfiguration.class.getName()); + } + } diff --git a/client/src/com/vaadin/client/Console.java b/client/src/com/vaadin/client/Console.java deleted file mode 100644 index aa8ef2adc5..0000000000 --- a/client/src/com/vaadin/client/Console.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2000-2013 Vaadin Ltd. - * - * 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 - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.vaadin.client; - -import java.util.Set; - -public interface Console { - - public abstract void log(String msg); - - public abstract void log(Throwable e); - - public abstract void error(Throwable e); - - public abstract void error(String msg); - - public abstract void printObject(Object msg); - - public abstract void dirUIDL(ValueMap u, ApplicationConnection client); - - public abstract void printLayoutProblems(ValueMap meta, - ApplicationConnection applicationConnection, - Set<ComponentConnector> zeroHeightComponents, - Set<ComponentConnector> zeroWidthComponents); - - public abstract void setQuietMode(boolean quietDebugMode); - - public abstract void init(); - -}
\ No newline at end of file diff --git a/client/src/com/vaadin/client/NullConsole.java b/client/src/com/vaadin/client/NullConsole.java deleted file mode 100644 index 2b70454b9d..0000000000 --- a/client/src/com/vaadin/client/NullConsole.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2000-2013 Vaadin Ltd. - * - * 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 - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.vaadin.client; - -import java.util.Set; - -import com.google.gwt.core.client.GWT; - -/** - * Client side console implementation for non-debug mode that discards all - * messages. - * - */ -public class NullConsole implements Console { - - @Override - public void dirUIDL(ValueMap u, ApplicationConnection conn) { - } - - @Override - public void error(String msg) { - GWT.log(msg); - } - - @Override - public void log(String msg) { - GWT.log(msg); - } - - @Override - public void printObject(Object msg) { - GWT.log(msg.toString()); - } - - @Override - public void printLayoutProblems(ValueMap meta, - ApplicationConnection applicationConnection, - Set<ComponentConnector> zeroHeightComponents, - Set<ComponentConnector> zeroWidthComponents) { - } - - @Override - public void log(Throwable e) { - GWT.log(e.getMessage(), e); - } - - @Override - public void error(Throwable e) { - GWT.log(e.getMessage(), e); - } - - @Override - public void setQuietMode(boolean quietDebugMode) { - } - - @Override - public void init() { - } - -} diff --git a/client/src/com/vaadin/client/Profiler.java b/client/src/com/vaadin/client/Profiler.java index 6e8f2f5f9a..95b3232723 100644 --- a/client/src/com/vaadin/client/Profiler.java +++ b/client/src/com/vaadin/client/Profiler.java @@ -387,17 +387,12 @@ public class Profiler { StringBuilder stringBuilder = new StringBuilder(); rootNode.buildRecursiveString(stringBuilder, ""); - Console implementation = VConsole.getImplementation(); - if (implementation instanceof VDebugConsole) { - VDebugConsole console = (VDebugConsole) implementation; - SimpleTree tree = (SimpleTree) stack.getFirst().buildTree(); - tree.setText("Profiler data"); - - console.showTree(tree, stringBuilder.toString()); - } else { - VConsole.log(stringBuilder.toString()); - } + /* + * Should really output to a separate section in the debug window, but + * just dump it to the log for now. + */ + VConsole.log(stringBuilder.toString()); Map<String, Node> totals = new HashMap<String, Node>(); rootNode.sumUpTotals(totals); @@ -482,13 +477,11 @@ public class Profiler { return; } - Console implementation = VConsole.getImplementation(); - if (implementation instanceof VDebugConsole) { - VDebugConsole console = (VDebugConsole) implementation; - console.showTree(tree, stringBuilder.toString()); - } else { - VConsole.log(stringBuilder.toString()); - } + /* + * Should really output to a separate section in the debug window, + * but just dump it to the log for now. + */ + VConsole.log(stringBuilder.toString()); } } diff --git a/client/src/com/vaadin/client/SimpleTree.java b/client/src/com/vaadin/client/SimpleTree.java index d4aef4e4f7..5f356fd25b 100644 --- a/client/src/com/vaadin/client/SimpleTree.java +++ b/client/src/com/vaadin/client/SimpleTree.java @@ -30,6 +30,13 @@ import com.google.gwt.user.client.ui.ComplexPanel; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.Widget; +/** + * @author Vaadin Ltd + * + * @deprecated as of 7.1. This class was mainly used by the old debug console + * but is retained for now for backwards compatibility. + */ +@Deprecated public class SimpleTree extends ComplexPanel { private Element children = Document.get().createDivElement().cast(); private SpanElement handle = Document.get().createSpanElement(); diff --git a/client/src/com/vaadin/client/VConsole.java b/client/src/com/vaadin/client/VConsole.java index db19d1a9fd..f7a7554e34 100644 --- a/client/src/com/vaadin/client/VConsole.java +++ b/client/src/com/vaadin/client/VConsole.java @@ -16,91 +16,67 @@ package com.vaadin.client; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; -import com.google.gwt.core.client.GWT; +import com.google.gwt.logging.client.LogConfiguration; +import com.vaadin.client.debug.internal.VDebugWindow; /** * A helper class to do some client side logging. - * <p> - * This class replaces previously used loggin style: - * ApplicationConnection.getConsole().log("foo"). - * <p> - * The default widgetset provides three modes for debugging: - * <ul> - * <li>NullConsole (Default, displays no errors at all) - * <li>VDebugConsole ( Enabled by appending ?debug to url. Displays a floating - * console in the browser and also prints to browsers internal console (builtin - * or Firebug) and GWT's development mode console if available.) - * <li>VDebugConsole in quiet mode (Enabled by appending ?debug=quiet. Same as - * previous but without the console floating over application). - * </ul> - * <p> - * Implementations can be customized with GWT deferred binding by overriding - * NullConsole.class or VDebugConsole.class. This way developer can for example - * build mechanism to send client side logging data to a server. - * <p> - * Note that logging in client side is not fully optimized away even in - * production mode. Use logging moderately in production code to keep the size - * of client side engine small. An exception is {@link GWT#log(String)} style - * logging, which is available only in GWT development mode, but optimized away - * when compiled to web mode. - * - * - * TODO improve javadocs of individual methods * + * @deprecated as of 7.1, use {@link Logger} from java.util.logging instead. */ +@Deprecated public class VConsole { - private static Console impl; + private static VDebugWindow impl; /** * Used by ApplicationConfiguration to initialize VConsole. * * @param console */ - static void setImplementation(Console console) { + static void setImplementation(VDebugWindow console) { impl = console; } - /** - * Used by ApplicationConnection to support deprecated getConsole() api. - */ - static Console getImplementation() { - return impl; - } - public static void log(String msg) { - if (impl != null) { - impl.log(msg); + if (LogConfiguration.loggingIsEnabled(Level.INFO)) { + getLogger().log(Level.INFO, msg); } } public static void log(Throwable e) { - if (impl != null) { - impl.log(e); + if (LogConfiguration.loggingIsEnabled(Level.INFO)) { + getLogger().log(Level.INFO, e.getMessage(), e); } } public static void error(Throwable e) { - if (impl != null) { - impl.error(e); + if (LogConfiguration.loggingIsEnabled(Level.SEVERE)) { + getLogger().log(Level.SEVERE, e.getMessage(), e); } } public static void error(String msg) { - if (impl != null) { - impl.error(msg); + if (LogConfiguration.loggingIsEnabled(Level.SEVERE)) { + getLogger().log(Level.SEVERE, msg); } } public static void printObject(Object msg) { - if (impl != null) { - impl.printObject(msg); + String str; + if (msg == null) { + str = "null"; + } else { + str = msg.toString(); } + log(str); } public static void dirUIDL(ValueMap u, ApplicationConnection client) { if (impl != null) { - impl.dirUIDL(u, client); + impl.uidl(client, u); } } @@ -109,9 +85,12 @@ public class VConsole { Set<ComponentConnector> zeroHeightComponents, Set<ComponentConnector> zeroWidthComponents) { if (impl != null) { - impl.printLayoutProblems(meta, applicationConnection, - zeroHeightComponents, zeroWidthComponents); + impl.meta(applicationConnection, meta); } } + private static Logger getLogger() { + return Logger.getLogger(VConsole.class.getName()); + } + } diff --git a/client/src/com/vaadin/client/VDebugConsole.java b/client/src/com/vaadin/client/VDebugConsole.java deleted file mode 100644 index 025bbb2678..0000000000 --- a/client/src/com/vaadin/client/VDebugConsole.java +++ /dev/null @@ -1,1041 +0,0 @@ -/* - * Copyright 2000-2013 Vaadin Ltd. - * - * 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 - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.vaadin.client; - -import java.util.Collection; -import java.util.Date; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.JsArray; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; -import com.google.gwt.dom.client.Style; -import com.google.gwt.dom.client.Style.FontWeight; -import com.google.gwt.dom.client.Style.Overflow; -import com.google.gwt.dom.client.Style.Position; -import com.google.gwt.dom.client.Style.Unit; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.event.dom.client.KeyCodes; -import com.google.gwt.event.dom.client.MouseOutEvent; -import com.google.gwt.event.dom.client.MouseOutHandler; -import com.google.gwt.event.logical.shared.ValueChangeEvent; -import com.google.gwt.event.logical.shared.ValueChangeHandler; -import com.google.gwt.event.shared.HandlerRegistration; -import com.google.gwt.event.shared.UmbrellaException; -import com.google.gwt.http.client.Request; -import com.google.gwt.http.client.RequestBuilder; -import com.google.gwt.http.client.RequestCallback; -import com.google.gwt.http.client.RequestException; -import com.google.gwt.http.client.Response; -import com.google.gwt.http.client.UrlBuilder; -import com.google.gwt.i18n.client.DateTimeFormat; -import com.google.gwt.storage.client.Storage; -import com.google.gwt.user.client.Cookies; -import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.Element; -import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.Event.NativePreviewEvent; -import com.google.gwt.user.client.Event.NativePreviewHandler; -import com.google.gwt.user.client.EventPreview; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.Window.Location; -import com.google.gwt.user.client.ui.Button; -import com.google.gwt.user.client.ui.CheckBox; -import com.google.gwt.user.client.ui.FlowPanel; -import com.google.gwt.user.client.ui.HTML; -import com.google.gwt.user.client.ui.HorizontalPanel; -import com.google.gwt.user.client.ui.Label; -import com.google.gwt.user.client.ui.Panel; -import com.google.gwt.user.client.ui.RootPanel; -import com.google.gwt.user.client.ui.VerticalPanel; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.client.ui.VLazyExecutor; -import com.vaadin.client.ui.VNotification; -import com.vaadin.client.ui.VOverlay; -import com.vaadin.client.ui.ui.UIConnector; -import com.vaadin.client.ui.window.WindowConnector; -import com.vaadin.shared.Version; - -/** - * A helper console for client side development. The debug console can also be - * used to resolve layout issues, inspect the communication between browser and - * the server, start GWT dev mode and restart application. - * - * <p> - * This implementation is used vaadin is in debug mode (see manual) and - * developer appends "?debug" query parameter to url. Debug information can also - * be shown on browsers internal console only, by appending "?debug=quiet" query - * parameter. - * <p> - * This implementation can be overridden with GWT deferred binding. - * - */ -public class VDebugConsole extends VOverlay implements Console { - - private final class HighlightModeHandler implements NativePreviewHandler { - private final Label label; - - private HighlightModeHandler(Label label) { - this.label = label; - } - - @Override - public void onPreviewNativeEvent(NativePreviewEvent event) { - if (event.getTypeInt() == Event.ONKEYDOWN - && event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) { - highlightModeRegistration.removeHandler(); - VUIDLBrowser.deHiglight(); - return; - } - if (event.getTypeInt() == Event.ONMOUSEMOVE) { - VUIDLBrowser.deHiglight(); - Element eventTarget = Util.getElementFromPoint(event - .getNativeEvent().getClientX(), event.getNativeEvent() - .getClientY()); - if (getElement().isOrHasChild(eventTarget)) { - return; - } - - for (ApplicationConnection a : ApplicationConfiguration - .getRunningApplications()) { - ComponentConnector connector = Util.getConnectorForElement( - a, a.getUIConnector().getWidget(), eventTarget); - if (connector == null) { - connector = Util.getConnectorForElement(a, - RootPanel.get(), eventTarget); - } - if (connector != null) { - String pid = connector.getConnectorId(); - VUIDLBrowser.highlight(connector); - label.setText("Currently focused :" - + connector.getClass() + " ID:" + pid); - event.cancel(); - event.consume(); - event.getNativeEvent().stopPropagation(); - return; - } - } - } - if (event.getTypeInt() == Event.ONCLICK) { - VUIDLBrowser.deHiglight(); - event.cancel(); - event.consume(); - event.getNativeEvent().stopPropagation(); - highlightModeRegistration.removeHandler(); - Element eventTarget = Util.getElementFromPoint(event - .getNativeEvent().getClientX(), event.getNativeEvent() - .getClientY()); - for (ApplicationConnection a : ApplicationConfiguration - .getRunningApplications()) { - ComponentConnector paintable = Util.getConnectorForElement( - a, a.getUIConnector().getWidget(), eventTarget); - if (paintable == null) { - paintable = Util.getConnectorForElement(a, - RootPanel.get(), eventTarget); - } - - if (paintable != null) { - a.highlightConnector(paintable); - return; - } - } - } - event.cancel(); - } - } - - private static final String POS_COOKIE_NAME = "VDebugConsolePos"; - - private HandlerRegistration highlightModeRegistration; - - Element caption = DOM.createDiv(); - - private Panel panel; - - private Button clear = new Button("C"); - private Button restart = new Button("R"); - private Button forceLayout = new Button("FL"); - private Button analyzeLayout = new Button("AL"); - private Button savePosition = new Button("S"); - private Button highlight = new Button("H"); - private Button connectorStats = new Button("CS"); - private CheckBox devMode = new CheckBox("Dev"); - private CheckBox superDevMode = new CheckBox("SDev"); - private CheckBox autoScroll = new CheckBox("Autoscroll "); - private HorizontalPanel actions; - private boolean collapsed = false; - - private boolean resizing; - private int startX; - private int startY; - private int initialW; - private int initialH; - - private boolean moving = false; - - private int origTop; - - private int origLeft; - - private static final String help = "Drag title=move, shift-drag=resize, doubleclick title=min/max." - + "Use debug=quiet to log only to browser console."; - - private static final int DEFAULT_WIDTH = 650; - private static final int DEFAULT_HEIGHT = 400; - - public VDebugConsole() { - super(false, false); - getElement().getStyle().setOverflow(Overflow.HIDDEN); - clear.setTitle("Clear console"); - restart.setTitle("Restart app"); - forceLayout.setTitle("Force layout"); - analyzeLayout.setTitle("Analyze layouts"); - savePosition.setTitle("Save pos"); - } - - private EventPreview dragpreview = new EventPreview() { - - @Override - public boolean onEventPreview(Event event) { - onBrowserEvent(event); - return false; - } - }; - - private boolean quietMode; - - @Override - public void onBrowserEvent(Event event) { - super.onBrowserEvent(event); - switch (DOM.eventGetType(event)) { - case Event.ONMOUSEDOWN: - if (DOM.eventGetShiftKey(event)) { - resizing = true; - DOM.setCapture(getElement()); - startX = DOM.eventGetScreenX(event); - startY = DOM.eventGetScreenY(event); - initialW = VDebugConsole.this.getOffsetWidth(); - initialH = VDebugConsole.this.getOffsetHeight(); - DOM.eventCancelBubble(event, true); - DOM.eventPreventDefault(event); - DOM.addEventPreview(dragpreview); - } else if (DOM.eventGetTarget(event) == caption) { - moving = true; - startX = DOM.eventGetScreenX(event); - startY = DOM.eventGetScreenY(event); - origTop = getAbsoluteTop(); - origLeft = getAbsoluteLeft(); - DOM.eventCancelBubble(event, true); - DOM.eventPreventDefault(event); - DOM.addEventPreview(dragpreview); - } - - break; - case Event.ONMOUSEMOVE: - if (resizing) { - int deltaX = startX - DOM.eventGetScreenX(event); - int detalY = startY - DOM.eventGetScreenY(event); - int w = initialW - deltaX; - if (w < 30) { - w = 30; - } - int h = initialH - detalY; - if (h < 40) { - h = 40; - } - VDebugConsole.this.setPixelSize(w, h); - DOM.eventCancelBubble(event, true); - DOM.eventPreventDefault(event); - } else if (moving) { - int deltaX = startX - DOM.eventGetScreenX(event); - int detalY = startY - DOM.eventGetScreenY(event); - int left = origLeft - deltaX; - if (left < 0) { - left = 0; - } - int top = origTop - detalY; - if (top < 0) { - top = 0; - } - VDebugConsole.this.setPopupPosition(left, top); - DOM.eventCancelBubble(event, true); - DOM.eventPreventDefault(event); - } - break; - case Event.ONLOSECAPTURE: - case Event.ONMOUSEUP: - if (resizing) { - DOM.releaseCapture(getElement()); - resizing = false; - } else if (moving) { - DOM.releaseCapture(getElement()); - moving = false; - } - DOM.removeEventPreview(dragpreview); - break; - case Event.ONDBLCLICK: - if (DOM.eventGetTarget(event) == caption) { - if (collapsed) { - panel.setVisible(true); - setToDefaultSizeAndPos(); - } else { - panel.setVisible(false); - setPixelSize(120, 20); - setPopupPosition(Window.getClientWidth() - 125, - Window.getClientHeight() - 25); - } - collapsed = !collapsed; - } - break; - default: - break; - } - - } - - private void setToDefaultSizeAndPos() { - String cookie = Cookies.getCookie(POS_COOKIE_NAME); - int width, height, top, left; - boolean autoScrollValue = false; - if (cookie != null) { - String[] split = cookie.split(","); - left = Integer.parseInt(split[0]); - top = Integer.parseInt(split[1]); - width = Integer.parseInt(split[2]); - height = Integer.parseInt(split[3]); - autoScrollValue = Boolean.valueOf(split[4]); - } else { - int windowHeight = Window.getClientHeight(); - int windowWidth = Window.getClientWidth(); - width = DEFAULT_WIDTH; - height = DEFAULT_HEIGHT; - - if (height > windowHeight / 2) { - height = windowHeight / 2; - } - if (width > windowWidth / 2) { - width = windowWidth / 2; - } - - top = windowHeight - (height + 10); - left = windowWidth - (width + 10); - } - setPixelSize(width, height); - setPopupPosition(left, top); - autoScroll.setValue(autoScrollValue); - } - - @Override - public void setPixelSize(int width, int height) { - if (height < 20) { - height = 20; - } - if (width < 2) { - width = 2; - } - panel.setHeight((height - 20) + "px"); - panel.setWidth((width - 2) + "px"); - getElement().getStyle().setWidth(width, Unit.PX); - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.client.Console#log(java.lang.String) - */ - @Override - public void log(String msg) { - if (msg == null) { - msg = "null"; - } - msg = addTimestamp(msg); - // remoteLog(msg); - - logToDebugWindow(msg, false); - GWT.log(msg); - consoleLog(msg); - System.out.println(msg); - } - - private List<String> msgQueue = new LinkedList<String>(); - - private ScheduledCommand doSend = new ScheduledCommand() { - @Override - public void execute() { - if (!msgQueue.isEmpty()) { - RequestBuilder requestBuilder = new RequestBuilder( - RequestBuilder.POST, getRemoteLogUrl()); - try { - String requestData = ""; - for (String str : msgQueue) { - requestData += str; - requestData += "\n"; - } - requestBuilder.sendRequest(requestData, - new RequestCallback() { - - @Override - public void onResponseReceived(Request request, - Response response) { - // TODO Auto-generated method stub - - } - - @Override - public void onError(Request request, - Throwable exception) { - // TODO Auto-generated method stub - - } - }); - } catch (RequestException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - msgQueue.clear(); - } - } - - }; - private VLazyExecutor sendToRemoteLog = new VLazyExecutor(350, doSend); - - protected String getRemoteLogUrl() { - return "http://sun-vehje.local:8080/remotelog/"; - } - - protected void remoteLog(String msg) { - msgQueue.add(msg); - sendToRemoteLog.trigger(); - } - - /** - * Logs the given message to the debug window. - * - * @param msg - * The message to log. Must not be null. - */ - private void logToDebugWindow(String msg, boolean error) { - Widget row; - if (error) { - row = createErrorHtml(msg); - } else { - row = new HTML(msg); - } - panel.add(row); - if (autoScroll.getValue()) { - row.getElement().scrollIntoView(); - } - } - - private HTML createErrorHtml(String msg) { - HTML html = new HTML(msg); - html.getElement().getStyle().setColor("#f00"); - html.getElement().getStyle().setFontWeight(FontWeight.BOLD); - return html; - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.client.Console#error(java.lang.String) - */ - @Override - public void error(String msg) { - if (msg == null) { - msg = "null"; - } - msg = addTimestamp(msg); - logToDebugWindow(msg, true); - - GWT.log(msg); - consoleErr(msg); - System.out.println(msg); - - } - - DateTimeFormat timestampFormat = DateTimeFormat.getFormat("HH:mm:ss:SSS"); - - @SuppressWarnings("deprecation") - private String addTimestamp(String msg) { - Date date = new Date(); - String timestamp = timestampFormat.format(date); - return timestamp + " " + msg; - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.client.Console#printObject(java.lang. Object) - */ - @Override - public void printObject(Object msg) { - String str; - if (msg == null) { - str = "null"; - } else { - str = msg.toString(); - } - panel.add((new Label(str))); - consoleLog(str); - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.client.Console#dirUIDL(com.vaadin.client.UIDL) - */ - @Override - public void dirUIDL(ValueMap u, ApplicationConnection client) { - if (panel.isAttached()) { - VUIDLBrowser vuidlBrowser = new VUIDLBrowser(u, client); - vuidlBrowser.setText("Response:"); - panel.add(vuidlBrowser); - } - consoleDir(u); - // consoleLog(u.getChildrenAsXML()); - } - - /** - * Adds a {@link SimpleTree} to the console and prints a string - * representation of the tree structure to the text console. - * - * @param tree - * the simple tree to display in the console window - * @param stringRepresentation - * the string representation of the tree to output to the text - * console - */ - public void showTree(SimpleTree tree, String stringRepresentation) { - if (panel.isAttached()) { - panel.add(tree); - } - consoleLog(stringRepresentation); - } - - private static native void consoleDir(ValueMap u) - /*-{ - if($wnd.console && $wnd.console.log) { - if($wnd.console.dir) { - $wnd.console.dir(u); - } else { - $wnd.console.log(u); - } - } - - }-*/; - - private static native void consoleLog(String msg) - /*-{ - if($wnd.console && $wnd.console.log) { - $wnd.console.log(msg); - } - }-*/; - - private static native void consoleErr(String msg) - /*-{ - if($wnd.console) { - if ($wnd.console.error) - $wnd.console.error(msg); - else if ($wnd.console.log) - $wnd.console.log(msg); - } - }-*/; - - @Override - public void printLayoutProblems(ValueMap meta, ApplicationConnection ac, - Set<ComponentConnector> zeroHeightComponents, - Set<ComponentConnector> zeroWidthComponents) { - JsArray<ValueMap> valueMapArray = meta - .getJSValueMapArray("invalidLayouts"); - int size = valueMapArray.length(); - panel.add(new HTML("<div>************************</div>" - + "<h4>Layouts analyzed on server, total top level problems: " - + size + " </h4>")); - if (size > 0) { - SimpleTree root = new SimpleTree("Root problems"); - - for (int i = 0; i < size; i++) { - printLayoutError(valueMapArray.get(i), root, ac); - } - panel.add(root); - - } - if (zeroHeightComponents.size() > 0 || zeroWidthComponents.size() > 0) { - panel.add(new HTML("<h4> Client side notifications</h4>" - + " <em>The following relative sized components were " - + "rendered to a zero size container on the client side." - + " Note that these are not necessarily invalid " - + "states, but reported here as they might be.</em>")); - if (zeroHeightComponents.size() > 0) { - panel.add(new HTML( - "<p><strong>Vertically zero size:</strong></p>")); - printClientSideDetectedIssues(zeroHeightComponents, ac); - } - if (zeroWidthComponents.size() > 0) { - panel.add(new HTML( - "<p><strong>Horizontally zero size:</strong></p>")); - printClientSideDetectedIssues(zeroWidthComponents, ac); - } - } - log("************************"); - } - - private void printClientSideDetectedIssues( - Set<ComponentConnector> zeroHeightComponents, - ApplicationConnection ac) { - for (final ComponentConnector paintable : zeroHeightComponents) { - final ServerConnector parent = paintable.getParent(); - - VerticalPanel errorDetails = new VerticalPanel(); - errorDetails.add(new Label("" + Util.getSimpleName(paintable) - + " inside " + Util.getSimpleName(parent))); - if (parent instanceof ComponentConnector) { - ComponentConnector parentComponent = (ComponentConnector) parent; - final Widget layout = parentComponent.getWidget(); - - final CheckBox emphasisInUi = new CheckBox( - "Emphasize components parent in UI (the actual component is not visible)"); - emphasisInUi.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - Element element2 = layout.getElement(); - Widget.setStyleName(element2, "invalidlayout", - emphasisInUi.getValue().booleanValue()); - } - }); - - errorDetails.add(emphasisInUi); - } - panel.add(errorDetails); - } - } - - private void printLayoutError(ValueMap valueMap, SimpleTree root, - final ApplicationConnection ac) { - final String pid = valueMap.getString("id"); - final ComponentConnector paintable = (ComponentConnector) ConnectorMap - .get(ac).getConnector(pid); - - SimpleTree errorNode = new SimpleTree(); - VerticalPanel errorDetails = new VerticalPanel(); - errorDetails.add(new Label(Util.getSimpleName(paintable) + " id: " - + pid)); - if (valueMap.containsKey("heightMsg")) { - errorDetails.add(new Label("Height problem: " - + valueMap.getString("heightMsg"))); - } - if (valueMap.containsKey("widthMsg")) { - errorDetails.add(new Label("Width problem: " - + valueMap.getString("widthMsg"))); - } - final CheckBox emphasisInUi = new CheckBox("Emphasize component in UI"); - emphasisInUi.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - if (paintable != null) { - Element element2 = paintable.getWidget().getElement(); - Widget.setStyleName(element2, "invalidlayout", - emphasisInUi.getValue()); - } - } - }); - errorDetails.add(emphasisInUi); - errorNode.add(errorDetails); - if (valueMap.containsKey("subErrors")) { - HTML l = new HTML( - "<em>Expand this node to show problems that may be dependent on this problem.</em>"); - errorDetails.add(l); - JsArray<ValueMap> suberrors = valueMap - .getJSValueMapArray("subErrors"); - for (int i = 0; i < suberrors.length(); i++) { - ValueMap value = suberrors.get(i); - printLayoutError(value, errorNode, ac); - } - - } - root.add(errorNode); - } - - @Override - public void log(Throwable e) { - if (e instanceof UmbrellaException) { - UmbrellaException ue = (UmbrellaException) e; - for (Throwable t : ue.getCauses()) { - log(t); - } - return; - } - log(Util.getSimpleName(e) + ": " + e.getMessage()); - GWT.log(e.getMessage(), e); - } - - @Override - public void error(Throwable e) { - handleError(e, this); - } - - static void handleError(Throwable e, Console target) { - if (e instanceof UmbrellaException) { - UmbrellaException ue = (UmbrellaException) e; - for (Throwable t : ue.getCauses()) { - target.error(t); - } - return; - } - String exceptionText = Util.getSimpleName(e); - String message = e.getMessage(); - if (message != null && message.length() != 0) { - exceptionText += ": " + e.getMessage(); - } - target.error(exceptionText); - GWT.log(e.getMessage(), e); - if (!GWT.isProdMode()) { - e.printStackTrace(); - } - try { - Widget owner = null; - - if (!ApplicationConfiguration.getRunningApplications().isEmpty()) { - // Make a wild guess and use the first available - // ApplicationConnection. This is better than than leaving the - // exception completely unstyled... - ApplicationConnection connection = ApplicationConfiguration - .getRunningApplications().get(0); - owner = connection.getUIConnector().getWidget(); - } - VNotification - .createNotification(VNotification.DELAY_FOREVER, owner) - .show("<h1>Uncaught client side exception</h1><br />" - + exceptionText, VNotification.CENTERED, "error"); - } catch (Exception e2) { - // Just swallow this exception - } - } - - @Override - public void init() { - panel = new FlowPanel(); - if (!quietMode) { - DOM.appendChild(getContainerElement(), caption); - setWidget(panel); - caption.setClassName("v-debug-console-caption"); - setStyleName("v-debug-console"); - getElement().getStyle().setZIndex(20000); - getElement().getStyle().setOverflow(Overflow.HIDDEN); - - sinkEvents(Event.ONDBLCLICK); - - sinkEvents(Event.MOUSEEVENTS); - - panel.setStyleName("v-debug-console-content"); - - caption.setInnerHTML("Debug window"); - caption.getStyle().setHeight(25, Unit.PX); - caption.setTitle(help); - - show(); - setToDefaultSizeAndPos(); - - actions = new HorizontalPanel(); - Style style = actions.getElement().getStyle(); - style.setPosition(Position.ABSOLUTE); - style.setBackgroundColor("#666"); - style.setLeft(135, Unit.PX); - style.setHeight(25, Unit.PX); - style.setTop(0, Unit.PX); - - actions.add(clear); - actions.add(restart); - actions.add(forceLayout); - actions.add(analyzeLayout); - actions.add(highlight); - actions.add(connectorStats); - connectorStats.setTitle("Show connector statistics for client"); - highlight - .setTitle("Select a component and print details about it to the server log and client side console."); - actions.add(savePosition); - savePosition - .setTitle("Saves the position and size of debug console to a cookie"); - actions.add(autoScroll); - addDevMode(); - addSuperDevMode(); - - autoScroll - .setTitle("Automatically scroll so that new messages are visible"); - - panel.add(actions); - - panel.add(new HTML("<i>" + help + "</i>")); - - clear.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - int width = panel.getOffsetWidth(); - int height = panel.getOffsetHeight(); - panel = new FlowPanel(); - panel.setPixelSize(width, height); - panel.setStyleName("v-debug-console-content"); - panel.add(actions); - setWidget(panel); - } - }); - - restart.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - - String queryString = Window.Location.getQueryString(); - if (queryString != null - && queryString.contains("restartApplications")) { - Window.Location.reload(); - } else { - String url = Location.getHref(); - String separator = "?"; - if (url.contains("?")) { - separator = "&"; - } - if (!url.contains("restartApplication")) { - url += separator; - url += "restartApplication"; - } - if (!"".equals(Location.getHash())) { - String hash = Location.getHash(); - url = url.replace(hash, "") + hash; - } - Window.Location.replace(url); - } - - } - }); - - forceLayout.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - for (ApplicationConnection applicationConnection : ApplicationConfiguration - .getRunningApplications()) { - applicationConnection.forceLayout(); - } - } - }); - - analyzeLayout.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - List<ApplicationConnection> runningApplications = ApplicationConfiguration - .getRunningApplications(); - for (ApplicationConnection applicationConnection : runningApplications) { - applicationConnection.analyzeLayouts(); - } - } - }); - analyzeLayout - .setTitle("Analyzes currently rendered view and " - + "reports possible common problems in usage of relative sizes." - + "Will cause server visit/rendering of whole screen and loss of" - + " all non committed variables form client side."); - - savePosition.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - String pos = getAbsoluteLeft() + "," + getAbsoluteTop() - + "," + getOffsetWidth() + "," + getOffsetHeight() - + "," + autoScroll.getValue(); - Cookies.setCookie(POS_COOKIE_NAME, pos); - } - }); - - highlight.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - final Label label = new Label("--"); - log("<i>Use mouse to select a component or click ESC to exit highlight mode.</i>"); - panel.add(label); - highlightModeRegistration = Event - .addNativePreviewHandler(new HighlightModeHandler( - label)); - - } - }); - - } - connectorStats.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - for (ApplicationConnection a : ApplicationConfiguration - .getRunningApplications()) { - dumpConnectorInfo(a); - } - } - }); - log("Starting Vaadin client side engine. Widgetset: " - + GWT.getModuleName()); - - log("Widget set is built on version: " + Version.getFullVersion()); - - logToDebugWindow("<div class=\"v-theme-version v-theme-version-" - + Version.getFullVersion().replaceAll("\\.", "_") - + "\">Warning: widgetset version " + Version.getFullVersion() - + " does not seem to match theme version </div>", true); - - } - - private void addSuperDevMode() { - final Storage sessionStorage = Storage.getSessionStorageIfSupported(); - if (sessionStorage == null) { - return; - } - actions.add(superDevMode); - if (Location.getParameter("superdevmode") != null) { - superDevMode.setValue(true); - } - superDevMode.addValueChangeHandler(new ValueChangeHandler<Boolean>() { - - @Override - public void onValueChange(ValueChangeEvent<Boolean> event) { - SuperDevMode.redirect(event.getValue()); - } - - }); - - } - - private void addDevMode() { - actions.add(devMode); - if (Location.getParameter("gwt.codesvr") != null) { - devMode.setValue(true); - } - devMode.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - if (devMode.getValue()) { - addHMParameter(); - } else { - removeHMParameter(); - } - } - - private void addHMParameter() { - UrlBuilder createUrlBuilder = Location.createUrlBuilder(); - createUrlBuilder.setParameter("gwt.codesvr", "localhost:9997"); - Location.assign(createUrlBuilder.buildString()); - } - - private void removeHMParameter() { - UrlBuilder createUrlBuilder = Location.createUrlBuilder(); - createUrlBuilder.removeParameter("gwt.codesvr"); - Location.assign(createUrlBuilder.buildString()); - - } - }); - } - - protected void dumpConnectorInfo(ApplicationConnection a) { - UIConnector root = a.getUIConnector(); - log("================"); - log("Connector hierarchy for Root: " + root.getState().caption + " (" - + root.getConnectorId() + ")"); - Set<ServerConnector> connectorsInHierarchy = new HashSet<ServerConnector>(); - SimpleTree rootHierachy = dumpConnectorHierarchy(root, "", - connectorsInHierarchy); - if (panel.isAttached()) { - rootHierachy.open(true); - panel.add(rootHierachy); - } - - ConnectorMap connectorMap = a.getConnectorMap(); - Collection<? extends ServerConnector> registeredConnectors = connectorMap - .getConnectors(); - log("Sub windows:"); - Set<ServerConnector> subWindowHierarchyConnectors = new HashSet<ServerConnector>(); - for (WindowConnector wc : root.getSubWindows()) { - SimpleTree windowHierachy = dumpConnectorHierarchy(wc, "", - subWindowHierarchyConnectors); - if (panel.isAttached()) { - windowHierachy.open(true); - panel.add(windowHierachy); - } - } - log("Registered connectors not in hierarchy (should be empty):"); - for (ServerConnector registeredConnector : registeredConnectors) { - - if (connectorsInHierarchy.contains(registeredConnector)) { - continue; - } - - if (subWindowHierarchyConnectors.contains(registeredConnector)) { - continue; - } - error(getConnectorString(registeredConnector)); - - } - log("Unregistered connectors in hierarchy (should be empty):"); - for (ServerConnector hierarchyConnector : connectorsInHierarchy) { - if (!connectorMap.hasConnector(hierarchyConnector.getConnectorId())) { - error(getConnectorString(hierarchyConnector)); - } - - } - - log("================"); - - } - - private SimpleTree dumpConnectorHierarchy(final ServerConnector connector, - String indent, Set<ServerConnector> connectors) { - SimpleTree simpleTree = new SimpleTree(getConnectorString(connector)) { - @Override - protected void select(ClickEvent event) { - super.select(event); - if (connector instanceof ComponentConnector) { - VUIDLBrowser.highlight((ComponentConnector) connector); - } - } - }; - simpleTree.addDomHandler(new MouseOutHandler() { - @Override - public void onMouseOut(MouseOutEvent event) { - VUIDLBrowser.deHiglight(); - } - }, MouseOutEvent.getType()); - connectors.add(connector); - - String msg = indent + "* " + getConnectorString(connector); - GWT.log(msg); - consoleLog(msg); - System.out.println(msg); - - for (ServerConnector c : connector.getChildren()) { - simpleTree.add(dumpConnectorHierarchy(c, indent + " ", connectors)); - } - return simpleTree; - } - - private static String getConnectorString(ServerConnector connector) { - return Util.getConnectorString(connector); - } - - @Override - public void setQuietMode(boolean quietDebugMode) { - quietMode = quietDebugMode; - } -} diff --git a/client/src/com/vaadin/client/VUIDLBrowser.java b/client/src/com/vaadin/client/VUIDLBrowser.java index fded37ec5c..e6f38fb167 100644 --- a/client/src/com/vaadin/client/VUIDLBrowser.java +++ b/client/src/com/vaadin/client/VUIDLBrowser.java @@ -42,8 +42,12 @@ import com.vaadin.client.ui.UnknownComponentConnector; import com.vaadin.client.ui.VWindow; /** - * TODO Rename to something more Vaadin7-ish? + * @author Vaadin Ltd + * + * @deprecated as of 7.1. This class was mainly used by the old debug console + * but is retained for now for backwards compatibility. */ +@Deprecated public class VUIDLBrowser extends SimpleTree { private static final String HELP = "Shift click handle to open recursively. " + " Click components to highlight them on client side." diff --git a/client/src/com/vaadin/client/debug/internal/ConsoleAdapter.java b/client/src/com/vaadin/client/debug/internal/ConsoleAdapter.java deleted file mode 100644 index 9397e27906..0000000000 --- a/client/src/com/vaadin/client/debug/internal/ConsoleAdapter.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright 2000-2013 Vaadin Ltd. - * - * 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 - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.client.debug.internal; - -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; - -import com.google.gwt.core.shared.GWT; -import com.google.gwt.event.shared.UmbrellaException; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.client.ApplicationConfiguration; -import com.vaadin.client.ApplicationConnection; -import com.vaadin.client.ComponentConnector; -import com.vaadin.client.Console; -import com.vaadin.client.Util; -import com.vaadin.client.ValueMap; -import com.vaadin.client.ui.VNotification; - -/** - * Internal API, do not use. Implements the 'old' Console API and passes the - * messages to the new debug window. - * <p> - * <em>WILL BE CHANGED/REMOVED.</em> - * </p> - * - * @since 7.1 - * @author Vaadin Ltd - */ -public class ConsoleAdapter implements Console { - - static VDebugWindow window = GWT.create(VDebugWindow.class); - - static { - window.addSection((Section) GWT.create(LogSection.class)); - window.addSection((Section) GWT.create(HierarchySection.class)); - window.addSection((Section) GWT.create(NetworkSection.class)); - - } - - @Override - public void log(String msg) { - getLogger().log(Level.INFO, msg); - } - - @Override - public void log(Throwable e) { - if (e instanceof UmbrellaException) { - UmbrellaException ue = (UmbrellaException) e; - for (Throwable t : ue.getCauses()) { - log(t); - } - return; - } - log(Util.getSimpleName(e) + ": " + e.getMessage()); - GWT.log(e.getMessage(), e); - } - - @Override - public void error(Throwable e) { - handleError(e, this); - } - - @Override - public void error(String msg) { - if (msg == null) { - msg = "null"; - } - - getLogger().log(Level.SEVERE, msg); - } - - @Override - public void printObject(Object msg) { - String str; - if (msg == null) { - str = "null"; - } else { - str = msg.toString(); - } - log(str); - consoleLog(str); - } - - @Override - public void dirUIDL(ValueMap u, ApplicationConnection client) { - window.uidl(client, u); - } - - @Override - public void printLayoutProblems(ValueMap meta, - ApplicationConnection applicationConnection, - Set<ComponentConnector> zeroHeightComponents, - Set<ComponentConnector> zeroWidthComponents) { - - window.meta(applicationConnection, meta); - } - - private boolean quietMode = false; - - @Override - public void setQuietMode(boolean quietMode) { - this.quietMode = quietMode; - if (quietMode) { - window.close(); - } else { - // NOP can't switch ATM - } - } - - @Override - public void init() { - if (!quietMode) { - window.init(); - } - } - - static void handleError(Throwable e, Console target) { - if (e instanceof UmbrellaException) { - UmbrellaException ue = (UmbrellaException) e; - for (Throwable t : ue.getCauses()) { - target.error(t); - } - return; - } - String exceptionText = Util.getSimpleName(e); - String message = e.getMessage(); - if (message != null && message.length() != 0) { - exceptionText += ": " + e.getMessage(); - } - target.error(exceptionText); - GWT.log(e.getMessage(), e); - if (!GWT.isProdMode()) { - e.printStackTrace(); - } - try { - Widget owner = null; - - if (!ApplicationConfiguration.getRunningApplications().isEmpty()) { - // Make a wild guess and use the first available - // ApplicationConnection. This is better than than leaving the - // exception completely unstyled... - ApplicationConnection connection = ApplicationConfiguration - .getRunningApplications().get(0); - owner = connection.getUIConnector().getWidget(); - } - VNotification - .createNotification(VNotification.DELAY_FOREVER, owner) - .show("<h1>Uncaught client side exception</h1><br />" - + exceptionText, VNotification.CENTERED, "error"); - } catch (Exception e2) { - // Just swallow this exception - } - } - - private static native void consoleLog(String msg) - /*-{ - if($wnd.console && $wnd.console.log) { - $wnd.console.log(msg); - } - }-*/; - - private static native void consoleErr(String msg) - /*-{ - if($wnd.console) { - if ($wnd.console.error) - $wnd.console.error(msg); - else if ($wnd.console.log) - $wnd.console.log(msg); - } - }-*/; - - private static Logger getLogger() { - return Logger.getLogger(ConsoleAdapter.class.getName()); - } -} diff --git a/client/src/com/vaadin/client/debug/internal/ErrorNotificationHandler.java b/client/src/com/vaadin/client/debug/internal/ErrorNotificationHandler.java new file mode 100644 index 0000000000..0e4c57494b --- /dev/null +++ b/client/src/com/vaadin/client/debug/internal/ErrorNotificationHandler.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * 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 + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.client.debug.internal; + +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; + +import com.google.gwt.logging.client.TextLogFormatter; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.client.ApplicationConfiguration; +import com.vaadin.client.ApplicationConnection; +import com.vaadin.client.ui.VNotification; + +/** + * Log message handler that shows big red notification for {@link Level#SEVERE} + * messages that have a throwable. + * + * @since 7.1 + * @author Vaadin Ltd + */ +public class ErrorNotificationHandler extends Handler { + public ErrorNotificationHandler() { + setLevel(Level.SEVERE); + setFormatter(new TextLogFormatter(true) { + @Override + protected String getRecordInfo(LogRecord event, String newline) { + return ""; + } + }); + } + + @Override + public void publish(LogRecord record) { + if (!isLoggable(record) || record.getThrown() == null) { + return; + } + + try { + String exceptionText = getFormatter().format(record); + + Widget owner = null; + + if (!ApplicationConfiguration.getRunningApplications().isEmpty()) { + /* + * Make a wild guess and use the first available + * ApplicationConnection. This is better than than leaving the + * exception completely unstyled... + */ + ApplicationConnection connection = ApplicationConfiguration + .getRunningApplications().get(0); + owner = connection.getUIConnector().getWidget(); + } + VNotification + .createNotification(VNotification.DELAY_FOREVER, owner) + .show("<h1>Uncaught client side exception</h1><br />" + + exceptionText, VNotification.CENTERED, "error"); + } catch (Exception e2) { + // Just swallow this exception + } + } + + @Override + public void close() { + // Nothing to do + } + + @Override + public void flush() { + // Nothing todo + } +}
\ No newline at end of file diff --git a/client/src/com/vaadin/client/debug/internal/HierarchySection.java b/client/src/com/vaadin/client/debug/internal/HierarchySection.java index b09038cf97..fad0110ed5 100644 --- a/client/src/com/vaadin/client/debug/internal/HierarchySection.java +++ b/client/src/com/vaadin/client/debug/internal/HierarchySection.java @@ -64,7 +64,7 @@ import com.vaadin.shared.AbstractComponentState; * @since 7.1 * @author Vaadin Ltd */ -class HierarchySection implements Section { +public class HierarchySection implements Section { /** * Shared state properties that have hardcoded support in diff --git a/client/src/com/vaadin/client/debug/internal/LogSection.java b/client/src/com/vaadin/client/debug/internal/LogSection.java index 105ef55c32..74ac3641c2 100644 --- a/client/src/com/vaadin/client/debug/internal/LogSection.java +++ b/client/src/com/vaadin/client/debug/internal/LogSection.java @@ -44,7 +44,7 @@ import com.vaadin.client.ValueMap; * @since 7.1 * @author Vaadin Ltd */ -class LogSection implements Section { +public class LogSection implements Section { private final class LogSectionHandler extends Handler { private LogSectionHandler() { diff --git a/client/src/com/vaadin/client/debug/internal/VDebugWindow.java b/client/src/com/vaadin/client/debug/internal/VDebugWindow.java index a7e22420b7..5aab95616a 100644 --- a/client/src/com/vaadin/client/debug/internal/VDebugWindow.java +++ b/client/src/com/vaadin/client/debug/internal/VDebugWindow.java @@ -245,7 +245,7 @@ public final class VDebugWindow extends VOverlay { /** * Closes the window and stops visual logging. */ - void close() { + public void close() { // TODO disable even more if (resizeReg != null) { resizeReg.removeHandler(); @@ -499,7 +499,7 @@ public final class VDebugWindow extends VOverlay { * * @param section */ - void addSection(final Section section) { + public void addSection(final Section section) { Button b = section.getTabButton(); b.addClickHandler(new ClickHandler() { @Override @@ -661,7 +661,7 @@ public final class VDebugWindow extends VOverlay { /** * Called when the window is initialized. */ - void init() { + public void init() { show(); readStoredState(); @@ -690,7 +690,7 @@ public final class VDebugWindow extends VOverlay { * @param ac * @param meta */ - void meta(ApplicationConnection ac, ValueMap meta) { + public void meta(ApplicationConnection ac, ValueMap meta) { if (isClosed()) { return; } @@ -705,7 +705,7 @@ public final class VDebugWindow extends VOverlay { * @param ac * @param uidl */ - void uidl(ApplicationConnection ac, ValueMap uidl) { + public void uidl(ApplicationConnection ac, ValueMap uidl) { if (isClosed()) { return; } diff --git a/client/src/com/vaadin/client/ui/VWindow.java b/client/src/com/vaadin/client/ui/VWindow.java index 138a7f7adc..084ce522c1 100644 --- a/client/src/com/vaadin/client/ui/VWindow.java +++ b/client/src/com/vaadin/client/ui/VWindow.java @@ -43,10 +43,10 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.BrowserInfo; import com.vaadin.client.ConnectorMap; -import com.vaadin.client.Console; import com.vaadin.client.Focusable; import com.vaadin.client.LayoutManager; import com.vaadin.client.Util; +import com.vaadin.client.debug.internal.VDebugWindow; import com.vaadin.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner; import com.vaadin.shared.EventId; import com.vaadin.shared.ui.window.WindowMode; @@ -931,7 +931,7 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, // debug window Widget w = Util.findWidget(target, null); while (w != null) { - if (w instanceof Console) { + if (w instanceof VDebugWindow) { return true; // allow debug-window clicks } else if (ConnectorMap.get(client).isConnector(w)) { return false; |