Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

UIConnector.java 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. /*
  2. * Copyright 2000-2013 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.ui.ui;
  17. import java.util.ArrayList;
  18. import java.util.Iterator;
  19. import java.util.List;
  20. import com.google.gwt.core.client.Scheduler;
  21. import com.google.gwt.core.client.Scheduler.ScheduledCommand;
  22. import com.google.gwt.dom.client.Document;
  23. import com.google.gwt.dom.client.Element;
  24. import com.google.gwt.dom.client.HeadElement;
  25. import com.google.gwt.dom.client.LinkElement;
  26. import com.google.gwt.dom.client.NativeEvent;
  27. import com.google.gwt.dom.client.Style;
  28. import com.google.gwt.dom.client.Style.Position;
  29. import com.google.gwt.dom.client.StyleInjector;
  30. import com.google.gwt.event.dom.client.ScrollEvent;
  31. import com.google.gwt.event.dom.client.ScrollHandler;
  32. import com.google.gwt.event.logical.shared.ResizeEvent;
  33. import com.google.gwt.event.logical.shared.ResizeHandler;
  34. import com.google.gwt.http.client.URL;
  35. import com.google.gwt.user.client.Command;
  36. import com.google.gwt.user.client.DOM;
  37. import com.google.gwt.user.client.Event;
  38. import com.google.gwt.user.client.History;
  39. import com.google.gwt.user.client.Timer;
  40. import com.google.gwt.user.client.Window;
  41. import com.google.gwt.user.client.Window.Location;
  42. import com.google.gwt.user.client.ui.RootPanel;
  43. import com.google.gwt.user.client.ui.Widget;
  44. import com.google.web.bindery.event.shared.HandlerRegistration;
  45. import com.vaadin.client.ApplicationConnection;
  46. import com.vaadin.client.ApplicationConnection.ApplicationStoppedEvent;
  47. import com.vaadin.client.BrowserInfo;
  48. import com.vaadin.client.ComponentConnector;
  49. import com.vaadin.client.ConnectorHierarchyChangeEvent;
  50. import com.vaadin.client.Focusable;
  51. import com.vaadin.client.Paintable;
  52. import com.vaadin.client.ServerConnector;
  53. import com.vaadin.client.UIDL;
  54. import com.vaadin.client.VConsole;
  55. import com.vaadin.client.ValueMap;
  56. import com.vaadin.client.communication.StateChangeEvent;
  57. import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler;
  58. import com.vaadin.client.ui.AbstractSingleComponentContainerConnector;
  59. import com.vaadin.client.ui.ClickEventHandler;
  60. import com.vaadin.client.ui.ShortcutActionHandler;
  61. import com.vaadin.client.ui.VNotification;
  62. import com.vaadin.client.ui.VOverlay;
  63. import com.vaadin.client.ui.VUI;
  64. import com.vaadin.client.ui.layout.MayScrollChildren;
  65. import com.vaadin.client.ui.window.WindowConnector;
  66. import com.vaadin.server.Page.Styles;
  67. import com.vaadin.shared.MouseEventDetails;
  68. import com.vaadin.shared.communication.MethodInvocation;
  69. import com.vaadin.shared.ui.ComponentStateUtil;
  70. import com.vaadin.shared.ui.Connect;
  71. import com.vaadin.shared.ui.Connect.LoadStyle;
  72. import com.vaadin.shared.ui.ui.DebugWindowClientRpc;
  73. import com.vaadin.shared.ui.ui.DebugWindowServerRpc;
  74. import com.vaadin.shared.ui.ui.PageClientRpc;
  75. import com.vaadin.shared.ui.ui.PageState;
  76. import com.vaadin.shared.ui.ui.ScrollClientRpc;
  77. import com.vaadin.shared.ui.ui.UIClientRpc;
  78. import com.vaadin.shared.ui.ui.UIConstants;
  79. import com.vaadin.shared.ui.ui.UIServerRpc;
  80. import com.vaadin.shared.ui.ui.UIState;
  81. import com.vaadin.ui.UI;
  82. @Connect(value = UI.class, loadStyle = LoadStyle.EAGER)
  83. public class UIConnector extends AbstractSingleComponentContainerConnector
  84. implements Paintable, MayScrollChildren {
  85. private HandlerRegistration childStateChangeHandlerRegistration;
  86. private final StateChangeHandler childStateChangeHandler = new StateChangeHandler() {
  87. @Override
  88. public void onStateChanged(StateChangeEvent stateChangeEvent) {
  89. // TODO Should use a more specific handler that only reacts to
  90. // size changes
  91. onChildSizeChange();
  92. }
  93. };
  94. @Override
  95. protected void init() {
  96. super.init();
  97. registerRpc(PageClientRpc.class, new PageClientRpc() {
  98. @Override
  99. public void reload() {
  100. Window.Location.reload();
  101. }
  102. });
  103. registerRpc(ScrollClientRpc.class, new ScrollClientRpc() {
  104. @Override
  105. public void setScrollTop(int scrollTop) {
  106. getWidget().getElement().setScrollTop(scrollTop);
  107. }
  108. @Override
  109. public void setScrollLeft(int scrollLeft) {
  110. getWidget().getElement().setScrollLeft(scrollLeft);
  111. }
  112. });
  113. registerRpc(UIClientRpc.class, new UIClientRpc() {
  114. @Override
  115. public void uiClosed(final boolean sessionExpired) {
  116. Scheduler.get().scheduleDeferred(new ScheduledCommand() {
  117. @Override
  118. public void execute() {
  119. // Only notify user if we're still running and not eg.
  120. // navigating away (#12298)
  121. if (getConnection().isApplicationRunning()) {
  122. if (sessionExpired) {
  123. getConnection().showSessionExpiredError(null);
  124. } else {
  125. getState().enabled = false;
  126. updateEnabledState(getState().enabled);
  127. }
  128. getConnection().setApplicationRunning(false);
  129. }
  130. }
  131. });
  132. }
  133. });
  134. registerRpc(DebugWindowClientRpc.class, new DebugWindowClientRpc() {
  135. @Override
  136. public void reportLayoutProblems(String json) {
  137. VConsole.printLayoutProblems(getValueMap(json), getConnection());
  138. }
  139. private native ValueMap getValueMap(String json)
  140. /*-{
  141. return JSON.parse(json);
  142. }-*/;
  143. });
  144. getWidget().addResizeHandler(new ResizeHandler() {
  145. @Override
  146. public void onResize(ResizeEvent event) {
  147. getRpcProxy(UIServerRpc.class).resize(event.getHeight(),
  148. event.getWidth(), Window.getClientWidth(),
  149. Window.getClientHeight());
  150. if (getState().immediate || getPageState().hasResizeListeners) {
  151. getConnection().sendPendingVariableChanges();
  152. }
  153. }
  154. });
  155. getWidget().addScrollHandler(new ScrollHandler() {
  156. private int lastSentScrollTop = Integer.MAX_VALUE;
  157. private int lastSentScrollLeft = Integer.MAX_VALUE;
  158. @Override
  159. public void onScroll(ScrollEvent event) {
  160. Element element = getWidget().getElement();
  161. int newScrollTop = element.getScrollTop();
  162. int newScrollLeft = element.getScrollLeft();
  163. if (newScrollTop != lastSentScrollTop
  164. || newScrollLeft != lastSentScrollLeft) {
  165. lastSentScrollTop = newScrollTop;
  166. lastSentScrollLeft = newScrollLeft;
  167. getRpcProxy(UIServerRpc.class).scroll(newScrollTop,
  168. newScrollLeft);
  169. }
  170. }
  171. });
  172. }
  173. private native void open(String url, String name)
  174. /*-{
  175. $wnd.open(url, name);
  176. }-*/;
  177. @Override
  178. public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) {
  179. getWidget().id = getConnectorId();
  180. boolean firstPaint = getWidget().connection == null;
  181. getWidget().connection = client;
  182. getWidget().immediate = getState().immediate;
  183. getWidget().resizeLazy = uidl.hasAttribute(UIConstants.RESIZE_LAZY);
  184. String newTheme = uidl.getStringAttribute("theme");
  185. if (getWidget().theme != null && !newTheme.equals(getWidget().theme)) {
  186. // Complete page refresh is needed due css can affect layout
  187. // calculations etc
  188. getWidget().reloadHostPage();
  189. } else {
  190. getWidget().theme = newTheme;
  191. }
  192. // this also implicitly removes old styles
  193. String styles = "";
  194. styles += getWidget().getStylePrimaryName() + " ";
  195. if (ComponentStateUtil.hasStyles(getState())) {
  196. for (String style : getState().styles) {
  197. styles += style + " ";
  198. }
  199. }
  200. if (!client.getConfiguration().isStandalone()) {
  201. styles += getWidget().getStylePrimaryName() + "-embedded";
  202. }
  203. getWidget().setStyleName(styles.trim());
  204. getWidget().makeScrollable();
  205. clickEventHandler.handleEventHandlerRegistration();
  206. // Process children
  207. int childIndex = 0;
  208. // Open URL:s
  209. boolean isClosed = false; // was this window closed?
  210. while (childIndex < uidl.getChildCount()
  211. && "open".equals(uidl.getChildUIDL(childIndex).getTag())) {
  212. final UIDL open = uidl.getChildUIDL(childIndex);
  213. final String url = client.translateVaadinUri(open
  214. .getStringAttribute("src"));
  215. final String target = open.getStringAttribute("name");
  216. if (target == null) {
  217. // source will be opened to this browser window, but we may have
  218. // to finish rendering this window in case this is a download
  219. // (and window stays open).
  220. Scheduler.get().scheduleDeferred(new Command() {
  221. @Override
  222. public void execute() {
  223. VUI.goTo(url);
  224. }
  225. });
  226. } else if ("_self".equals(target)) {
  227. // This window is closing (for sure). Only other opens are
  228. // relevant in this change. See #3558, #2144
  229. isClosed = true;
  230. VUI.goTo(url);
  231. } else {
  232. String options;
  233. boolean alwaysAsPopup = true;
  234. if (open.hasAttribute("popup")) {
  235. alwaysAsPopup = open.getBooleanAttribute("popup");
  236. }
  237. if (alwaysAsPopup) {
  238. if (open.hasAttribute("border")) {
  239. if (open.getStringAttribute("border").equals("minimal")) {
  240. options = "menubar=yes,location=no,status=no";
  241. } else {
  242. options = "menubar=no,location=no,status=no";
  243. }
  244. } else {
  245. options = "resizable=yes,menubar=yes,toolbar=yes,directories=yes,location=yes,scrollbars=yes,status=yes";
  246. }
  247. if (open.hasAttribute("width")) {
  248. int w = open.getIntAttribute("width");
  249. options += ",width=" + w;
  250. }
  251. if (open.hasAttribute("height")) {
  252. int h = open.getIntAttribute("height");
  253. options += ",height=" + h;
  254. }
  255. Window.open(url, target, options);
  256. } else {
  257. open(url, target);
  258. }
  259. }
  260. childIndex++;
  261. }
  262. if (isClosed) {
  263. // We're navigating away, so stop the application.
  264. client.setApplicationRunning(false);
  265. return;
  266. }
  267. // Handle other UIDL children
  268. UIDL childUidl;
  269. while ((childUidl = uidl.getChildUIDL(childIndex++)) != null) {
  270. String tag = childUidl.getTag().intern();
  271. if (tag == "actions") {
  272. if (getWidget().actionHandler == null) {
  273. getWidget().actionHandler = new ShortcutActionHandler(
  274. getWidget().id, client);
  275. }
  276. getWidget().actionHandler.updateActionMap(childUidl);
  277. } else if (tag == "notifications") {
  278. for (final Iterator<?> it = childUidl.getChildIterator(); it
  279. .hasNext();) {
  280. final UIDL notification = (UIDL) it.next();
  281. VNotification.showNotification(client, notification);
  282. }
  283. } else if (tag == "css-injections") {
  284. injectCSS(childUidl);
  285. }
  286. }
  287. if (uidl.hasAttribute("focused")) {
  288. // set focused component when render phase is finished
  289. Scheduler.get().scheduleDeferred(new Command() {
  290. @Override
  291. public void execute() {
  292. ComponentConnector paintable = (ComponentConnector) uidl
  293. .getPaintableAttribute("focused", getConnection());
  294. if (paintable == null) {
  295. // Do not try to focus invisible components which not
  296. // present in UIDL
  297. return;
  298. }
  299. final Widget toBeFocused = paintable.getWidget();
  300. /*
  301. * Two types of Widgets can be focused, either implementing
  302. * GWT HasFocus of a thinner Vaadin specific Focusable
  303. * interface.
  304. */
  305. if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) {
  306. final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused;
  307. toBeFocusedWidget.setFocus(true);
  308. } else if (toBeFocused instanceof Focusable) {
  309. ((Focusable) toBeFocused).focus();
  310. } else {
  311. VConsole.log("Could not focus component");
  312. }
  313. }
  314. });
  315. }
  316. // Add window listeners on first paint, to prevent premature
  317. // variablechanges
  318. if (firstPaint) {
  319. Window.addWindowClosingHandler(getWidget());
  320. Window.addResizeHandler(getWidget());
  321. }
  322. if (uidl.hasAttribute("scrollTo")) {
  323. final ComponentConnector connector = (ComponentConnector) uidl
  324. .getPaintableAttribute("scrollTo", getConnection());
  325. scrollIntoView(connector);
  326. }
  327. if (uidl.hasAttribute(UIConstants.LOCATION_VARIABLE)) {
  328. String location = uidl
  329. .getStringAttribute(UIConstants.LOCATION_VARIABLE);
  330. String newFragment;
  331. int fragmentIndex = location.indexOf('#');
  332. if (fragmentIndex >= 0) {
  333. // Decode fragment to avoid double encoding (#10769)
  334. newFragment = URL.decodePathSegment(location
  335. .substring(fragmentIndex + 1));
  336. if (newFragment.isEmpty()
  337. && Location.getHref().indexOf('#') == -1) {
  338. // Ensure there is a trailing # even though History and
  339. // Location.getHash() treat null and "" the same way.
  340. Location.assign(Location.getHref() + "#");
  341. }
  342. } else {
  343. // No fragment in server-side location, but can't completely
  344. // remove the browser fragment since that would reload the page
  345. newFragment = "";
  346. }
  347. getWidget().currentFragment = newFragment;
  348. if (!newFragment.equals(History.getToken())) {
  349. History.newItem(newFragment, true);
  350. }
  351. }
  352. if (firstPaint) {
  353. // Queue the initial window size to be sent with the following
  354. // request.
  355. Scheduler.get().scheduleDeferred(new ScheduledCommand() {
  356. @Override
  357. public void execute() {
  358. getWidget().sendClientResized();
  359. }
  360. });
  361. }
  362. }
  363. /**
  364. * Reads CSS strings and resources injected by {@link Styles#inject} from
  365. * the UIDL stream.
  366. *
  367. * @param uidl
  368. * The uidl which contains "css-resource" and "css-string" tags
  369. */
  370. private void injectCSS(UIDL uidl) {
  371. final HeadElement head = HeadElement.as(Document.get()
  372. .getElementsByTagName(HeadElement.TAG).getItem(0));
  373. /*
  374. * Search the UIDL stream for CSS resources and strings to be injected.
  375. */
  376. for (Iterator<?> it = uidl.getChildIterator(); it.hasNext();) {
  377. UIDL cssInjectionsUidl = (UIDL) it.next();
  378. // Check if we have resources to inject
  379. if (cssInjectionsUidl.getTag().equals("css-resource")) {
  380. String url = getWidget().connection
  381. .translateVaadinUri(cssInjectionsUidl
  382. .getStringAttribute("url"));
  383. LinkElement link = LinkElement.as(DOM
  384. .createElement(LinkElement.TAG));
  385. link.setRel("stylesheet");
  386. link.setHref(url);
  387. link.setType("text/css");
  388. head.appendChild(link);
  389. // Check if we have CSS string to inject
  390. } else if (cssInjectionsUidl.getTag().equals("css-string")) {
  391. for (Iterator<?> it2 = cssInjectionsUidl.getChildIterator(); it2
  392. .hasNext();) {
  393. StyleInjector.injectAtEnd((String) it2.next());
  394. StyleInjector.flush();
  395. }
  396. }
  397. }
  398. }
  399. public void init(String rootPanelId,
  400. ApplicationConnection applicationConnection) {
  401. DOM.sinkEvents(getWidget().getElement(), Event.ONKEYDOWN
  402. | Event.ONSCROLL);
  403. RootPanel root = RootPanel.get(rootPanelId);
  404. // Remove the v-app-loading or any splash screen added inside the div by
  405. // the user
  406. root.getElement().setInnerHTML("");
  407. String themeName = applicationConnection.getConfiguration()
  408. .getThemeName();
  409. root.addStyleName(themeName);
  410. root.add(getWidget());
  411. // Set default tab index before focus call. State change handler
  412. // will update this later if needed.
  413. getWidget().setTabIndex(1);
  414. if (applicationConnection.getConfiguration().isStandalone()) {
  415. // set focus to iview element by default to listen possible keyboard
  416. // shortcuts. For embedded applications this is unacceptable as we
  417. // don't want to steal focus from the main page nor we don't want
  418. // side-effects from focusing (scrollIntoView).
  419. getWidget().getElement().focus();
  420. }
  421. applicationConnection.addHandler(
  422. ApplicationConnection.ApplicationStoppedEvent.TYPE,
  423. new ApplicationConnection.ApplicationStoppedHandler() {
  424. @Override
  425. public void onApplicationStopped(
  426. ApplicationStoppedEvent event) {
  427. // Stop any polling
  428. if (pollTimer != null) {
  429. pollTimer.cancel();
  430. pollTimer = null;
  431. }
  432. }
  433. });
  434. }
  435. private ClickEventHandler clickEventHandler = new ClickEventHandler(this) {
  436. @Override
  437. protected void fireClick(NativeEvent event,
  438. MouseEventDetails mouseDetails) {
  439. getRpcProxy(UIServerRpc.class).click(mouseDetails);
  440. }
  441. };
  442. private Timer pollTimer = null;
  443. @Override
  444. public void updateCaption(ComponentConnector component) {
  445. // NOP The main view never draws caption for its layout
  446. }
  447. @Override
  448. public VUI getWidget() {
  449. return (VUI) super.getWidget();
  450. }
  451. protected void onChildSizeChange() {
  452. ComponentConnector child = getContent();
  453. if (child == null) {
  454. return;
  455. }
  456. Style childStyle = child.getWidget().getElement().getStyle();
  457. /*
  458. * Must set absolute position if the child has relative height and
  459. * there's a chance of horizontal scrolling as some browsers will
  460. * otherwise not take the scrollbar into account when calculating the
  461. * height. Assuming v-ui does not have an undefined width for now, see
  462. * #8460.
  463. */
  464. if (child.isRelativeHeight() && !BrowserInfo.get().isIE9()) {
  465. childStyle.setPosition(Position.ABSOLUTE);
  466. } else {
  467. childStyle.clearPosition();
  468. }
  469. }
  470. /**
  471. * Checks if the given sub window is a child of this UI Connector
  472. *
  473. * @deprecated Should be replaced by a more generic mechanism for getting
  474. * non-ComponentConnector children
  475. * @param wc
  476. * @return
  477. */
  478. @Deprecated
  479. public boolean hasSubWindow(WindowConnector wc) {
  480. return getChildComponents().contains(wc);
  481. }
  482. /**
  483. * Return an iterator for current subwindows. This method is meant for
  484. * testing purposes only.
  485. *
  486. * @return
  487. */
  488. public List<WindowConnector> getSubWindows() {
  489. ArrayList<WindowConnector> windows = new ArrayList<WindowConnector>();
  490. for (ComponentConnector child : getChildComponents()) {
  491. if (child instanceof WindowConnector) {
  492. windows.add((WindowConnector) child);
  493. }
  494. }
  495. return windows;
  496. }
  497. @Override
  498. public UIState getState() {
  499. return (UIState) super.getState();
  500. }
  501. /**
  502. * Returns the state of the Page associated with the UI.
  503. * <p>
  504. * Note that state is considered an internal part of the connector. You
  505. * should not rely on the state object outside of the connector who owns it.
  506. * If you depend on the state of other connectors you should use their
  507. * public API instead of their state object directly. The page state might
  508. * not be an independent state object but can be embedded in UI state.
  509. * </p>
  510. *
  511. * @since 7.1
  512. * @return state object of the page
  513. */
  514. public PageState getPageState() {
  515. return getState().pageState;
  516. }
  517. @Override
  518. public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {
  519. ComponentConnector oldChild = null;
  520. ComponentConnector newChild = getContent();
  521. for (ComponentConnector c : event.getOldChildren()) {
  522. if (!(c instanceof WindowConnector)) {
  523. oldChild = c;
  524. break;
  525. }
  526. }
  527. if (oldChild != newChild) {
  528. if (childStateChangeHandlerRegistration != null) {
  529. childStateChangeHandlerRegistration.removeHandler();
  530. childStateChangeHandlerRegistration = null;
  531. }
  532. if (newChild != null) {
  533. getWidget().setWidget(newChild.getWidget());
  534. childStateChangeHandlerRegistration = newChild
  535. .addStateChangeHandler(childStateChangeHandler);
  536. // Must handle new child here as state change events are already
  537. // fired
  538. onChildSizeChange();
  539. } else {
  540. getWidget().setWidget(null);
  541. }
  542. }
  543. for (ComponentConnector c : getChildComponents()) {
  544. if (c instanceof WindowConnector) {
  545. WindowConnector wc = (WindowConnector) c;
  546. wc.setWindowOrderAndPosition();
  547. }
  548. }
  549. // Close removed sub windows
  550. for (ComponentConnector c : event.getOldChildren()) {
  551. if (c.getParent() != this && c instanceof WindowConnector) {
  552. ((WindowConnector) c).getWidget().hide();
  553. }
  554. }
  555. }
  556. @Override
  557. public boolean hasTooltip() {
  558. /*
  559. * Always return true so there's always top level tooltip handler that
  560. * takes care of hiding tooltips whenever the mouse is moved somewhere
  561. * else.
  562. */
  563. return true;
  564. }
  565. /**
  566. * Tries to scroll the viewport so that the given connector is in view.
  567. *
  568. * @param componentConnector
  569. * The connector which should be visible
  570. *
  571. */
  572. public void scrollIntoView(final ComponentConnector componentConnector) {
  573. if (componentConnector == null) {
  574. return;
  575. }
  576. Scheduler.get().scheduleDeferred(new Command() {
  577. @Override
  578. public void execute() {
  579. componentConnector.getWidget().getElement().scrollIntoView();
  580. }
  581. });
  582. }
  583. @Override
  584. public void onStateChanged(StateChangeEvent stateChangeEvent) {
  585. super.onStateChanged(stateChangeEvent);
  586. if (stateChangeEvent.hasPropertyChanged("tooltipConfiguration")) {
  587. getConnection().getVTooltip().setCloseTimeout(
  588. getState().tooltipConfiguration.closeTimeout);
  589. getConnection().getVTooltip().setOpenDelay(
  590. getState().tooltipConfiguration.openDelay);
  591. getConnection().getVTooltip().setQuickOpenDelay(
  592. getState().tooltipConfiguration.quickOpenDelay);
  593. getConnection().getVTooltip().setQuickOpenTimeout(
  594. getState().tooltipConfiguration.quickOpenTimeout);
  595. getConnection().getVTooltip().setMaxWidth(
  596. getState().tooltipConfiguration.maxWidth);
  597. }
  598. if (stateChangeEvent
  599. .hasPropertyChanged("loadingIndicatorConfiguration")) {
  600. getConnection().getLoadingIndicator().setFirstDelay(
  601. getState().loadingIndicatorConfiguration.firstDelay);
  602. getConnection().getLoadingIndicator().setSecondDelay(
  603. getState().loadingIndicatorConfiguration.secondDelay);
  604. getConnection().getLoadingIndicator().setThirdDelay(
  605. getState().loadingIndicatorConfiguration.thirdDelay);
  606. }
  607. if (stateChangeEvent.hasPropertyChanged("pollInterval")) {
  608. configurePolling();
  609. }
  610. if (stateChangeEvent.hasPropertyChanged("pageState.title")) {
  611. String title = getState().pageState.title;
  612. if (title != null) {
  613. com.google.gwt.user.client.Window.setTitle(title);
  614. }
  615. }
  616. if (stateChangeEvent.hasPropertyChanged("pushConfiguration")) {
  617. getConnection().setPushEnabled(
  618. getState().pushConfiguration.mode.isEnabled());
  619. }
  620. if (stateChangeEvent.hasPropertyChanged("overlayContainerLabel")) {
  621. VOverlay.setOverlayContainerLabel(getConnection(),
  622. getState().overlayContainerLabel);
  623. }
  624. }
  625. private void configurePolling() {
  626. if (pollTimer != null) {
  627. pollTimer.cancel();
  628. pollTimer = null;
  629. }
  630. if (getState().pollInterval >= 0) {
  631. pollTimer = new Timer() {
  632. @Override
  633. public void run() {
  634. if (getState().pollInterval < 0) {
  635. // Polling has been cancelled server side
  636. pollTimer.cancel();
  637. pollTimer = null;
  638. return;
  639. }
  640. getRpcProxy(UIServerRpc.class).poll();
  641. // Send changes even though poll is @Delayed
  642. getConnection().sendPendingVariableChanges();
  643. }
  644. };
  645. pollTimer.scheduleRepeating(getState().pollInterval);
  646. } else {
  647. // Ensure no more polls are sent as polling has been disabled
  648. getConnection().removePendingInvocations(
  649. new MethodInvocation(getConnectorId(), UIServerRpc.class
  650. .getName(), "poll"));
  651. }
  652. }
  653. /**
  654. * Invokes the layout analyzer on the server
  655. *
  656. * @since 7.1
  657. */
  658. public void analyzeLayouts() {
  659. getRpcProxy(DebugWindowServerRpc.class).analyzeLayouts();
  660. }
  661. /**
  662. * Sends a request to the server to print details to console that will help
  663. * the developer to locate the corresponding server-side connector in the
  664. * source code.
  665. *
  666. * @since 7.1
  667. * @param serverConnector
  668. * the connector to locate
  669. */
  670. public void showServerDebugInfo(ServerConnector serverConnector) {
  671. getRpcProxy(DebugWindowServerRpc.class).showServerDebugInfo(
  672. serverConnector);
  673. }
  674. }