]> source.dussan.org Git - vaadin-framework.git/commitdiff
Send connector debug (highlight) using RPC (#11536)
authorArtur Signell <artur@vaadin.com>
Tue, 4 Jun 2013 19:29:26 +0000 (22:29 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 5 Jun 2013 09:19:10 +0000 (09:19 +0000)
Change-Id: I8995e9affd371543457f16568f1245f7467e0804

client/src/com/vaadin/client/ApplicationConnection.java
client/src/com/vaadin/client/ui/ui/UIConnector.java
server/src/com/vaadin/server/communication/MetadataWriter.java
server/src/com/vaadin/server/communication/UidlRequestHandler.java
server/src/com/vaadin/server/communication/UidlWriter.java
server/src/com/vaadin/ui/UI.java
server/src/com/vaadin/util/ConnectorHelper.java [new file with mode: 0644]
shared/src/com/vaadin/shared/ApplicationConstants.java
shared/src/com/vaadin/shared/ui/ui/DebugWindowServerRpc.java [new file with mode: 0644]

index 2f5401a75baba83efa8baf3ee2216b2ee0bc2784..4dd68cc24fdf1539f3bc9546fbadff9862259284 100644 (file)
@@ -691,12 +691,12 @@ public class ApplicationConnection {
      * source code.
      * 
      * @param serverConnector
+     * @deprecated as of 7.1. Replaced by
+     *             {@link UIConnector#showServerDebugInfo(ServerConnector)}
      */
+    @Deprecated
     void highlightConnector(ServerConnector serverConnector) {
-        String params = getRepaintAllParameters() + "&"
-                + ApplicationConstants.PARAM_HIGHLIGHT_CONNECTOR + "="
-                + serverConnector.getConnectorId();
-        makeUidlRequest("", params);
+        getUIConnector().showServerDebugInfo(serverConnector);
     }
 
     /**
index bba9252d47006d77d18b0445787fa66c8435de94..38c26a77e668cf40c857ca423ea8f6531185c202 100644 (file)
@@ -50,6 +50,7 @@ import com.vaadin.client.ConnectorHierarchyChangeEvent;
 import com.vaadin.client.ConnectorMap;
 import com.vaadin.client.Focusable;
 import com.vaadin.client.Paintable;
+import com.vaadin.client.ServerConnector;
 import com.vaadin.client.UIDL;
 import com.vaadin.client.VConsole;
 import com.vaadin.client.communication.StateChangeEvent;
@@ -68,6 +69,7 @@ import com.vaadin.shared.communication.MethodInvocation;
 import com.vaadin.shared.ui.ComponentStateUtil;
 import com.vaadin.shared.ui.Connect;
 import com.vaadin.shared.ui.Connect.LoadStyle;
+import com.vaadin.shared.ui.ui.DebugWindowServerRpc;
 import com.vaadin.shared.ui.ui.PageClientRpc;
 import com.vaadin.shared.ui.ui.PageState;
 import com.vaadin.shared.ui.ui.ScrollClientRpc;
@@ -659,4 +661,18 @@ public class UIConnector extends AbstractSingleComponentContainerConnector
                             .getName(), "poll"));
         }
     }
+
+    /**
+     * Sends a request to the server to print details to console that will help
+     * the developer to locate the corresponding server-side connector in the
+     * source code.
+     * 
+     * @since 7.1
+     * @param serverConnector
+     *            the connector to locate
+     */
+    public void showServerDebugInfo(ServerConnector serverConnector) {
+        getRpcProxy(DebugWindowServerRpc.class).showServerDebugInfo(
+                serverConnector);
+    }
 }
index 1a3f0e946a14a20b08fa117a6347c8c670d6772c..9993ef1e44579f9b2618a3a94be9a8ae2faa5444 100644 (file)
@@ -22,7 +22,6 @@ import java.io.Serializable;
 import java.io.Writer;
 import java.util.List;
 
-import com.vaadin.server.ClientConnector;
 import com.vaadin.server.ComponentSizeValidator;
 import com.vaadin.server.ComponentSizeValidator.InvalidLayout;
 import com.vaadin.server.SystemMessages;
@@ -54,9 +53,6 @@ public class MetadataWriter implements Serializable {
      * @param async
      *            True if this message is sent by the server asynchronously,
      *            false if it is a response to a client message.
-     * @param hilightedConnector
-     *            The connector that should be highlighted on the client or null
-     *            if none.
      * @param messages
      *            a {@link SystemMessages} containing client-side error
      *            messages.
@@ -65,8 +61,7 @@ public class MetadataWriter implements Serializable {
      * 
      */
     public void write(UI ui, Writer writer, boolean repaintAll,
-            boolean analyzeLayouts, boolean async,
-            ClientConnector hilightedConnector, SystemMessages messages)
+            boolean analyzeLayouts, boolean async, SystemMessages messages)
             throws IOException {
 
         List<InvalidLayout> invalidComponentRelativeSizes = null;
@@ -109,11 +104,6 @@ public class MetadataWriter implements Serializable {
                 }
                 writer.write("]");
             }
-            if (hilightedConnector != null) {
-                writer.write(", \"hl\":\"");
-                writer.write(hilightedConnector.getConnectorId());
-                writer.write("\"");
-            }
         }
 
         if (async) {
index 73ff92f8bde0572565f31753b232bb0f10a9a180..55fb473998d99e5880f0413c3bbe726ba84bf913 100644 (file)
@@ -19,13 +19,11 @@ package com.vaadin.server.communication;
 import java.io.IOException;
 import java.io.StringWriter;
 import java.io.Writer;
-import java.util.LinkedList;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.json.JSONException;
 
-import com.vaadin.server.ClientConnector;
 import com.vaadin.server.Constants;
 import com.vaadin.server.LegacyCommunicationManager.InvalidUIDLSecurityKeyException;
 import com.vaadin.server.ServletPortletHelper;
@@ -39,7 +37,6 @@ import com.vaadin.server.VaadinSession;
 import com.vaadin.shared.ApplicationConstants;
 import com.vaadin.shared.JsonConstants;
 import com.vaadin.shared.Version;
-import com.vaadin.ui.Component;
 import com.vaadin.ui.UI;
 
 /**
@@ -79,11 +76,10 @@ public class UidlRequestHandler extends SynchronizedRequestHandler implements
 
         checkWidgetsetVersion(request);
         String requestThemeName = request.getParameter("theme");
-        ClientConnector highlightedConnector;
         // repaint requested or session has timed out and new one is created
         boolean repaintAll;
 
-        // TODO PUSH repaintAll, analyzeLayouts, highlightConnector should be
+        // TODO PUSH repaintAll, analyzeLayouts should be
         // part of the message payload to make the functionality transport
         // agnostic
 
@@ -95,14 +91,6 @@ public class UidlRequestHandler extends SynchronizedRequestHandler implements
             // analyzing can be done only with repaintAll
             analyzeLayouts = (request
                     .getParameter(ApplicationConstants.PARAM_ANALYZE_LAYOUTS) != null);
-
-            String pid = request
-                    .getParameter(ApplicationConstants.PARAM_HIGHLIGHT_CONNECTOR);
-            if (pid != null) {
-                highlightedConnector = uI.getConnectorTracker().getConnector(
-                        pid);
-                highlightConnector(highlightedConnector);
-            }
         }
 
         StringWriter stringWriter = new StringWriter();
@@ -190,63 +178,6 @@ public class UidlRequestHandler extends SynchronizedRequestHandler implements
         outWriter.write("for(;;);[{");
     }
 
-    // TODO Does this belong here?
-    protected void highlightConnector(ClientConnector highlightedConnector) {
-        StringBuilder sb = new StringBuilder();
-        sb.append("*** Debug details of a connector:  *** \n");
-        sb.append("Type: ");
-        sb.append(highlightedConnector.getClass().getName());
-        sb.append("\nId:");
-        sb.append(highlightedConnector.getConnectorId());
-        if (highlightedConnector instanceof Component) {
-            Component component = (Component) highlightedConnector;
-            if (component.getCaption() != null) {
-                sb.append("\nCaption:");
-                sb.append(component.getCaption());
-            }
-        }
-        printHighlightedConnectorHierarchy(sb, highlightedConnector);
-        getLogger().info(sb.toString());
-    }
-
-    // TODO Does this belong here?
-    protected void printHighlightedConnectorHierarchy(StringBuilder sb,
-            ClientConnector connector) {
-        LinkedList<ClientConnector> h = new LinkedList<ClientConnector>();
-        h.add(connector);
-        ClientConnector parent = connector.getParent();
-        while (parent != null) {
-            h.addFirst(parent);
-            parent = parent.getParent();
-        }
-
-        sb.append("\nConnector hierarchy:\n");
-        VaadinSession session2 = connector.getUI().getSession();
-        sb.append(session2.getClass().getName());
-        sb.append("(");
-        sb.append(session2.getClass().getSimpleName());
-        sb.append(".java");
-        sb.append(":1)");
-        int l = 1;
-        for (ClientConnector connector2 : h) {
-            sb.append("\n");
-            for (int i = 0; i < l; i++) {
-                sb.append("  ");
-            }
-            l++;
-            Class<? extends ClientConnector> connectorClass = connector2
-                    .getClass();
-            Class<?> topClass = connectorClass;
-            while (topClass.getEnclosingClass() != null) {
-                topClass = topClass.getEnclosingClass();
-            }
-            sb.append(connectorClass.getName());
-            sb.append("(");
-            sb.append(topClass.getSimpleName());
-            sb.append(".java:1)");
-        }
-    }
-
     private static final Logger getLogger() {
         return Logger.getLogger(UidlRequestHandler.class.getName());
     }
index 9c736d8dd9da98df933cd990cd3b1ddc4d2a8a8d..a915501056fc734e9eec585e27149d459039c419 100644 (file)
@@ -162,7 +162,7 @@ public class UidlWriter implements Serializable {
                     .getSystemMessages(ui.getLocale(), null);
             // TODO hilightedConnector
             new MetadataWriter().write(ui, writer, repaintAll, analyzeLayouts,
-                    async, null, messages);
+                    async, messages);
             writer.write(", ");
 
             writer.write("\"resources\" : ");
index d4ac156787af969a0f8ddae4e17aeca529d75a3d..3194786431fec786d7fe97a190fd835237304e02 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.concurrent.Future;
+import java.util.logging.Logger;
 
 import com.vaadin.event.Action;
 import com.vaadin.event.Action.Handler;
@@ -30,6 +31,7 @@ import com.vaadin.event.ActionManager;
 import com.vaadin.event.MouseEvents.ClickEvent;
 import com.vaadin.event.MouseEvents.ClickListener;
 import com.vaadin.navigator.Navigator;
+import com.vaadin.server.ClientConnector;
 import com.vaadin.server.LocaleService;
 import com.vaadin.server.Page;
 import com.vaadin.server.PaintException;
@@ -40,15 +42,18 @@ import com.vaadin.server.VaadinService;
 import com.vaadin.server.VaadinServlet;
 import com.vaadin.server.VaadinSession;
 import com.vaadin.server.communication.PushConnection;
+import com.vaadin.shared.Connector;
 import com.vaadin.shared.EventId;
 import com.vaadin.shared.MouseEventDetails;
 import com.vaadin.shared.communication.PushMode;
+import com.vaadin.shared.ui.ui.DebugWindowServerRpc;
 import com.vaadin.shared.ui.ui.ScrollClientRpc;
 import com.vaadin.shared.ui.ui.UIClientRpc;
 import com.vaadin.shared.ui.ui.UIConstants;
 import com.vaadin.shared.ui.ui.UIServerRpc;
 import com.vaadin.shared.ui.ui.UIState;
 import com.vaadin.ui.Component.Focusable;
+import com.vaadin.util.ConnectorHelper;
 import com.vaadin.util.CurrentInstance;
 
 /**
@@ -161,6 +166,14 @@ public abstract class UI extends AbstractSingleComponentContainer implements
              */
         }
     };
+    private DebugWindowServerRpc debugRpc = new DebugWindowServerRpc() {
+        @Override
+        public void showServerDebugInfo(Connector connector) {
+            String info = ConnectorHelper
+                    .getDebugInformation((ClientConnector) connector);
+            getLogger().info(info);
+        }
+    };
 
     /**
      * Timestamp keeping track of the last heartbeat of this UI. Updated to the
@@ -193,6 +206,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements
      */
     public UI(Component content) {
         registerRpc(rpc);
+        registerRpc(debugRpc);
         setSizeFull();
         setContent(content);
     }
@@ -1441,4 +1455,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements
         return localeService;
     }
 
+    private static Logger getLogger() {
+        return Logger.getLogger(UI.class.getName());
+    }
 }
diff --git a/server/src/com/vaadin/util/ConnectorHelper.java b/server/src/com/vaadin/util/ConnectorHelper.java
new file mode 100644 (file)
index 0000000..e698e92
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * 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.util;
+
+import java.util.LinkedList;
+
+import com.vaadin.server.ClientConnector;
+import com.vaadin.ui.Component;
+
+/**
+ * Provides various helper methods for connectors. Meant for internal use.
+ * 
+ * @since 7.1
+ * @author Vaadin Ltd
+ */
+public class ConnectorHelper {
+
+    /**
+     * Creates a string containing debug info for the connector
+     * 
+     * @since 7.1
+     * @param connector
+     *            The connector to print debug info about
+     * @return A string with debug information
+     */
+    public static String getDebugInformation(ClientConnector connector) {
+        StringBuilder sb = new StringBuilder();
+        sb.append("*** Debug details of a connector:  *** \n");
+        sb.append("Type: ");
+        sb.append(connector.getClass().getName());
+        sb.append("\nId:");
+        sb.append(connector.getConnectorId());
+        if (connector instanceof Component) {
+            Component component = (Component) connector;
+            if (component.getCaption() != null) {
+                sb.append("\nCaption:");
+                sb.append(component.getCaption());
+            }
+        }
+        writeHierarchyInformation(connector, sb);
+        return sb.toString();
+    }
+
+    /**
+     * Creates a string containing hierarchy information for the connector
+     * 
+     * @since 7.1
+     * @param connector
+     *            The connector to get hierarchy information for
+     * @param builder
+     *            The StringBuilder where the information should be written
+     */
+    public static void writeHierarchyInformation(ClientConnector connector,
+            StringBuilder builder) {
+        LinkedList<ClientConnector> h = new LinkedList<ClientConnector>();
+        h.add(connector);
+        ClientConnector parent = connector.getParent();
+        while (parent != null) {
+            h.addFirst(parent);
+            parent = parent.getParent();
+        }
+
+        builder.append("\nConnector hierarchy:\n");
+
+        int l = 0;
+        for (ClientConnector connector2 : h) {
+            if (l != 0) {
+                builder.append("\n");
+                for (int i = 0; i < l; i++) {
+                    builder.append("  ");
+                }
+            }
+            l++;
+            Class<? extends ClientConnector> connectorClass = connector2
+                    .getClass();
+            Class<?> topClass = connectorClass;
+            while (topClass.getEnclosingClass() != null) {
+                topClass = topClass.getEnclosingClass();
+            }
+            builder.append(connectorClass.getName());
+            builder.append("(");
+            builder.append(topClass.getSimpleName());
+            builder.append(".java:1)");
+        }
+    }
+
+}
index 04cba79c0cea6d68e5a7bbd2cf9b68f737dd77f0..6124b71d3434210f311b0b10775aa8d96e906686 100644 (file)
@@ -40,7 +40,6 @@ public class ApplicationConstants implements Serializable {
     public static final String UIDL_SECURITY_TOKEN_ID = "Vaadin-Security-Key";
 
     public static final String PARAM_ANALYZE_LAYOUTS = "analyzeLayouts";
-    public static final String PARAM_HIGHLIGHT_CONNECTOR = "highlightConnector";
 
     @Deprecated
     public static final String UPDATE_VARIABLE_INTERFACE = "v";
diff --git a/shared/src/com/vaadin/shared/ui/ui/DebugWindowServerRpc.java b/shared/src/com/vaadin/shared/ui/ui/DebugWindowServerRpc.java
new file mode 100644 (file)
index 0000000..ec8bc45
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.shared.ui.ui;
+
+import com.vaadin.shared.Connector;
+import com.vaadin.shared.communication.ServerRpc;
+
+/**
+ * Server RPC methods for the Debug Window.
+ * 
+ * @since 7.1
+ * @author Vaadin Ltd
+ */
+public interface DebugWindowServerRpc extends ServerRpc {
+    /**
+     * Sends a request to the server to print details to console that will help
+     * the developer to locate the corresponding server-side connector in the
+     * source code.
+     * 
+     * @since 7.1
+     * @param connector
+     *            the connector to locate
+     **/
+    public void showServerDebugInfo(Connector connector);
+
+}