PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/com.plectix.rulestudio.core/src/com/plectix/rulestudio/core/Activator.java

https://github.com/kappamodeler/rulestudio
Java | 123 lines | 83 code | 19 blank | 21 comment | 15 complexity | 78df8b65a8186e1bddca54842c131ee9 MD5 | raw file
  1. package com.plectix.rulestudio.core;
  2. import org.eclipse.core.runtime.IProgressMonitor;
  3. import org.eclipse.core.runtime.IStatus;
  4. import org.eclipse.core.runtime.Status;
  5. import org.eclipse.jface.dialogs.MessageDialog;
  6. import org.eclipse.swt.widgets.Display;
  7. import org.eclipse.swt.widgets.Shell;
  8. import org.eclipse.ui.plugin.AbstractUIPlugin;
  9. import org.eclipse.ui.progress.UIJob;
  10. import org.osgi.framework.BundleContext;
  11. import org.osgi.framework.Version;
  12. import com.plectix.rulestudio.core.usagedata.UsageDataCollector;
  13. /**
  14. * The activator class controls the plug-in life cycle
  15. */
  16. public class Activator extends AbstractUIPlugin {
  17. // The plug-in ID
  18. public static final String PLUGIN_ID = "com.plectix.rulestudio.core";
  19. private static final String DEFAULT_CELLUCIDATE_URL = "http://api.rulebase.org";
  20. private static String url = null;
  21. // The shared instance
  22. private static Activator plugin;
  23. /**
  24. * The constructor
  25. */
  26. public Activator() {
  27. }
  28. /*
  29. * (non-Javadoc)
  30. * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
  31. */
  32. public void start(BundleContext context) throws Exception {
  33. super.start(context);
  34. plugin = this;
  35. verifyPlatform();
  36. UsageDataCollector.getInstance().start();
  37. }
  38. /*
  39. * (non-Javadoc)
  40. * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
  41. */
  42. public void stop(BundleContext context) throws Exception {
  43. UsageDataCollector.getInstance().stop();
  44. plugin = null;
  45. super.stop(context);
  46. }
  47. /**
  48. * Returns the shared instance
  49. *
  50. * @return the shared instance
  51. */
  52. public static Activator getDefault() {
  53. return plugin;
  54. }
  55. public Version getVersion() {
  56. return getBundle().getVersion();
  57. }
  58. public String getUrl() {
  59. if (url == null) {
  60. String setUrl = System.getProperty("cellucidate");
  61. if (setUrl instanceof String && setUrl.length() > 0)
  62. url = setUrl;
  63. else
  64. url = DEFAULT_CELLUCIDATE_URL;
  65. }
  66. return url;
  67. }
  68. public void verifyPlatform() {
  69. final String version = System.getProperty("java.version");
  70. final String vendor = System.getProperty("java.vendor");
  71. final String osVersion = System.getProperty("os.version");
  72. Version os = new Version(osVersion);
  73. boolean reportError = false;
  74. if (vendor.startsWith("Apple") && os.getMajor() <= 10 && os.getMinor() <= 5) {
  75. if (!version.startsWith("1.5")) {
  76. reportError = true;
  77. }
  78. } else if (!version.startsWith("1.6")) {
  79. reportError = true;
  80. }
  81. if (reportError) {
  82. UIJob fixup = new UIJob("Update client JRE.") {
  83. @Override
  84. public IStatus runInUIThread(IProgressMonitor monitor) {
  85. String message;
  86. if (vendor.startsWith("Apple")) {
  87. message = "MAC clients before 10.6 require Java 1.5.";
  88. } else {
  89. message = "This client requires Java 1.6 for Windows and Linux.";
  90. }
  91. Display disp = Display.getCurrent();
  92. if (disp == null)
  93. disp = Display.getDefault();
  94. Shell parent = disp.getActiveShell();
  95. MessageDialog.openError(parent, "Java Version Error", message);
  96. return Status.OK_STATUS;
  97. }
  98. };
  99. fixup.setSystem(true);
  100. fixup.setUser(false);
  101. fixup.schedule();
  102. }
  103. }
  104. }