You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConnectorInfoPanel.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.debug.internal;
  17. import java.util.Arrays;
  18. import java.util.HashSet;
  19. import java.util.Set;
  20. import com.google.gwt.user.client.ui.FlowPanel;
  21. import com.google.gwt.user.client.ui.HTML;
  22. import com.vaadin.client.ComponentConnector;
  23. import com.vaadin.client.JsArrayObject;
  24. import com.vaadin.client.ServerConnector;
  25. import com.vaadin.client.Util;
  26. import com.vaadin.client.VConsole;
  27. import com.vaadin.client.metadata.NoDataException;
  28. import com.vaadin.client.metadata.Property;
  29. import com.vaadin.client.ui.AbstractConnector;
  30. import com.vaadin.shared.AbstractComponentState;
  31. import com.vaadin.shared.communication.SharedState;
  32. /**
  33. * Connector information view panel of the debug window.
  34. *
  35. * @since 7.1.4
  36. */
  37. public class ConnectorInfoPanel extends FlowPanel {
  38. /**
  39. * Update the panel to show information about a connector.
  40. *
  41. * @param connector
  42. */
  43. public void update(ServerConnector connector) {
  44. SharedState state = connector.getState();
  45. Set<String> ignoreProperties = new HashSet<String>();
  46. ignoreProperties.add("id");
  47. String html = getRowHTML("Id", connector.getConnectorId());
  48. html += getRowHTML("Connector", Util.getSimpleName(connector));
  49. if (connector instanceof ComponentConnector) {
  50. ComponentConnector component = (ComponentConnector) connector;
  51. ignoreProperties.addAll(Arrays.asList("caption", "description",
  52. "width", "height"));
  53. AbstractComponentState componentState = component.getState();
  54. html += getRowHTML("Widget",
  55. Util.getSimpleName(component.getWidget()));
  56. html += getRowHTML("Caption", componentState.caption);
  57. html += getRowHTML("Description", componentState.description);
  58. html += getRowHTML("Width", componentState.width + " (actual: "
  59. + component.getWidget().getOffsetWidth() + "px)");
  60. html += getRowHTML("Height", componentState.height + " (actual: "
  61. + component.getWidget().getOffsetHeight() + "px)");
  62. }
  63. try {
  64. JsArrayObject<Property> properties = AbstractConnector
  65. .getStateType(connector).getPropertiesAsArray();
  66. for (int i = 0; i < properties.size(); i++) {
  67. Property property = properties.get(i);
  68. String name = property.getName();
  69. if (!ignoreProperties.contains(name)) {
  70. html += getRowHTML(property.getDisplayName(),
  71. property.getValue(state));
  72. }
  73. }
  74. } catch (NoDataException e) {
  75. html += "<div>Could not read state, error has been logged to the console</div>";
  76. VConsole.error(e);
  77. }
  78. clear();
  79. add(new HTML(html));
  80. }
  81. private String getRowHTML(String caption, Object value) {
  82. return "<div class=\"" + VDebugWindow.STYLENAME
  83. + "-row\"><span class=\"caption\">" + caption
  84. + "</span><span class=\"value\">"
  85. + Util.escapeHTML(String.valueOf(value)) + "</span></div>";
  86. }
  87. /**
  88. * Clear the contents of the panel.
  89. */
  90. public void clearContents() {
  91. clear();
  92. }
  93. }