package jetbrains.mps.lang.editor.menus.extras.runtime;

/*Generated by MPS */

import jetbrains.mps.lang.editor.menus.SingleItemMenuPart;
import jetbrains.mps.openapi.editor.menus.transformation.TransformationMenuItem;
import jetbrains.mps.openapi.editor.menus.transformation.TransformationMenuContext;
import org.jetbrains.annotations.Nullable;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.ActionManager;
import org.jetbrains.annotations.NotNull;

public abstract class PluginActionMenuPartBase extends SingleItemMenuPart<TransformationMenuItem, TransformationMenuContext> {
  private final String myActionId;

  public PluginActionMenuPartBase(String actionId) {
    myActionId = actionId;
  }

  @Nullable
  @Override
  protected TransformationMenuItem createItem(TransformationMenuContext context) {
    AnAction action = ActionManager.getInstance().getAction(myActionId);
    if (action == null) {
      return null;
    }
    return createItem(context, action);
  }

  protected abstract TransformationMenuItem createItem(@NotNull TransformationMenuContext context, @NotNull AnAction action);
}
