diff options
author | Leif Åstrand <leif@vaadin.com> | 2013-04-09 11:19:54 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-04-09 11:35:17 +0000 |
commit | 9ee728b775c29ef4d9765e9a8262a883e1d0e8c6 (patch) | |
tree | 07cb8a052ec94b423a7b4b0a28d1084ec1786452 | |
parent | 3d311b6c03fd7f883d0a8e3f7358c0633468d01b (diff) | |
download | vaadin-framework-9ee728b775c29ef4d9765e9a8262a883e1d0e8c6.tar.gz vaadin-framework-9ee728b775c29ef4d9765e9a8262a883e1d0e8c6.zip |
Show all state properties in the hierarchy section (#11548)
Change-Id: I91b9a7a25822006c655a36858198be3a16057dac
-rw-r--r-- | client/src/com/vaadin/client/debug/internal/HierarchySection.java | 39 | ||||
-rw-r--r-- | client/src/com/vaadin/client/metadata/Property.java | 25 |
2 files changed, 56 insertions, 8 deletions
diff --git a/client/src/com/vaadin/client/debug/internal/HierarchySection.java b/client/src/com/vaadin/client/debug/internal/HierarchySection.java index 776ba9326d..f69315dbd9 100644 --- a/client/src/com/vaadin/client/debug/internal/HierarchySection.java +++ b/client/src/com/vaadin/client/debug/internal/HierarchySection.java @@ -15,6 +15,7 @@ */ package com.vaadin.client.debug.internal; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,11 +46,15 @@ import com.vaadin.client.ApplicationConnection; import com.vaadin.client.ComponentConnector; import com.vaadin.client.ComputedStyle; import com.vaadin.client.ConnectorMap; +import com.vaadin.client.JsArrayObject; import com.vaadin.client.ServerConnector; import com.vaadin.client.SimpleTree; import com.vaadin.client.Util; import com.vaadin.client.VConsole; import com.vaadin.client.ValueMap; +import com.vaadin.client.metadata.NoDataException; +import com.vaadin.client.metadata.Property; +import com.vaadin.client.ui.AbstractConnector; import com.vaadin.client.ui.UnknownComponentConnector; import com.vaadin.shared.AbstractComponentState; @@ -61,6 +66,14 @@ import com.vaadin.shared.AbstractComponentState; */ class HierarchySection implements Section { + /** + * Shared state properties that have hardcoded support in + * {@link #printState(ComponentConnector)} and should therefore be ignored + * when iterating through the properties. + */ + private final HashSet<String> ignoreProperties = new HashSet<String>( + Arrays.asList("id", "caption", "description", "width", "height")); + private final DebugButton tabButton = new DebugButton(Icon.HIERARCHY, "Examine compoent hierarchy"); @@ -486,13 +499,22 @@ class HierarchySection implements Section { + connector.getWidget().getOffsetWidth() + "px)"); html += getRowHTML("Height", state.height + " (actual: " + connector.getWidget().getOffsetHeight() + "px)"); - html += getRowHTML("Enabled", state.enabled); - html += getRowHTML("Read only", state.readOnly); - html += getRowHTML("Immediate", state.immediate); - html += getRowHTML("Error message", state.errorMessage); - html += getRowHTML("Primary stylename", state.primaryStyleName); - html += getRowHTML("Styles", state.styles); - html += getRowHTML("Resources", state.resources); + + try { + JsArrayObject<Property> properties = AbstractConnector + .getStateType(connector).getPropertiesAsArray(); + for (int i = 0; i < properties.size(); i++) { + Property property = properties.get(i); + String name = property.getName(); + if (!ignoreProperties.contains(name)) { + html += getRowHTML(property.getDisplayName(), + property.getValue(state)); + } + } + } catch (NoDataException e) { + html += "<div>Could not read state, error has been logged to the console</div>"; + VConsole.error(e); + } content.clear(); content.add(new HTML(html)); @@ -501,7 +523,8 @@ class HierarchySection implements Section { private String getRowHTML(String caption, Object value) { return "<div class=\"" + VDebugWindow.STYLENAME + "-row\"><span class=\"caption\">" + caption - + "</span><span class=\"value\">" + value + "</span></div>"; + + "</span><span class=\"value\">" + + Util.escapeHTML(String.valueOf(value)) + "</span></div>"; } private final NativePreviewHandler highlightModeHandler = new NativePreviewHandler() { diff --git a/client/src/com/vaadin/client/metadata/Property.java b/client/src/com/vaadin/client/metadata/Property.java index c0c375c14c..2e0ea49c88 100644 --- a/client/src/com/vaadin/client/metadata/Property.java +++ b/client/src/com/vaadin/client/metadata/Property.java @@ -88,4 +88,29 @@ public class Property { return getSignature(); } + /** + * Gets the property name formatted for displaying in a user interface. This + * returns a string where e.g. "camelCase" has been converted to + * "Camel case". + * + * @return the name of this property, formatted for humans to read + */ + public String getDisplayName() { + String camelCase = getName(); + StringBuilder b = new StringBuilder(camelCase.length()); + for (int i = 0; i < camelCase.length(); i++) { + char charAt = camelCase.charAt(i); + if (i == 0) { + // First char always upper case + b.append(Character.toUpperCase(charAt)); + } else if (Character.isUpperCase(charAt)) { + b.append(' '); + b.append(Character.toLowerCase(charAt)); + } else { + b.append(charAt); + } + } + return b.toString(); + } + } |