123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- /*
- @ITMillApache2LicenseForJavaFiles@
- */
-
- package com.itmill.toolkit.terminal.gwt.client;
-
- import java.util.Iterator;
-
- import com.google.gwt.user.client.Element;
- import com.google.gwt.user.client.ui.HasWidgets;
- import com.google.gwt.user.client.ui.Widget;
-
- public class Util {
-
- /**
- * Helper method for debugging purposes.
- *
- * Stops execution on firefox browsers on a breakpoint.
- *
- */
- public static native void browserDebugger() /*-{
- if(window.console)
- debugger;
- }-*/;
-
- /**
- * Detects if current browser is IE.
- *
- * @return true if IE
- */
- public static native boolean isIE() /*-{
- var browser=$wnd.navigator.appName;
- if (browser=="Microsoft Internet Explorer") {
- return true;
- }
- return false;
- }-*/;
-
- /**
- * Detects if current browser is IE6.
- *
- * @return true if IE6
- */
- public static native boolean isIE6() /*-{
- var browser=$wnd.navigator.appName;
- if (browser=="Microsoft Internet Explorer") {
- var ua = navigator.userAgent;
- var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
- if (re.exec(ua) != null)
- rv = parseFloat(RegExp.$1);
- if(rv == 6) return true;
- }
- return false;
- }-*/;
-
- /**
- * Nulls oncontextmenu function on given element. We need to manually clear
- * context menu events due bad browsers memory leaks, since GWT don't
- * support them.
- *
- * @param el
- */
- public native static void removeContextMenuEvent(Element el) /*-{
- el.oncontextmenu = null;
- }-*/;
-
- /**
- * Traverses recursively ancestors until ContainerResizedListener child
- * widget is found. They will delegate it futher if needed.
- *
- * @param container
- */
- public static void runDescendentsLayout(HasWidgets container) {
- final Iterator childWidgets = container.iterator();
- while (childWidgets.hasNext()) {
- final Widget child = (Widget) childWidgets.next();
- if (child instanceof ContainerResizedListener) {
- ((ContainerResizedListener) child).iLayout();
- } else if (child instanceof HasWidgets) {
- final HasWidgets childContainer = (HasWidgets) child;
- runDescendentsLayout(childContainer);
- }
- }
- }
-
- /**
- * Returns closest parent Widget in hierarchy that implements Container
- * interface
- *
- * @param component
- * @return closest parent Container
- */
- public static Container getParentLayout(Widget component) {
- Widget parent = component.getParent();
- while (parent != null && !(parent instanceof Container)) {
- parent = parent.getParent();
- }
- if (parent != null && ((Container) parent).hasChildComponent(component)) {
- return (Container) parent;
- }
- return null;
- }
- }
|