PageRenderTime 513ms CodeModel.GetById 25ms RepoModel.GetById 2ms app.codeStats 0ms

/ngpm/com.sap.runlet.apps.opportunitymanagement.ui/gxt/src/com/extjs/gxt/ui/client/GXT.java

https://github.com/FURCAS-dev/FURCAS
Java | 381 lines | 178 code | 56 blank | 147 comment | 73 complexity | b0d9cd1ed5649fe97e859d35d2e5dda0 MD5 | raw file
  1. /*
  2. * Ext GWT - Ext for GWT
  3. * Copyright(c) 2007-2009, Ext JS, LLC.
  4. * licensing@extjs.com
  5. *
  6. * http://extjs.com/license
  7. */
  8. package com.extjs.gxt.ui.client;
  9. import java.util.Map;
  10. import com.extjs.gxt.ui.client.core.El;
  11. import com.extjs.gxt.ui.client.core.XDOM;
  12. import com.extjs.gxt.ui.client.image.XImages;
  13. import com.extjs.gxt.ui.client.messages.XMessages;
  14. import com.extjs.gxt.ui.client.state.CookieProvider;
  15. import com.extjs.gxt.ui.client.state.StateManager;
  16. import com.extjs.gxt.ui.client.util.CSS;
  17. import com.extjs.gxt.ui.client.util.Theme;
  18. import com.google.gwt.core.client.GWT;
  19. import com.google.gwt.user.client.DOM;
  20. import com.google.gwt.user.client.Element;
  21. import com.google.gwt.user.client.Timer;
  22. import com.google.gwt.user.client.Window;
  23. /**
  24. * GXT core utilities and functions.
  25. */
  26. public class GXT {
  27. /**
  28. * GXT images.
  29. */
  30. public static XImages IMAGES = (XImages) GWT.create(XImages.class);
  31. /**
  32. * GXT messages.
  33. */
  34. public static XMessages MESSAGES = (XMessages) GWT.create(XMessages.class);
  35. /**
  36. * <code>true</code> if the browser uses the webkit engine.
  37. */
  38. public static boolean isWebKit;
  39. /**
  40. * <code>true</code> if the browser is safari.
  41. */
  42. public static boolean isSafari;
  43. /**
  44. * <code>true</code> if the browser is safari2.
  45. */
  46. public static boolean isSafari2;
  47. /**
  48. * <code>true</code> if the browser is safari3.
  49. */
  50. public static boolean isSafari3;
  51. /**
  52. * <code>true</code> if the browser is safari4.
  53. */
  54. public static boolean isSafari4;
  55. /**
  56. * <code>true</code> if the browser is chrome.
  57. */
  58. public static boolean isChrome;
  59. /**
  60. * <code>true</code> if the browser is opera.
  61. */
  62. public static boolean isOpera;
  63. /**
  64. * <code>true</code> if the browser is ie.
  65. */
  66. public static boolean isIE;
  67. /**
  68. * <code>true</code> if the browser is ie6.
  69. */
  70. public static boolean isIE6;
  71. /**
  72. * <code>true</code> if the browser is ie7.
  73. */
  74. public static boolean isIE7;
  75. /**
  76. * <code>true</code> if the browser is ie8.
  77. */
  78. public static boolean isIE8;
  79. /**
  80. * <code>true</code> if the browser is gecko.
  81. */
  82. public static boolean isGecko;
  83. /**
  84. * <code>true</code> if the browser is gecko2.
  85. */
  86. public static boolean isGecko2;
  87. /**
  88. * <code>true</code> if the browser is gecko3.
  89. */
  90. public static boolean isGecko3;
  91. /**
  92. * <code>true</code> if the browser is in strict mode.
  93. */
  94. public static boolean isStrict;
  95. /**
  96. * <code>true</code> if using https.
  97. */
  98. public static boolean isSecure;
  99. /**
  100. * <code>true</code> if mac os.
  101. */
  102. public static boolean isMac;
  103. /**
  104. * <code>true</code> if linux os.
  105. */
  106. public static boolean isLinux;
  107. /**
  108. * <code>true</code> if windows os.
  109. */
  110. public static boolean isWindows;
  111. /**
  112. * <code>true</code> if is air.
  113. */
  114. public static boolean isAir;
  115. /**
  116. * <code>true</code> if is borderbox.
  117. */
  118. public static boolean isBorderBox;
  119. /**
  120. * <code>true</code> if the browser uses shims.
  121. */
  122. public static boolean useShims;
  123. /**
  124. * URL to a blank file used by GXT when in secure mode for iframe src to
  125. * prevent the IE insecure content. Default value is 'blank.html'.
  126. */
  127. public static String SSL_SECURE_URL = GWT.getModuleBaseURL() + "blank.html";
  128. /**
  129. * URL to a 1x1 transparent gif image used by GXT to create inline icons with
  130. * CSS background images. Default value is '/images/default/shared/clear.gif';
  131. */
  132. public static String BLANK_IMAGE_URL = GWT.getModuleBaseURL() + "clear.gif";
  133. private static boolean initialized;
  134. private static Theme defaultTheme;
  135. private static boolean forceTheme;
  136. private static Version version;
  137. private static boolean ariaEnabled;
  138. /**
  139. * Returns the current theme id.
  140. *
  141. * @return the theme id
  142. */
  143. public static String getThemeId() {
  144. Map<String, Object> map = StateManager.get().getMap(GWT.getModuleBaseURL() + "theme");
  145. if (map != null) {
  146. return map.get("id").toString();
  147. }
  148. return null;
  149. }
  150. /**
  151. * Returns the browser's user agent.
  152. *
  153. * @return the user agent
  154. */
  155. public native static String getUserAgent() /*-{
  156. return $wnd.navigator.userAgent.toLowerCase();
  157. }-*/;
  158. /**
  159. * Returns the version information.
  160. *
  161. * @return the version information
  162. */
  163. public static Version getVersion() {
  164. if (version == null) {
  165. version = new Version();
  166. }
  167. return version;
  168. }
  169. /**
  170. * Hides the loading panel.
  171. *
  172. * @param id the loading panel id
  173. */
  174. public static void hideLoadingPanel(String id) {
  175. final Element loading = XDOM.getElementById(id);
  176. if (loading != null) {
  177. Timer t = new Timer() {
  178. @Override
  179. public void run() {
  180. loading.getStyle().setProperty("display", "none");
  181. }
  182. };
  183. t.schedule(500);
  184. }
  185. }
  186. /**
  187. * Initializes GXT.
  188. */
  189. public static void init() {
  190. if (initialized) {
  191. return;
  192. }
  193. initialized = true;
  194. String ua = getUserAgent();
  195. isOpera = ua.indexOf("opera") != -1;
  196. isChrome = ua.indexOf("chrome") != -1;
  197. isWebKit = ua.indexOf("webkit") != -1;
  198. isSafari = !isChrome && ua.indexOf("safari") != -1;
  199. isSafari3 = isSafari && ua.indexOf("version/3") != -1;
  200. isSafari4 = isSafari && ua.indexOf("version/4") != -1;
  201. isSafari2 = isSafari && !isSafari3 && !isSafari4;
  202. isIE = !isOpera && ua.indexOf("msie") != -1;
  203. isIE7 = !isOpera && ua.indexOf("msie 7") != -1;
  204. isIE8 = !isOpera && ua.indexOf("msie 8") != -1;
  205. isIE6 = isIE && !isIE7 && !isIE8;
  206. isGecko = !isWebKit && ua.indexOf("gecko") != -1;
  207. isGecko3 = isGecko && ua.indexOf("rv:1.9") != -1;
  208. isGecko2 = isGecko && !isGecko3;
  209. isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1);
  210. isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1);
  211. isAir = (ua.indexOf("adobeair") != -1);
  212. isLinux = (ua.indexOf("linux") != -1);
  213. useShims = isIE6 || (isMac && isGecko2);
  214. String mode = DOM.getElementProperty(XDOM.getDocument(), "compatMode");
  215. isStrict = mode != null ? mode.equals("CSS1Compat") : false;
  216. isBorderBox = isIE && !isStrict;
  217. isSecure = Window.Location.getHref().startsWith("https");
  218. initInternal();
  219. El bodyEl = XDOM.getBodyEl();
  220. if (isIE) {
  221. bodyEl.addStyleName("ext-ie");
  222. String cls = (isIE6 ? "ext-ie6" : (isIE7 ? "ext-ie7" : "ext-ie8"));
  223. bodyEl.addStyleName(cls);
  224. if (isBorderBox) {
  225. bodyEl.addStyleName("ext-border-box");
  226. }
  227. } else if (isGecko) {
  228. bodyEl.addStyleName("ext-gecko");
  229. String cls = (isGecko2 ? "ext-gecko2" : "ext-gecko3");
  230. bodyEl.addStyleName(cls);
  231. } else if (isOpera) {
  232. bodyEl.addStyleName("ext-opera");
  233. } else if (isWebKit) {
  234. bodyEl.addStyleName("ext-webkit");
  235. if (isSafari) {
  236. bodyEl.addStyleName("ext-safari");
  237. } else if (isChrome) {
  238. bodyEl.addStyleName("ext-chrome");
  239. }
  240. }
  241. if (isWindows) {
  242. bodyEl.addStyleName("ext-windows");
  243. } else if (isMac) {
  244. bodyEl.addStyleName("ext-mac");
  245. } else if (isLinux) {
  246. bodyEl.addStyleName("ext-linux");
  247. }
  248. CookieProvider provider = new CookieProvider("/", null, null, false);
  249. StateManager.get().setProvider(provider);
  250. Map<String, Object> theme = StateManager.get().getMap(
  251. GWT.getModuleBaseURL() + "theme");
  252. if ((defaultTheme != null && forceTheme) || (theme == null && defaultTheme != null)) {
  253. theme = defaultTheme.asMap();
  254. }
  255. if (theme != null) {
  256. String themeId = theme.get("id").toString();
  257. String fileName = theme.get("file").toString();
  258. if (!fileName.contains("gxt-all.css")) {
  259. CSS.addStyleSheet(themeId, fileName);
  260. }
  261. bodyEl.addStyleName("x-theme-" + themeId);
  262. StateManager.get().set(GWT.getModuleBaseURL() + "theme", theme);
  263. }
  264. if (isStrict) { // add to the parent to allow for selectors like
  265. // ".ext-strict .ext-ie"
  266. Element p = (Element) XDOM.getBody().getParentElement();
  267. if (p != null) {
  268. El.fly(p).addStyleName("ext-strict");
  269. }
  270. }
  271. if (isIE6) {
  272. removeBackgroundFlicker();
  273. }
  274. }
  275. /**
  276. * Returns the ARIA enabled state.
  277. *
  278. * @return true if enabled, false otherwise
  279. */
  280. public static boolean isAriaEnabled() {
  281. return ariaEnabled;
  282. }
  283. /**
  284. * True to enable ARIA functionality.
  285. *
  286. * @param enable true to enable
  287. */
  288. public static void setAriaEnabled(boolean enable) {
  289. ariaEnabled = enable;
  290. }
  291. /**
  292. * Sets the default theme which will be used if the user does not have a theme
  293. * selected with the state provider.
  294. *
  295. * @param theme the default theme
  296. * @param force true to force the theme, ignoring the the theme saved with the
  297. * state manager
  298. */
  299. public static void setDefaultTheme(Theme theme, boolean force) {
  300. defaultTheme = theme;
  301. forceTheme = force;
  302. }
  303. /**
  304. * Changes the theme. A theme's stylehseets should be given a class = to the
  305. * theme id. Any stylesheets that have a class that do not match the id be
  306. * removed (stylesheets with no class specified are ignored). The method will
  307. * reload the application after changing themes.
  308. *
  309. * @param theme the new theme name.
  310. */
  311. public static void switchTheme(Theme theme) {
  312. StateManager.get().set(GWT.getModuleBaseURL() + "theme", theme.asMap());
  313. XDOM.reload();
  314. }
  315. private static native void initInternal() /*-{
  316. $wnd.GXT = {};
  317. $wnd.GXT.Ext = {};
  318. @com.extjs.gxt.ui.client.core.Ext::load()();
  319. }-*/;
  320. private native static void removeBackgroundFlicker() /*-{
  321. try{
  322. $doc.execCommand("BackgroundImageCache", false, true);
  323. }catch(e){}
  324. }-*/;
  325. }