Modify pom file
[nemo.git] / nemo-tools / eclipse-plugin / nemo-editor / org.opendaylight.nemo.tool.eclipse.plugin.editor.ui / src-gen / org / opendaylight / nemo / tool / eclipse / plugin / ui / internal / EditorActivator.java
1 /*
2  * generated by Xtext
3  */
4 package org.opendaylight.nemo.tool.eclipse.plugin.ui.internal;
5
6 import java.util.Collections;
7 import java.util.Map;
8
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.osgi.framework.BundleContext;
14
15 import com.google.common.collect.Maps;
16 import com.google.inject.Guice;
17 import com.google.inject.Injector;
18 import com.google.inject.Module;
19
20 /**
21  * This class was generated. Customizations should only happen in a newly
22  * introduced subclass. 
23  */
24 public class EditorActivator extends AbstractUIPlugin {
25         
26         public static final String ORG_OPENDAYLIGHT_NEMO_TOOL_ECLIPSE_PLUGIN_EDITOR = "org.opendaylight.nemo.tool.eclipse.plugin.Editor";
27         
28         private static final Logger logger = Logger.getLogger(EditorActivator.class);
29         
30         private static EditorActivator INSTANCE;
31         
32         private Map<String, Injector> injectors = Collections.synchronizedMap(Maps.<String, Injector> newHashMapWithExpectedSize(1));
33         
34         @Override
35         public void start(BundleContext context) throws Exception {
36                 super.start(context);
37                 INSTANCE = this;
38         }
39         
40         @Override
41         public void stop(BundleContext context) throws Exception {
42                 injectors.clear();
43                 INSTANCE = null;
44                 super.stop(context);
45         }
46         
47         public static EditorActivator getInstance() {
48                 return INSTANCE;
49         }
50         
51         public Injector getInjector(String language) {
52                 synchronized (injectors) {
53                         Injector injector = injectors.get(language);
54                         if (injector == null) {
55                                 injectors.put(language, injector = createInjector(language));
56                         }
57                         return injector;
58                 }
59         }
60         
61         protected Injector createInjector(String language) {
62                 try {
63                         Module runtimeModule = getRuntimeModule(language);
64                         Module sharedStateModule = getSharedStateModule();
65                         Module uiModule = getUiModule(language);
66                         Module mergedModule = Modules2.mixin(runtimeModule, sharedStateModule, uiModule);
67                         return Guice.createInjector(mergedModule);
68                 } catch (Exception e) {
69                         logger.error("Failed to create injector for " + language);
70                         logger.error(e.getMessage(), e);
71                         throw new RuntimeException("Failed to create injector for " + language, e);
72                 }
73         }
74
75         protected Module getRuntimeModule(String grammar) {
76                 if (ORG_OPENDAYLIGHT_NEMO_TOOL_ECLIPSE_PLUGIN_EDITOR.equals(grammar)) {
77                         return new org.opendaylight.nemo.tool.eclipse.plugin.EditorRuntimeModule();
78                 }
79                 
80                 throw new IllegalArgumentException(grammar);
81         }
82         
83         protected Module getUiModule(String grammar) {
84                 if (ORG_OPENDAYLIGHT_NEMO_TOOL_ECLIPSE_PLUGIN_EDITOR.equals(grammar)) {
85                         return new org.opendaylight.nemo.tool.eclipse.plugin.ui.EditorUiModule(this);
86                 }
87                 
88                 throw new IllegalArgumentException(grammar);
89         }
90         
91         protected Module getSharedStateModule() {
92                 return new SharedStateModule();
93         }
94         
95 }