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.

Util.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.terminal.gwt.client;
  5. import java.util.Iterator;
  6. import com.google.gwt.user.client.Element;
  7. import com.google.gwt.user.client.ui.HasWidgets;
  8. import com.google.gwt.user.client.ui.Widget;
  9. public class Util {
  10. /**
  11. * Helper method for debugging purposes.
  12. *
  13. * Stops execution on firefox browsers on a breakpoint.
  14. *
  15. */
  16. public static native void browserDebugger() /*-{
  17. if(window.console)
  18. debugger;
  19. }-*/;
  20. /**
  21. * Detects if current browser is IE.
  22. *
  23. * @return true if IE
  24. */
  25. public static native boolean isIE() /*-{
  26. var browser=$wnd.navigator.appName;
  27. if (browser=="Microsoft Internet Explorer") {
  28. return true;
  29. }
  30. return false;
  31. }-*/;
  32. /**
  33. * Detects if current browser is IE6.
  34. *
  35. * @return true if IE6
  36. */
  37. public static native boolean isIE6() /*-{
  38. var browser=$wnd.navigator.appName;
  39. if (browser=="Microsoft Internet Explorer") {
  40. var ua = navigator.userAgent;
  41. var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
  42. if (re.exec(ua) != null)
  43. rv = parseFloat(RegExp.$1);
  44. if(rv == 6) return true;
  45. }
  46. return false;
  47. }-*/;
  48. /**
  49. * Nulls oncontextmenu function on given element. We need to manually clear
  50. * context menu events due bad browsers memory leaks, since GWT don't
  51. * support them.
  52. *
  53. * @param el
  54. */
  55. public native static void removeContextMenuEvent(Element el) /*-{
  56. el.oncontextmenu = null;
  57. }-*/;
  58. /**
  59. * Traverses recursively ancestors until ContainerResizedListener child
  60. * widget is found. They will delegate it futher if needed.
  61. *
  62. * @param container
  63. */
  64. public static void runDescendentsLayout(HasWidgets container) {
  65. final Iterator childWidgets = container.iterator();
  66. while (childWidgets.hasNext()) {
  67. final Widget child = (Widget) childWidgets.next();
  68. if (child instanceof ContainerResizedListener) {
  69. ((ContainerResizedListener) child).iLayout();
  70. } else if (child instanceof HasWidgets) {
  71. final HasWidgets childContainer = (HasWidgets) child;
  72. runDescendentsLayout(childContainer);
  73. }
  74. }
  75. }
  76. /**
  77. * Returns closest parent Widget in hierarchy that implements Container
  78. * interface
  79. *
  80. * @param component
  81. * @return closest parent Container
  82. */
  83. public static Container getParentLayout(Widget component) {
  84. Widget parent = component.getParent();
  85. while (parent != null && !(parent instanceof Container)) {
  86. parent = parent.getParent();
  87. }
  88. if (parent != null && ((Container) parent).hasChildComponent(component)) {
  89. return (Container) parent;
  90. }
  91. return null;
  92. }
  93. }