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.

InfoSection.java 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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.List;
  18. import java.util.logging.Level;
  19. import com.google.gwt.core.client.GWT;
  20. import com.google.gwt.dom.client.Element;
  21. import com.google.gwt.user.client.DOM;
  22. import com.google.gwt.user.client.Timer;
  23. import com.google.gwt.user.client.ui.HTML;
  24. import com.google.gwt.user.client.ui.RootPanel;
  25. import com.google.gwt.user.client.ui.Widget;
  26. import com.vaadin.client.ApplicationConfiguration;
  27. import com.vaadin.client.ApplicationConnection;
  28. import com.vaadin.client.ValueMap;
  29. import com.vaadin.shared.Version;
  30. import com.vaadin.shared.util.SharedUtil;
  31. /**
  32. * Information section of the debug window
  33. *
  34. * @since 7.1
  35. * @author Vaadin Ltd
  36. */
  37. public class InfoSection implements Section {
  38. private static final String THEME_VERSION_CLASSNAME = "v-vaadin-version";
  39. private static final String PRIMARY_STYLE_NAME = VDebugWindow.STYLENAME
  40. + "-info";
  41. private static final String ERROR_STYLE = Level.SEVERE.getName();
  42. private final HTML content = new HTML();
  43. private DebugButton tabButton = new DebugButton(Icon.INFO,
  44. "General information about the application(s)");
  45. private HTML controls = new HTML(tabButton.getTitle());
  46. private Timer refresher = new Timer() {
  47. @Override
  48. public void run() {
  49. refresh();
  50. }
  51. };
  52. /**
  53. *
  54. */
  55. public InfoSection() {
  56. createContent();
  57. }
  58. /**
  59. * @since 7.1
  60. */
  61. private void createContent() {
  62. content.setStylePrimaryName(PRIMARY_STYLE_NAME);
  63. refresh();
  64. }
  65. private void addRow(String parameter, String value) {
  66. addRow(parameter, value, null);
  67. }
  68. private void addRow(String parameter, String value, String className) {
  69. Element row = DOM.createDiv();
  70. row.addClassName(VDebugWindow.STYLENAME + "-row");
  71. if (className != null) {
  72. row.addClassName(className);
  73. }
  74. Element span = DOM.createSpan();
  75. span.setClassName("caption");
  76. span.setInnerText(parameter);
  77. row.appendChild(span);
  78. span = DOM.createSpan();
  79. span.setClassName("value");
  80. span.setInnerText(value);
  81. row.appendChild(span);
  82. content.getElement().appendChild(row);
  83. }
  84. /*
  85. * (non-Javadoc)
  86. *
  87. * @see com.vaadin.client.debug.internal.Section#getTabButton()
  88. */
  89. @Override
  90. public DebugButton getTabButton() {
  91. return tabButton;
  92. }
  93. /*
  94. * (non-Javadoc)
  95. *
  96. * @see com.vaadin.client.debug.internal.Section#getControls()
  97. */
  98. @Override
  99. public Widget getControls() {
  100. return controls;
  101. }
  102. /*
  103. * (non-Javadoc)
  104. *
  105. * @see com.vaadin.client.debug.internal.Section#getContent()
  106. */
  107. @Override
  108. public Widget getContent() {
  109. return content;
  110. }
  111. /*
  112. * (non-Javadoc)
  113. *
  114. * @see com.vaadin.client.debug.internal.Section#show()
  115. */
  116. @Override
  117. public void show() {
  118. refresh();
  119. }
  120. /**
  121. * Updates the information for all running applications
  122. *
  123. * @since 7.1
  124. */
  125. private void refresh() {
  126. clear();
  127. List<ApplicationConnection> apps = ApplicationConfiguration
  128. .getRunningApplications();
  129. if (apps.size() == 0) {
  130. // try again in a while
  131. refresher.schedule(1000);
  132. } else {
  133. for (ApplicationConnection application : apps) {
  134. refresh(application);
  135. }
  136. }
  137. }
  138. /**
  139. * Updates the information for a single running application
  140. *
  141. * @since 7.1
  142. */
  143. private void refresh(ApplicationConnection connection) {
  144. clear();
  145. ApplicationConfiguration configuration = connection.getConfiguration();
  146. addVersionInfo(configuration);
  147. addRow("Widget set", GWT.getModuleName());
  148. addRow("Theme", connection.getConfiguration().getThemeName());
  149. String communicationMethodInfo = connection
  150. .getCommunicationMethodName();
  151. int pollInterval = connection.getUIConnector().getState().pollInterval;
  152. if (pollInterval > 0) {
  153. communicationMethodInfo += " (poll interval " + pollInterval
  154. + "ms)";
  155. }
  156. addRow("Communication method", communicationMethodInfo);
  157. String heartBeatInfo;
  158. if (configuration.getHeartbeatInterval() < 0) {
  159. heartBeatInfo = "Disabled";
  160. } else {
  161. heartBeatInfo = configuration.getHeartbeatInterval() + "s";
  162. }
  163. addRow("Heartbeat", heartBeatInfo);
  164. }
  165. /**
  166. * Logs version information for client/server/theme.
  167. *
  168. * @param applicationConfiguration
  169. * @since 7.1
  170. */
  171. private void addVersionInfo(
  172. ApplicationConfiguration applicationConfiguration) {
  173. String clientVersion = Version.getFullVersion();
  174. String servletVersion = applicationConfiguration.getServletVersion();
  175. String themeVersion;
  176. boolean themeOk;
  177. if (com.vaadin.client.BrowserInfo.get().isIE8()) {
  178. themeVersion = "<IE8 can't detect this>";
  179. themeOk = true;
  180. } else {
  181. themeVersion = getThemeVersion();
  182. themeOk = equalsEither(themeVersion, clientVersion, servletVersion);
  183. }
  184. boolean clientOk = equalsEither(clientVersion, servletVersion,
  185. themeVersion);
  186. boolean servletOk = equalsEither(servletVersion, clientVersion,
  187. themeVersion);
  188. addRow("Client engine version", clientVersion, clientOk ? null
  189. : ERROR_STYLE);
  190. addRow("Server engine version", servletVersion, servletOk ? null
  191. : ERROR_STYLE);
  192. addRow("Theme version", themeVersion, themeOk ? null : ERROR_STYLE);
  193. }
  194. /**
  195. * Checks if the target value equals one of the reference values
  196. *
  197. * @param target
  198. * The value to compare
  199. * @param reference1
  200. * A reference value
  201. * @param reference2
  202. * A reference value
  203. * @return true if target equals one of the references, false otherwise
  204. */
  205. private boolean equalsEither(String target, String reference1,
  206. String reference2) {
  207. if (SharedUtil.equals(target, reference1)) {
  208. return true;
  209. }
  210. if (SharedUtil.equals(target, reference2)) {
  211. return true;
  212. }
  213. return false;
  214. }
  215. /**
  216. * Finds out the version of the current theme (i.e. the version of Vaadin
  217. * used to compile it)
  218. *
  219. * @since 7.1
  220. * @return The full version as a string
  221. */
  222. private String getThemeVersion() {
  223. Element div = DOM.createDiv();
  224. div.setClassName(THEME_VERSION_CLASSNAME);
  225. RootPanel.get().getElement().appendChild(div);
  226. String version = getComputedStyle(div, ":after", "content");
  227. div.removeFromParent();
  228. if (version != null) {
  229. // String version = new ComputedStyle(div).getProperty("content");
  230. version = version.replace("'", "");
  231. version = version.replace("\"", "");
  232. }
  233. return version;
  234. }
  235. private native String getComputedStyle(Element elem, String pseudoElement,
  236. String property)
  237. /*-{
  238. if ($wnd.document.defaultView && $wnd.document.defaultView.getComputedStyle) {
  239. return $wnd.document.defaultView.getComputedStyle(elem, pseudoElement)[property];
  240. } else {
  241. return null;
  242. }
  243. }-*/;
  244. /**
  245. * Removes all content
  246. *
  247. * @since 7.1
  248. */
  249. private void clear() {
  250. content.getElement().setInnerHTML("");
  251. }
  252. /*
  253. * (non-Javadoc)
  254. *
  255. * @see com.vaadin.client.debug.internal.Section#hide()
  256. */
  257. @Override
  258. public void hide() {
  259. refresher.cancel();
  260. }
  261. /*
  262. * (non-Javadoc)
  263. *
  264. * @see com.vaadin.client.debug.internal.Section#meta(com.vaadin.client.
  265. * ApplicationConnection, com.vaadin.client.ValueMap)
  266. */
  267. @Override
  268. public void meta(ApplicationConnection ac, ValueMap meta) {
  269. }
  270. /*
  271. * (non-Javadoc)
  272. *
  273. * @see com.vaadin.client.debug.internal.Section#uidl(com.vaadin.client.
  274. * ApplicationConnection, com.vaadin.client.ValueMap)
  275. */
  276. @Override
  277. public void uidl(ApplicationConnection ac, ValueMap uidl) {
  278. }
  279. }