diff options
author | Artur Signell <artur@vaadin.com> | 2013-06-04 23:13:29 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-06-05 09:19:26 +0000 |
commit | 6d4582eea9e19518c7341ec65357b1d04a1a37c6 (patch) | |
tree | bfa7fb5609d488880e9bfd8a2d47e2465d12f832 /server | |
parent | aa99259eac14854e1e9a33fbbd429d0c5ffa9c52 (diff) | |
download | vaadin-framework-6d4582eea9e19518c7341ec65357b1d04a1a37c6.tar.gz vaadin-framework-6d4582eea9e19518c7341ec65357b1d04a1a37c6.zip |
Change analyze layouts to use RPC (#11536)
Change-Id: I80d39e4ce4e0576b98ad095efce03740291d3de5
Diffstat (limited to 'server')
7 files changed, 79 insertions, 71 deletions
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()); + } + }; /** |