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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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.getUIConnector().getActiveTheme());
  149. String communicationMethodInfo = connection
  150. .getMessageSender().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 atmosphereVersion = applicationConfiguration
  176. .getAtmosphereVersion();
  177. String jsVersion = applicationConfiguration.getAtmosphereJSVersion();
  178. String themeVersion;
  179. boolean themeOk;
  180. if (com.vaadin.client.BrowserInfo.get().isIE8()) {
  181. themeVersion = "<IE8 can't detect this>";
  182. themeOk = true;
  183. } else {
  184. themeVersion = getThemeVersion();
  185. themeOk = equalsEither(themeVersion, clientVersion, servletVersion);
  186. }
  187. boolean clientOk = equalsEither(clientVersion, servletVersion,
  188. themeVersion);
  189. boolean servletOk = equalsEither(servletVersion, clientVersion,
  190. themeVersion);
  191. addRow("Client engine version", clientVersion, clientOk ? null
  192. : ERROR_STYLE);
  193. addRow("Server engine version", servletVersion, servletOk ? null
  194. : ERROR_STYLE);
  195. addRow("Theme version", themeVersion, themeOk ? null : ERROR_STYLE);
  196. if (jsVersion != null) {
  197. addRow("Push server version", atmosphereVersion);
  198. addRow("Push client version", jsVersion
  199. + " (note: does not need to match server version)");
  200. }
  201. }
  202. /**
  203. * Checks if the target value equals one of the reference values
  204. *
  205. * @param target
  206. * The value to compare
  207. * @param reference1
  208. * A reference value
  209. * @param reference2
  210. * A reference value
  211. * @return true if target equals one of the references, false otherwise
  212. */
  213. private boolean equalsEither(String target, String reference1,
  214. String reference2) {
  215. if (SharedUtil.equals(target, reference1)) {
  216. return true;
  217. }
  218. if (SharedUtil.equals(target, reference2)) {
  219. return true;
  220. }
  221. return false;
  222. }
  223. /**
  224. * Finds out the version of the current theme (i.e. the version of Vaadin
  225. * used to compile it)
  226. *
  227. * @since 7.1
  228. * @return The full version as a string
  229. */
  230. private String getThemeVersion() {
  231. Element div = DOM.createDiv();
  232. div.setClassName(THEME_VERSION_CLASSNAME);
  233. RootPanel.get().getElement().appendChild(div);
  234. String version = getComputedStyle(div, ":after", "content");
  235. div.removeFromParent();
  236. if (version != null) {
  237. // String version = new ComputedStyle(div).getProperty("content");
  238. version = version.replace("'", "");
  239. version = version.replace("\"", "");
  240. }
  241. return version;
  242. }
  243. private native String getComputedStyle(Element elem, String pseudoElement,
  244. String property)
  245. /*-{
  246. if ($wnd.document.defaultView && $wnd.document.defaultView.getComputedStyle) {
  247. return $wnd.document.defaultView.getComputedStyle(elem, pseudoElement)[property];
  248. } else {
  249. return null;
  250. }
  251. }-*/;
  252. /**
  253. * Removes all content
  254. *
  255. * @since 7.1
  256. */
  257. private void clear() {
  258. content.getElement().setInnerHTML("");
  259. }
  260. /*
  261. * (non-Javadoc)
  262. *
  263. * @see com.vaadin.client.debug.internal.Section#hide()
  264. */
  265. @Override
  266. public void hide() {
  267. refresher.cancel();
  268. }
  269. /*
  270. * (non-Javadoc)
  271. *
  272. * @see com.vaadin.client.debug.internal.Section#meta(com.vaadin.client.
  273. * ApplicationConnection, com.vaadin.client.ValueMap)
  274. */
  275. @Override
  276. public void meta(ApplicationConnection ac, ValueMap meta) {
  277. }
  278. /*
  279. * (non-Javadoc)
  280. *
  281. * @see com.vaadin.client.debug.internal.Section#uidl(com.vaadin.client.
  282. * ApplicationConnection, com.vaadin.client.ValueMap)
  283. */
  284. @Override
  285. public void uidl(ApplicationConnection ac, ValueMap uidl) {
  286. }
  287. }