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 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 java.util.logging.Level;
  21. import java.util.logging.Logger;
  22. import com.google.gwt.user.client.ui.FlowPanel;
  23. import com.google.gwt.user.client.ui.HTML;
  24. import com.vaadin.client.ComponentConnector;
  25. import com.vaadin.client.JsArrayObject;
  26. import com.vaadin.client.ServerConnector;
  27. import com.vaadin.client.WidgetUtil;
  28. import com.vaadin.client.metadata.NoDataException;
  29. import com.vaadin.client.metadata.Property;
  30. import com.vaadin.client.ui.AbstractConnector;
  31. import com.vaadin.shared.AbstractComponentState;
  32. import com.vaadin.shared.communication.SharedState;
  33. /**
  34. * Connector information view panel of the debug window.
  35. *
  36. * @since 7.1.4
  37. */
  38. public class ConnectorInfoPanel extends FlowPanel {
  39. /**
  40. * Update the panel to show information about a connector.
  41. *
  42. * @param connector
  43. */
  44. public void update(ServerConnector connector) {
  45. SharedState state = connector.getState();
  46. Set<String> ignoreProperties = new HashSet<String>();
  47. ignoreProperties.add("id");
  48. String html = getRowHTML("Id", connector.getConnectorId());
  49. html += getRowHTML("Connector", connector.getClass().getSimpleName());
  50. if (connector instanceof ComponentConnector) {
  51. ComponentConnector component = (ComponentConnector) connector;
  52. ignoreProperties.addAll(Arrays.asList("caption", "description",
  53. "width", "height"));
  54. AbstractComponentState componentState = component.getState();
  55. html += getRowHTML("Widget", component.getWidget().getClass()
  56. .getSimpleName());
  57. html += getRowHTML("Caption", componentState.caption);
  58. html += getRowHTML("Description", componentState.description);
  59. html += getRowHTML("Width", componentState.width + " (actual: "
  60. + component.getWidget().getOffsetWidth() + "px)");
  61. html += getRowHTML("Height", componentState.height + " (actual: "
  62. + component.getWidget().getOffsetHeight() + "px)");
  63. }
  64. try {
  65. JsArrayObject<Property> properties = AbstractConnector
  66. .getStateType(connector).getPropertiesAsArray();
  67. for (int i = 0; i < properties.size(); i++) {
  68. Property property = properties.get(i);
  69. String name = property.getName();
  70. if (!ignoreProperties.contains(name)) {
  71. html += getRowHTML(property.getDisplayName(),
  72. property.getValue(state));
  73. }
  74. }
  75. } catch (NoDataException e) {
  76. html += "<div>Could not read state, error has been logged to the console</div>";
  77. getLogger().log(Level.SEVERE, "Could not read state", e);
  78. }
  79. clear();
  80. add(new HTML(html));
  81. }
  82. private String getRowHTML(String caption, Object value) {
  83. return "<div class=\"" + VDebugWindow.STYLENAME
  84. + "-row\"><span class=\"caption\">" + caption
  85. + "</span><span class=\"value\">"
  86. + WidgetUtil.escapeHTML(String.valueOf(value))
  87. + "</span></div>";
  88. }
  89. /**
  90. * Clear the contents of the panel.
  91. */
  92. public void clearContents() {
  93. clear();
  94. }
  95. public static Logger getLogger() {
  96. return Logger.getLogger(ConnectorInfoPanel.class.getName());
  97. }
  98. }