4 package org.opendaylight.nemo.tool.eclipse.plugin.ui.internal;
6 import java.util.Collections;
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;
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;
21 * This class was generated. Customizations should only happen in a newly
22 * introduced subclass.
24 public class EditorActivator extends AbstractUIPlugin {
26 public static final String ORG_OPENDAYLIGHT_NEMO_TOOL_ECLIPSE_PLUGIN_EDITOR = "org.opendaylight.nemo.tool.eclipse.plugin.Editor";
28 private static final Logger logger = Logger.getLogger(EditorActivator.class);
30 private static EditorActivator INSTANCE;
32 private Map<String, Injector> injectors = Collections.synchronizedMap(Maps.<String, Injector> newHashMapWithExpectedSize(1));
35 public void start(BundleContext context) throws Exception {
41 public void stop(BundleContext context) throws Exception {
47 public static EditorActivator getInstance() {
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));
61 protected Injector createInjector(String language) {
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);
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();
80 throw new IllegalArgumentException(grammar);
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);
88 throw new IllegalArgumentException(grammar);
91 protected Module getSharedStateModule() {
92 return new SharedStateModule();