package jetbrains.mps.lang.editor.tooltips.runtime.plugin;

/*Generated by MPS */

import jetbrains.mps.plugins.part.ProjectPluginPart;
import jetbrains.mps.openapi.editor.extensions.EditorExtension;
import java.util.Map;
import jetbrains.mps.nodeEditor.EditorComponent;
import jetbrains.mps.lang.editor.tooltips.runtime.TooltipManager;
import java.util.HashMap;
import jetbrains.mps.project.MPSProject;
import org.jetbrains.annotations.NotNull;
import jetbrains.mps.openapi.editor.extensions.EditorExtensionRegistry;

public class ProjectPlugin_ProjectPluginPart extends ProjectPluginPart {
  private EditorExtension myCreateListener;
  private Map<EditorComponent, TooltipManager> managersPool = new HashMap<EditorComponent, TooltipManager>();
  public ProjectPlugin_ProjectPluginPart() {
  }
  @Override
  public void init(MPSProject project) {
    ProjectPlugin_ProjectPluginPart.this.myCreateListener = new EditorExtension() {
      @Override
      public boolean isApplicable(@NotNull jetbrains.mps.openapi.editor.EditorComponent ignored) {
        return true;
      }

      @Override
      public void install(@NotNull jetbrains.mps.openapi.editor.EditorComponent editorComponent) {
        // make sure a TooltipManager is created for the EditorComponent
        ProjectPlugin_ProjectPluginPart.this.managersPool.computeIfAbsent((EditorComponent) editorComponent, (EditorComponent key) -> new TooltipManager(key));
      }

      @Override
      public void uninstall(@NotNull jetbrains.mps.openapi.editor.EditorComponent editorComponent) {
        TooltipManager tm = ProjectPlugin_ProjectPluginPart.this.managersPool.remove(editorComponent);
        if (tm != null) {
          tm.dispose();
        }
      }
    };
    project.getComponent(EditorExtensionRegistry.class).registerExtension(ProjectPlugin_ProjectPluginPart.this.myCreateListener);
  }
  @Override
  public void dispose(MPSProject project) {
    project.getComponent(EditorExtensionRegistry.class).unregisterExtension(ProjectPlugin_ProjectPluginPart.this.myCreateListener);
  }
}
