/restructuration/org.eclipse.emf.compare.mpatch/src/org/eclipse/emf/compare/mpatch/Activator.java

https://github.com/zenobios/emf.compare · Java · 104 lines · 55 code · 14 blank · 35 comment · 13 complexity · cb8a757dbef84448b9b5766e29fb32b9 MD5 · raw file

  1. /*******************************************************************************
  2. * Copyright (c) 2010, 2011 Technical University of Denmark.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * Patrick Koenemann, DTU Informatics - initial API and implementation
  10. *******************************************************************************/
  11. package org.eclipse.emf.compare.mpatch;
  12. import org.eclipse.core.runtime.IStatus;
  13. import org.eclipse.core.runtime.Plugin;
  14. import org.eclipse.core.runtime.Status;
  15. import org.osgi.framework.BundleContext;
  16. /**
  17. * The activator class controls the plug-in life cycle.
  18. *
  19. * @author Patrick Koenemann (pk@imm.dtu.dk)
  20. */
  21. public class Activator extends Plugin {
  22. // The plug-in ID
  23. public static final String PLUGIN_ID = "org.eclipse.emf.compare.mpatch";
  24. // The shared instance
  25. private static Activator plugin;
  26. /**
  27. * The constructor
  28. */
  29. public Activator() {
  30. // Nothing to do
  31. }
  32. /*
  33. * (non-Javadoc)
  34. * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
  35. */
  36. @Override
  37. public void start(BundleContext context) throws Exception {
  38. super.start(context);
  39. plugin = this;
  40. }
  41. /*
  42. * (non-Javadoc)
  43. * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
  44. */
  45. @Override
  46. public void stop(BundleContext context) throws Exception {
  47. plugin = null;
  48. super.stop(context);
  49. }
  50. /**
  51. * Returns the shared instance
  52. *
  53. * @return the shared instance
  54. */
  55. public static Activator getDefault() {
  56. return plugin;
  57. }
  58. // //////////// SOME LOGGING
  59. public void logError(String error) {
  60. logError(error, null);
  61. }
  62. public void logError(String error, Throwable throwable) {
  63. if (error == null && throwable != null) {
  64. error = throwable.getMessage();
  65. }
  66. getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, error, throwable));
  67. debug(error, throwable);
  68. }
  69. public void logInfo(String message) {
  70. logInfo(message, null);
  71. }
  72. public void logInfo(String message, Throwable throwable) {
  73. if (message == null && throwable != null) {
  74. message = throwable.getMessage();
  75. }
  76. getLog().log(new Status(IStatus.INFO, PLUGIN_ID, IStatus.OK, message, throwable));
  77. debug(message, throwable);
  78. }
  79. private void debug(String message, Throwable throwable) {
  80. if (!isDebugging()) {
  81. return;
  82. }
  83. if (message != null) {
  84. System.err.println(message);
  85. }
  86. if (throwable != null) {
  87. throwable.printStackTrace();
  88. }
  89. }
  90. }