PageRenderTime 1075ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/org.jnario.ui/src/org/jnario/ui/internal/JnarioActivator.java

http://github.com/bmwcarit/Jnario
Java | 66 lines | 49 code | 10 blank | 7 comment | 2 complexity | 3243efea9afd1c808a7d247be125fd3d MD5 | raw file
Possible License(s): Apache-2.0
  1. /*******************************************************************************
  2. * Copyright (c) 2012 BMW Car IT and others.
  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. package org.jnario.ui.internal;
  9. import org.apache.log4j.Logger;
  10. import org.eclipse.ui.plugin.AbstractUIPlugin;
  11. import org.eclipse.xtext.ui.shared.SharedStateModule;
  12. import org.eclipse.xtext.util.Modules2;
  13. import org.jnario.ui.JnarioUiModule;
  14. import org.osgi.framework.BundleContext;
  15. import com.google.inject.Guice;
  16. import com.google.inject.Injector;
  17. import com.google.inject.Module;
  18. public class JnarioActivator extends AbstractUIPlugin {
  19. private static JnarioActivator INSTANCE;
  20. private static final Logger logger = Logger.getLogger(JnarioActivator.class);
  21. private Injector injector;
  22. @Override
  23. public void start(BundleContext context) throws Exception {
  24. super.start(context);
  25. INSTANCE = this;
  26. }
  27. @Override
  28. public void stop(BundleContext context) throws Exception {
  29. injector = null;
  30. INSTANCE = null;
  31. super.stop(context);
  32. }
  33. public static JnarioActivator getInstance() {
  34. return INSTANCE;
  35. }
  36. public synchronized Injector getInjector() {
  37. if (injector == null) {
  38. injector = createInjector();
  39. }
  40. return injector;
  41. }
  42. protected Injector createInjector() {
  43. try {
  44. Module sharedStateModule = getSharedStateModule();
  45. Module jnarioModule = new JnarioUiModule(this);
  46. return Guice.createInjector(Modules2.mixin(jnarioModule, sharedStateModule));
  47. } catch (Exception e) {
  48. logger.error("Failed to create injector for jnario");
  49. logger.error(e.getMessage(), e);
  50. throw new RuntimeException("Failed to create injector for jnario", e);
  51. }
  52. }
  53. protected Module getSharedStateModule() {
  54. return new SharedStateModule();
  55. }
  56. }