001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008:
009: package com.gwtext.client.core;
010:
011: import com.google.gwt.user.client.Element;
012: import com.gwtext.client.widgets.Component;
013:
014: /**
015: * Ext core utilities and functions.
016: */
017: public class Ext {
018:
019: /**
020: * URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent the IE insecure content
021: * warning (defaults to javascript:false).
022: *
023: * @param url the url
024: */
025: public static native void setSslSecureUrl(String url)/*-{
026: $wnd.Ext.SSL_SECURE_URL = url;
027: }-*/;
028:
029: /**
030: * True to automatically uncache orphaned Ext.Elements periodically (defaults to true).
031: *
032: * @param enableGarbageCollector true to enable GC
033: */
034: public static native void setEnableGarbageCollector(
035: boolean enableGarbageCollector)/*-{
036: $wnd.Ext.enableGarbageCollector = enableGarbageCollector;
037: }-*/;
038:
039: /**
040: * Returns is Garbage Collector is enabled.
041: *
042: * @return true if GC enabled
043: */
044: public static native boolean isEnableGarbageCollector()/*-{
045: return $wnd.Ext.enableGarbageCollector;
046: }-*/;
047:
048: /**
049: * True to automatically purge event listeners after uncaching an element (defaults to false). Note: this only happens if enableGarbageCollector is true.
050: *
051: * @param enableListenerCollection true to enable listener collection
052: */
053: public static native void setEnableListenerCollection(
054: boolean enableListenerCollection)/*-{
055: $wnd.Ext.enableListenerCollection = enableListenerCollection;
056: }-*/;
057:
058: /**
059: * Retruns true if listener collection is true.
060: *
061: * @return true if listener collection is enabled
062: */
063: public static native boolean isEnableListenerCollection()/*-{
064: return $wnd.Ext.enableListenerCollection;
065: }-*/;
066:
067: /**
068: * @return true if bodex box
069: */
070: public static native boolean isBorderBox()/*-{
071: return $wnd.Ext.isBorderBox;
072: }-*/;
073:
074: /**
075: * @return true if Gecko broswer
076: */
077: public static native boolean isGecko()/*-{
078: return $wnd.Ext.isGecko;
079: }-*/;
080:
081: /**
082: * @return true if IE
083: */
084: public static native boolean isIE()/*-{
085: return $wnd.Ext.isIE;
086: }-*/;
087:
088: /**
089: * @return true if IE6
090: */
091: public static native boolean isIE6()/*-{
092: return $wnd.Ext.isIE6;
093: }-*/;
094:
095: /**
096: * @return true if IE7
097: */
098: public static native boolean isIE7()/*-{
099: return $wnd.Ext.isIE7;
100: }-*/;
101:
102: /**
103: * @return true if Linux OS
104: */
105: public static native boolean isLinux()/*-{
106: return $wnd.Ext.isLinux;
107: }-*/;
108:
109: /**
110: * @return true if Mac
111: */
112: public static native boolean isMac()/*-{
113: return $wnd.Ext.isMac;
114: }-*/;
115:
116: /**
117: * @return true if running under Adobe AIR
118: */
119: public static native boolean isAir()/*-{
120: return $wnd.Ext.isAir;
121: }-*/;
122:
123: /**
124: * @return true if Opera
125: */
126: public static native boolean isOpera()/*-{
127: return $wnd.Ext.isOpera;
128: }-*/;
129:
130: /**
131: * @return true when the document is fully initialized and ready for action
132: */
133: public static native boolean isReady()/*-{
134: return $wnd.Ext.isReady;
135: }-*/;
136:
137: /**
138: * @return true if Safari
139: */
140: public static native boolean isSafari()/*-{
141: return $wnd.Ext.isSafari;
142: }-*/;
143:
144: /**
145: * @return true if the page is running over SSL
146: */
147: public static native boolean isSecure()/*-{
148: return $wnd.Ext.isSecure;
149: }-*/;
150:
151: /**
152: * @return true if the browser is in strict mode
153: */
154: public static native boolean isStrict()/*-{
155: return $wnd.Ext.isStrict;
156: }-*/;
157:
158: /**
159: * @return true if Windows OS
160: */
161: public static native boolean isWindows()/*-{
162: return $wnd.Ext.isWindows;
163: }-*/;
164:
165: /**
166: * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash, you
167: * may want to set this to true.
168: *
169: * @param useShims true to use shims
170: */
171: public static native void setUseShims(boolean useShims)/*-{
172: $wnd.Ext.useShims = useShims;
173: }-*/;
174:
175: /**
176: * @return true if use shims.
177: */
178: public static native boolean isUseShims()/*-{
179: return $wnd.Ext.useShims;
180: }-*/;
181:
182: /**
183: * Escapes the passed string for use in a regular expression.
184: *
185: * @param str the String to escape
186: * @return escaped String
187: */
188: public static native String escapeRe(String str)/*-{
189: return $wnd.Ext.escapeRe(str);
190: }-*/;
191:
192: //made package protected. Users don't need to call this anymore since it is handled internally on
193: //applicaiotn startup.
194: native static void setBlankImageUrl(String url) /*-{
195: $wnd.Ext.BLANK_IMAGE_URL = url;
196: }-*/;
197:
198: /**
199: * Method to retrieve Element objects. Uses simple caching to consistently return the same object. Automatically fixes if an object was recreated with the same id via AJAX or DOM.
200: *
201: * @param id element ID
202: * @return the element
203: */
204: public static native ExtElement get(String id) /*-{
205: var el = $wnd.Ext.get(id);
206: return el == null || el === undefined ? null : @com.gwtext.client.core.ExtElement::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(el);
207: }-*/;
208:
209: /**
210: * Method to retrieve Element objects. Uses simple caching to consistently return the same object. Automatically fixes if an object was recreated with the same id via AJAX or DOM.
211: *
212: * @param element the element
213: * @return the element
214: */
215: public static native ExtElement get(Element element) /*-{
216: var el = $wnd.Ext.get(element);
217: return el == null ? null : @com.gwtext.client.core.ExtElement::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(el);
218: }-*/;
219:
220: /**
221: * Attempts to destroy the objects by removing all event listeners, removing them from the DOM (if applicable) and calling their destroy functions (if available).
222: *
223: * @param element the element to destroy
224: */
225: public static native void destroy(ExtElement element) /*-{
226: var el = element.@com.gwtext.client.core.JsObject::getJsObj()();
227: $wnd.Ext.destroy(el);
228: }-*/;
229:
230: /**
231: * Attempts to destroy the component passed to it by removing all event listeners, removing them from the DOM (if applicable) and calling their destroy functions (if available).
232: *
233: * @param component the component to destroy
234: */
235: public static native void destroy(Component component) /*-{
236: var comp = component.@com.gwtext.client.widgets.Component::getJsObj()();
237: $wnd.Ext.destroy(comp);
238: }-*/;
239:
240: /**
241: * Returns the current HTML document object as an {@link ExtElement}.
242: *
243: * @return the document
244: */
245: public static native ExtElement getDoc() /*-{
246: var el = $wnd.Ext.getDoc();
247: return el == null ? null : @com.gwtext.client.core.ExtElement::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(el);
248: }-*/;
249:
250: /**
251: * Returns the current document body as an{@link ExtElement}.
252: *
253: * @return the document body
254: */
255: public static native ExtElement getBody() /*-{
256: var el = $wnd.Ext.getBody();
257: return el == null ? null : @com.gwtext.client.core.ExtElement::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(el);
258: }-*/;
259:
260: /**
261: * Gets the globally shared flyweight ExtElement, with the passed node as the active element. Do not store a reference
262: * to this element - the dom node can be overwritten by other code.
263: *
264: * @param id the element ID
265: * @return the ExtElement
266: */
267: public static native ExtElement fly(String id) /*-{
268: var el = $wnd.Ext.fly(id);
269: return el == null ? null : @com.gwtext.client.core.ExtElement::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(el);
270: }-*/;
271:
272: /**
273: * Gets the globally shared flyweight ExtElement, with the passed node as the active element. Do not store a reference
274: * to this element - the dom node can be overwritten by other code.
275: *
276: * @param id the element ID
277: * @param named allows for creation of named reusable flyweights to prevent conflicts (e.g. internally Ext uses "_internal")
278: * @return the ExtElement
279: */
280: public static native ExtElement fly(String id, String named) /*-{
281: var el = $wnd.Ext.fly(id, named);
282: return el == null ? null : @com.gwtext.client.core.ExtElement::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(el);
283: }-*/;
284:
285: /**
286: * Gets the globally shared flyweight ExtElement, with the passed node as the active element. Do not store a reference
287: * to this element - the dom node can be overwritten by other code.
288: *
289: * @param element the element
290: * @return the ExtElement
291: */
292: public static native ExtElement fly(Element element) /*-{
293: var el = $wnd.Ext.fly(element);
294: return el == null ? null : @com.gwtext.client.core.ExtElement::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(el);
295: }-*/;
296:
297: /**
298: * Gets the globally shared flyweight ExtElement, with the passed node as the active element. Do not store a reference
299: * to this element - the dom node can be overwritten by other code.
300: *
301: * @param element the element
302: * @param named allows for creation of named reusable flyweights to prevent conflicts (e.g. internally Ext uses "_internal")
303: * @return the ExtElement
304: */
305: public static native ExtElement fly(Element element, String named) /*-{
306: var el = $wnd.Ext.fly(element, named);
307: return el == null ? null : @com.gwtext.client.core.ExtElement::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(el);
308: }-*/;
309:
310: /**
311: * Generates unique ids.
312: *
313: * @return a unique ID
314: */
315: public static native String generateId()/*-{
316: return $wnd.Ext.id();
317: }-*/;
318:
319: /**
320: * Generates unique ids.
321: *
322: * @param prefix Id prefix (defaults "ext-gen")
323: * @return a unique ID
324: */
325: public static native String generateId(String prefix)/*-{
326: return $wnd.Ext.id(null, prefix);
327: }-*/;
328:
329: /**
330: * Fires when the document is ready (before onload and before images are loaded).
331: * Can alternatively use the GWT entry point mechanism.
332: *
333: * @param cb callback to execute
334: */
335: public static native void onReady(Function cb) /*-{
336: $wnd.Ext.onReady(function() {
337: cb.@com.gwtext.client.core.Function::execute()();
338: });
339: }-*/;
340:
341: /**
342: * Utility method to kick up Javascript debugger. Userful during development / troubleshooting where it is desired to step through
343: * Javascript code.
344: */
345: public static native void debugger()/*-{
346: debugger;
347: }-*/;
348: }
|