diff options
12 files changed, 115 insertions, 118 deletions
diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index 4dd68cc24f..a3279e5631 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -221,8 +221,6 @@ public class ApplicationConnection { private Date requestStartTime; - private boolean validatingLayouts = false; - private final LayoutManager layoutManager; private final RpcManager rpcManager; @@ -678,11 +676,12 @@ public class ApplicationConnection { /** * Requests an analyze of layouts, to find inconsistencies. Exclusively used * for debugging during development. + * + * @deprecated as of 7.1. Replaced by {@link UIConnector#analyzeLayouts()} */ + @Deprecated public void analyzeLayouts() { - String params = getRepaintAllParameters() + "&" - + ApplicationConstants.PARAM_ANALYZE_LAYOUTS + "=1"; - makeUidlRequest("", params); + getUIConnector().analyzeLayouts(); } /** @@ -1358,9 +1357,6 @@ public class ApplicationConnection { meta = json.getValueMap("meta"); if (meta.containsKey("repaintAll")) { prepareRepaintAll(); - if (meta.containsKey("invalidLayouts")) { - validatingLayouts = true; - } } if (meta.containsKey("timedRedirect")) { final ValueMap timedRedirect = meta @@ -1461,17 +1457,6 @@ public class ApplicationConnection { applicationRunning = false; } - if (validatingLayouts) { - Set<ComponentConnector> zeroHeightComponents = new HashSet<ComponentConnector>(); - Set<ComponentConnector> zeroWidthComponents = new HashSet<ComponentConnector>(); - findZeroSizeComponents(zeroHeightComponents, - zeroWidthComponents, getUIConnector()); - VConsole.printLayoutProblems(meta, - ApplicationConnection.this, - zeroHeightComponents, zeroWidthComponents); - validatingLayouts = false; - - } Profiler.leave("Error handling"); } @@ -2226,28 +2211,6 @@ public class ApplicationConnection { ApplicationConfiguration.runWhenDependenciesLoaded(c); } - private void findZeroSizeComponents( - Set<ComponentConnector> zeroHeightComponents, - Set<ComponentConnector> zeroWidthComponents, - ComponentConnector connector) { - Widget widget = connector.getWidget(); - ComputedStyle computedStyle = new ComputedStyle(widget.getElement()); - if (computedStyle.getIntProperty("height") == 0) { - zeroHeightComponents.add(connector); - } - if (computedStyle.getIntProperty("width") == 0) { - zeroWidthComponents.add(connector); - } - List<ServerConnector> children = connector.getChildren(); - for (ServerConnector serverConnector : children) { - if (serverConnector instanceof ComponentConnector) { - findZeroSizeComponents(zeroHeightComponents, - zeroWidthComponents, - (ComponentConnector) serverConnector); - } - } - } - private void loadStyleDependencies(JsArrayString dependencies) { // Assuming no reason to interpret in a defined order ResourceLoadListener resourceLoadListener = new ResourceLoadListener() { diff --git a/client/src/com/vaadin/client/VConsole.java b/client/src/com/vaadin/client/VConsole.java index f7a7554e34..37ed8e6370 100644 --- a/client/src/com/vaadin/client/VConsole.java +++ b/client/src/com/vaadin/client/VConsole.java @@ -15,7 +15,6 @@ */ package com.vaadin.client; -import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -81,9 +80,7 @@ public class VConsole { } public static void printLayoutProblems(ValueMap meta, - ApplicationConnection applicationConnection, - Set<ComponentConnector> zeroHeightComponents, - Set<ComponentConnector> zeroWidthComponents) { + ApplicationConnection applicationConnection) { if (impl != null) { impl.meta(applicationConnection, meta); } diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java index 38c26a77e6..1c2c6ddeb8 100644 --- a/client/src/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java @@ -53,6 +53,7 @@ import com.vaadin.client.Paintable; import com.vaadin.client.ServerConnector; import com.vaadin.client.UIDL; import com.vaadin.client.VConsole; +import com.vaadin.client.ValueMap; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler; import com.vaadin.client.ui.AbstractSingleComponentContainerConnector; @@ -69,6 +70,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.DebugWindowClientRpc; import com.vaadin.shared.ui.ui.DebugWindowServerRpc; import com.vaadin.shared.ui.ui.PageClientRpc; import com.vaadin.shared.ui.ui.PageState; @@ -136,6 +138,19 @@ public class UIConnector extends AbstractSingleComponentContainerConnector }); } }); + registerRpc(DebugWindowClientRpc.class, new DebugWindowClientRpc() { + + @Override + public void reportLayoutProblems(String json) { + VConsole.printLayoutProblems(getValueMap(json), getConnection()); + } + + private native ValueMap getValueMap(String json) + /*-{ + return JSON.parse(json); + }-*/; + }); + getWidget().addResizeHandler(new ResizeHandler() { @Override public void onResize(ResizeEvent event) { @@ -663,6 +678,15 @@ public class UIConnector extends AbstractSingleComponentContainerConnector } /** + * Invokes the layout analyzer on the server + * + * @since 7.1 + */ + public void analyzeLayouts() { + getRpcProxy(DebugWindowServerRpc.class).analyzeLayouts(); + } + + /** * 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. diff --git a/server/src/com/vaadin/server/ComponentSizeValidator.java b/server/src/com/vaadin/server/ComponentSizeValidator.java index 27d087a2b2..07c195a1c1 100644 --- a/server/src/com/vaadin/server/ComponentSizeValidator.java +++ b/server/src/com/vaadin/server/ComponentSizeValidator.java @@ -16,8 +16,8 @@ package com.vaadin.server; import java.io.PrintStream; -import java.io.PrintWriter; import java.io.Serializable; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; @@ -40,6 +40,7 @@ import com.vaadin.ui.GridLayout.Area; import com.vaadin.ui.Layout; import com.vaadin.ui.Panel; import com.vaadin.ui.TabSheet; +import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; @@ -190,14 +191,14 @@ public class ComponentSizeValidator implements Serializable { subErrors.add(error); } - public void reportErrors(PrintWriter clientJSON, + public void reportErrors(StringBuilder clientJSON, PrintStream serverErrorStream) { - clientJSON.write("{"); + clientJSON.append("{"); Component parent = component.getParent(); String paintableId = component.getConnectorId(); - clientJSON.print("id:\"" + paintableId + "\""); + clientJSON.append("\"id\":\"" + paintableId + "\""); if (invalidHeight) { Stack<ComponentInfo> attributes = null; @@ -227,7 +228,7 @@ public class ComponentSizeValidator implements Serializable { attributes = getHeightAttributes(component); } printServerError(msg, attributes, false, serverErrorStream); - clientJSON.print(",\"heightMsg\":\"" + msg + "\""); + clientJSON.append(",\"heightMsg\":\"" + msg + "\""); } if (invalidWidth) { Stack<ComponentInfo> attributes = null; @@ -255,25 +256,25 @@ public class ComponentSizeValidator implements Serializable { msg = "A component with relative width needs a parent with defined width."; attributes = getWidthAttributes(component); } - clientJSON.print(",\"widthMsg\":\"" + msg + "\""); + clientJSON.append(",\"widthMsg\":\"" + msg + "\""); printServerError(msg, attributes, true, serverErrorStream); } if (subErrors.size() > 0) { serverErrorStream.println("Sub errors >>"); - clientJSON.write(", \"subErrors\" : ["); + clientJSON.append(", \"subErrors\" : ["); boolean first = true; for (InvalidLayout subError : subErrors) { if (!first) { - clientJSON.print(","); + clientJSON.append(","); } else { first = false; } subError.reportErrors(clientJSON, serverErrorStream); } - clientJSON.write("]"); + clientJSON.append("]"); serverErrorStream.println("<< Sub erros"); } - clientJSON.write("}"); + clientJSON.append("}"); } } @@ -673,4 +674,31 @@ public class ComponentSizeValidator implements Serializable { return Logger.getLogger(ComponentSizeValidator.class.getName()); } + /** + * Validates the layout and returns a collection of errors + * + * @since 7.1 + * @param ui + * The UI to validate + * @return A collection of errors. An empty collection if there are no + * errors. + */ + public static List<InvalidLayout> validateLayouts(UI ui) { + List<InvalidLayout> invalidRelativeSizes = ComponentSizeValidator + .validateComponentRelativeSizes(ui.getContent(), + new ArrayList<ComponentSizeValidator.InvalidLayout>(), + null); + + // Also check any existing subwindows + if (ui.getWindows() != null) { + for (Window subWindow : ui.getWindows()) { + invalidRelativeSizes = ComponentSizeValidator + .validateComponentRelativeSizes(subWindow.getContent(), + invalidRelativeSizes, null); + } + } + return invalidRelativeSizes; + + } + } diff --git a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java index e967dd925a..9e57ccb45d 100644 --- a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java +++ b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java @@ -123,7 +123,7 @@ public class AtmospherePushConnection implements PushConnection { protected void push(boolean async) throws IOException { Writer writer = new StringWriter(); try { - new UidlWriter().write(getUI(), writer, false, false, async); + new UidlWriter().write(getUI(), writer, false, async); } catch (JSONException e) { throw new IOException("Error writing UIDL", e); } diff --git a/server/src/com/vaadin/server/communication/MetadataWriter.java b/server/src/com/vaadin/server/communication/MetadataWriter.java index 9993ef1e44..5ad7186c24 100644 --- a/server/src/com/vaadin/server/communication/MetadataWriter.java +++ b/server/src/com/vaadin/server/communication/MetadataWriter.java @@ -17,16 +17,11 @@ package com.vaadin.server.communication; import java.io.IOException; -import java.io.PrintWriter; import java.io.Serializable; import java.io.Writer; -import java.util.List; -import com.vaadin.server.ComponentSizeValidator; -import com.vaadin.server.ComponentSizeValidator.InvalidLayout; import com.vaadin.server.SystemMessages; import com.vaadin.ui.UI; -import com.vaadin.ui.Window; /** * Serializes miscellaneous metadata to JSON. @@ -60,26 +55,8 @@ public class MetadataWriter implements Serializable { * If the serialization fails. * */ - public void write(UI ui, Writer writer, boolean repaintAll, - boolean analyzeLayouts, boolean async, SystemMessages messages) - throws IOException { - - List<InvalidLayout> invalidComponentRelativeSizes = null; - - if (analyzeLayouts) { - invalidComponentRelativeSizes = ComponentSizeValidator - .validateComponentRelativeSizes(ui.getContent(), null, null); - - // Also check any existing subwindows - if (ui.getWindows() != null) { - for (Window subWindow : ui.getWindows()) { - invalidComponentRelativeSizes = ComponentSizeValidator - .validateComponentRelativeSizes( - subWindow.getContent(), - invalidComponentRelativeSizes, null); - } - } - } + public void write(UI ui, Writer writer, boolean repaintAll, boolean async, + SystemMessages messages) throws IOException { writer.write("{"); @@ -87,23 +64,6 @@ public class MetadataWriter implements Serializable { if (repaintAll) { metaOpen = true; writer.write("\"repaintAll\":true"); - if (analyzeLayouts) { - writer.write(", \"invalidLayouts\":"); - writer.write("["); - if (invalidComponentRelativeSizes != null) { - boolean first = true; - for (InvalidLayout invalidLayout : invalidComponentRelativeSizes) { - if (!first) { - writer.write(","); - } else { - first = false; - } - invalidLayout.reportErrors(new PrintWriter(writer), - System.err); - } - } - writer.write("]"); - } } if (async) { diff --git a/server/src/com/vaadin/server/communication/UIInitHandler.java b/server/src/com/vaadin/server/communication/UIInitHandler.java index e4b5360b49..8507bf40cc 100644 --- a/server/src/com/vaadin/server/communication/UIInitHandler.java +++ b/server/src/com/vaadin/server/communication/UIInitHandler.java @@ -273,7 +273,7 @@ public abstract class UIInitHandler extends SynchronizedRequestHandler { if (session.getConfiguration().isXsrfProtectionEnabled()) { writer.write(getSecurityKeyUIDL(session)); } - new UidlWriter().write(uI, writer, true, false, false); + new UidlWriter().write(uI, writer, true, false); writer.write("}"); String initialUIDL = writer.toString(); diff --git a/server/src/com/vaadin/server/communication/UidlRequestHandler.java b/server/src/com/vaadin/server/communication/UidlRequestHandler.java index 55fb473998..3564aa65b5 100644 --- a/server/src/com/vaadin/server/communication/UidlRequestHandler.java +++ b/server/src/com/vaadin/server/communication/UidlRequestHandler.java @@ -86,13 +86,6 @@ public class UidlRequestHandler extends SynchronizedRequestHandler implements repaintAll = (request .getParameter(ApplicationConstants.URL_PARAMETER_REPAINT_ALL) != null); - boolean analyzeLayouts = false; - if (repaintAll) { - // analyzing can be done only with repaintAll - analyzeLayouts = (request - .getParameter(ApplicationConstants.PARAM_ANALYZE_LAYOUTS) != null); - } - StringWriter stringWriter = new StringWriter(); try { @@ -102,8 +95,7 @@ public class UidlRequestHandler extends SynchronizedRequestHandler implements session.getCommunicationManager().repaintAll(uI); } - writeUidl(request, response, uI, stringWriter, repaintAll, - analyzeLayouts); + writeUidl(request, response, uI, stringWriter, repaintAll); } catch (JSONException e) { getLogger().log(Level.SEVERE, "Error writing JSON to response", e); // Refresh on client side @@ -152,11 +144,11 @@ public class UidlRequestHandler extends SynchronizedRequestHandler implements } private void writeUidl(VaadinRequest request, VaadinResponse response, - UI ui, Writer writer, boolean repaintAll, boolean analyzeLayouts) - throws IOException, JSONException { + UI ui, Writer writer, boolean repaintAll) throws IOException, + JSONException { openJsonMessage(writer, response); - new UidlWriter().write(ui, writer, repaintAll, analyzeLayouts, false); + new UidlWriter().write(ui, writer, repaintAll, false); closeJsonMessage(writer); } diff --git a/server/src/com/vaadin/server/communication/UidlWriter.java b/server/src/com/vaadin/server/communication/UidlWriter.java index a915501056..60933a75c2 100644 --- a/server/src/com/vaadin/server/communication/UidlWriter.java +++ b/server/src/com/vaadin/server/communication/UidlWriter.java @@ -71,9 +71,8 @@ public class UidlWriter implements Serializable { * @throws JSONException * If the JSON serialization fails. */ - public void write(UI ui, Writer writer, boolean repaintAll, - boolean analyzeLayouts, boolean async) throws IOException, - JSONException { + public void write(UI ui, Writer writer, boolean repaintAll, boolean async) + throws IOException, JSONException { VaadinSession session = ui.getSession(); // Purge pending access calls as they might produce additional changes @@ -161,8 +160,7 @@ public class UidlWriter implements Serializable { SystemMessages messages = ui.getSession().getService() .getSystemMessages(ui.getLocale(), null); // TODO hilightedConnector - new MetadataWriter().write(ui, writer, repaintAll, analyzeLayouts, - async, messages); + new MetadataWriter().write(ui, writer, repaintAll, async, messages); writer.write(", "); writer.write("\"resources\" : "); diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index 3194786431..2c6283377a 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashSet; +import java.util.List; import java.util.Map; import java.util.concurrent.Future; import java.util.logging.Logger; @@ -32,6 +33,8 @@ 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.ComponentSizeValidator; +import com.vaadin.server.ComponentSizeValidator.InvalidLayout; import com.vaadin.server.LocaleService; import com.vaadin.server.Page; import com.vaadin.server.PaintException; @@ -46,6 +49,7 @@ 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.DebugWindowClientRpc; import com.vaadin.shared.ui.ui.DebugWindowServerRpc; import com.vaadin.shared.ui.ui.ScrollClientRpc; import com.vaadin.shared.ui.ui.UIClientRpc; @@ -173,6 +177,32 @@ public abstract class UI extends AbstractSingleComponentContainer implements .getDebugInformation((ClientConnector) connector); getLogger().info(info); } + + @Override + public void analyzeLayouts() { + // TODO Move to client side + List<InvalidLayout> invalidSizes = ComponentSizeValidator + .validateLayouts(UI.this); + StringBuilder json = new StringBuilder(); + json.append("{\"invalidLayouts\":"); + json.append("["); + + if (invalidSizes != null) { + boolean first = true; + for (InvalidLayout invalidSize : invalidSizes) { + if (!first) { + json.append(","); + } else { + first = false; + } + invalidSize.reportErrors(json, System.err); + } + } + json.append("]}"); + getRpcProxy(DebugWindowClientRpc.class).reportLayoutProblems( + json.toString()); + } + }; /** diff --git a/shared/src/com/vaadin/shared/ApplicationConstants.java b/shared/src/com/vaadin/shared/ApplicationConstants.java index 6124b71d34..e51139dac7 100644 --- a/shared/src/com/vaadin/shared/ApplicationConstants.java +++ b/shared/src/com/vaadin/shared/ApplicationConstants.java @@ -39,8 +39,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"; - @Deprecated public static final String UPDATE_VARIABLE_INTERFACE = "v"; @Deprecated diff --git a/shared/src/com/vaadin/shared/ui/ui/DebugWindowServerRpc.java b/shared/src/com/vaadin/shared/ui/ui/DebugWindowServerRpc.java index ec8bc45b81..76e7d23379 100644 --- a/shared/src/com/vaadin/shared/ui/ui/DebugWindowServerRpc.java +++ b/shared/src/com/vaadin/shared/ui/ui/DebugWindowServerRpc.java @@ -40,4 +40,11 @@ public interface DebugWindowServerRpc extends ServerRpc { **/ public void showServerDebugInfo(Connector connector); + /** + * Invokes the layout analyzer on the server + * + * @since 7.1 + */ + public void analyzeLayouts(); + } |