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.

VUriFragmentUtility.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.vaadin.terminal.gwt.client.ui;
  2. import com.google.gwt.dom.client.Document;
  3. import com.google.gwt.user.client.History;
  4. import com.google.gwt.user.client.HistoryListener;
  5. import com.google.gwt.user.client.ui.Widget;
  6. import com.vaadin.terminal.gwt.client.ApplicationConnection;
  7. import com.vaadin.terminal.gwt.client.BrowserInfo;
  8. import com.vaadin.terminal.gwt.client.Paintable;
  9. import com.vaadin.terminal.gwt.client.UIDL;
  10. /**
  11. * Client side implementation for UriFragmentUtility. Uses GWT's History object
  12. * as an implementation.
  13. *
  14. */
  15. public class VUriFragmentUtility extends Widget implements Paintable,
  16. HistoryListener {
  17. private String fragment;
  18. private ApplicationConnection client;
  19. private String paintableId;
  20. private boolean immediate;
  21. public VUriFragmentUtility() {
  22. setElement(Document.get().createDivElement());
  23. if (BrowserInfo.get().isIE6()) {
  24. getElement().getStyle().setProperty("overflow", "hidden");
  25. getElement().getStyle().setProperty("height", "0");
  26. }
  27. History.addHistoryListener(this);
  28. History.fireCurrentHistoryState();
  29. }
  30. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  31. if (client.updateComponent(this, uidl, false)) {
  32. return;
  33. }
  34. String uidlFragment = uidl.getStringVariable("fragment");
  35. immediate = uidl.getBooleanAttribute("immediate");
  36. if (this.client == null) {
  37. // initial paint has some special logic
  38. this.client = client;
  39. paintableId = uidl.getId();
  40. if (!fragment.equals(uidlFragment)) {
  41. // initial server side fragment (from link/bookmark/typed) does
  42. // not equal the one on
  43. // server, send initial fragment to server
  44. History.fireCurrentHistoryState();
  45. }
  46. } else {
  47. if (uidlFragment != null && !uidlFragment.equals(fragment)) {
  48. fragment = uidlFragment;
  49. // normal fragment change from server, add new history item
  50. History.newItem(uidlFragment, false);
  51. }
  52. }
  53. }
  54. public void onHistoryChanged(String historyToken) {
  55. fragment = historyToken;
  56. if (client != null) {
  57. client.updateVariable(paintableId, "fragment", fragment, immediate);
  58. }
  59. }
  60. }