]> source.dussan.org Git - vaadin-framework.git/commitdiff
Updated debug window to include "clear" and "restartApplication" buttons.
authorArtur Signell <artur.signell@itmill.com>
Wed, 3 Sep 2008 13:47:24 +0000 (13:47 +0000)
committerArtur Signell <artur.signell@itmill.com>
Wed, 3 Sep 2008 13:47:24 +0000 (13:47 +0000)
Changed debug messages to also go to firebug console if it is available.

svn changeset:5348/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
src/com/itmill/toolkit/terminal/gwt/client/IDebugConsole.java

index 507b3861266ea57063b0bd055ec7cc41b5f647bf..db7202c43f880b2e4dd04ab2038e9c09eed9c83d 100755 (executable)
@@ -107,7 +107,7 @@ public class ApplicationConnection {
         configuration = cnf;
 
         if (isDebugMode()) {
-            console = new IDebugConsole(this, cnf);
+            console = new IDebugConsole(this, cnf, !isQuietDebugMode());
         } else {
             console = new NullConsole();
         }
@@ -221,6 +221,13 @@ public class ApplicationConnection {
      return re.test(uri);
      }-*/;
 
+    private native static boolean isQuietDebugMode()
+    /*-{
+     var uri = $wnd.location;
+     var re = /debug=q[^\/]*$/;
+     return re.test(uri);
+     }-*/;
+
     public String getAppUri() {
         return configuration.getApplicationUri();
     };
@@ -1004,7 +1011,8 @@ public class ApplicationConnection {
         }
 
         public void run() {
-            getConsole().log("Running re-layout");
+            getConsole().log(
+                    "Running re-layout of " + view.getClass().getName());
             Util.runDescendentsLayout(view);
             isPending = false;
         }
index 2005728e3ad768bc0a75cd987cf6ba48f758950a..a9796b98c94ea415c0e719976b7b02eb65bd3761 100755 (executable)
@@ -7,7 +7,9 @@ package com.itmill.toolkit.terminal.gwt.client;
 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.EventListener;
 import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.Button;
 import com.google.gwt.user.client.ui.FlowPanel;
 import com.google.gwt.user.client.ui.HTML;
 import com.google.gwt.user.client.ui.Label;
@@ -16,7 +18,8 @@ import com.google.gwt.user.client.ui.ScrollPanel;
 import com.google.gwt.user.client.ui.Widget;
 import com.itmill.toolkit.terminal.gwt.client.ui.IWindow;
 
-public final class IDebugConsole extends IWindow implements Console {
+public final class IDebugConsole extends IWindow implements Console,
+        EventListener {
 
     /**
      * Builds number. For example 0-custom_tag in 5.0.0-custom_tag.
@@ -33,18 +36,39 @@ public final class IDebugConsole extends IWindow implements Console {
     }
 
     private final Panel panel;
+    private com.google.gwt.dom.client.Element restartApplicationElement;
+    private Element clearButtonElement;
 
     public IDebugConsole(ApplicationConnection client,
-            ApplicationConfiguration cnf) {
+            ApplicationConfiguration cnf, boolean showWindow) {
         super();
+
         this.client = client;
         panel = new FlowPanel();
-        final ScrollPanel p = new ScrollPanel();
-        p.add(panel);
+
+        Element buttonDiv = DOM.createDiv();
+        getContainerElement().appendChild(buttonDiv);
+
+        final ScrollPanel p = new ScrollPanel(panel);
+
+        Button clearButton = new Button("Clear");
+        clearButtonElement = clearButton.getElement();
+
+        Button restartApplicationButton = new Button("Restart application");
+        restartApplicationElement = restartApplicationButton.getElement();
+        buttonDiv.appendChild(clearButtonElement);
+        buttonDiv.appendChild(restartApplicationElement);
+        DOM.sinkEvents(clearButton.getElement(), Event.ONCLICK);
+
         setWidget(p);
         setCaption("Debug window");
-        minimize();
-        show();
+
+        setPixelSize(400, 300);
+        setPopupPosition(Window.getClientWidth() - 400 - 20, 0);
+
+        if (showWindow) {
+            show();
+        }
 
         ;
 
@@ -73,7 +97,15 @@ public final class IDebugConsole extends IWindow implements Console {
     public void log(String msg) {
         panel.add(new HTML(msg));
         System.out.println(msg);
+        logFirebug(msg);
+    }
+
+    private static native void logFirebug(String msg)
+    /*-{
+    if (typeof(console) != "undefined") {
+      console.log(msg);
     }
+    }-*/;
 
     /*
      * (non-Javadoc)
@@ -84,6 +116,7 @@ public final class IDebugConsole extends IWindow implements Console {
     public void error(String msg) {
         panel.add((new HTML(msg)));
         System.out.println(msg);
+        logFirebug(msg);
     }
 
     /*
@@ -95,6 +128,7 @@ public final class IDebugConsole extends IWindow implements Console {
      */
     public void printObject(Object msg) {
         panel.add((new Label(msg.toString())));
+        logFirebug(msg.toString());
     }
 
     /*
@@ -140,4 +174,28 @@ public final class IDebugConsole extends IWindow implements Console {
         DOM.setStyleAttribute(elem, "top", top + "px");
     }
 
+    public void onBrowserEvent(Event event) {
+        super.onBrowserEvent(event);
+
+        final int type = DOM.eventGetType(event);
+        if (type == Event.BUTTON_LEFT) {
+
+            if (event.getTarget() == restartApplicationElement) {
+                String href = Window.Location.getHref();
+                if (Window.Location.getParameter("restartApplication") == null) {
+                    if (href.contains("?")) {
+                        href += "&restartApplication";
+                    } else {
+                        href += "?restartApplication";
+                    }
+
+                    Window.Location.replace(href);
+                } else {
+                    Window.Location.replace(href);
+                }
+            } else if (event.getTarget() == clearButtonElement) {
+                panel.clear();
+            }
+        }
+    }
 }