package jetbrains.mps.baseLanguage.editor;

/*Generated by MPS */

import jetbrains.mps.lang.editor.generator.internal.AbstractCellMenuComponent;
import jetbrains.mps.nodeEditor.cellMenu.SubstituteInfoPartExt;
import jetbrains.mps.lang.editor.generator.internal.AbstractCellMenuPart_Generic_Item;
import java.util.List;
import jetbrains.mps.openapi.editor.cells.SubstituteAction;
import jetbrains.mps.nodeEditor.cellMenu.CellContext;
import jetbrains.mps.openapi.editor.EditorContext;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import jetbrains.mps.smodel.action.NodeSubstituteActionWrapper;
import jetbrains.mps.openapi.editor.menus.EditorMenuTraceInfo;
import jetbrains.mps.nodeEditor.menus.EditorMenuTraceInfoImpl;
import jetbrains.mps.lang.editor.menus.EditorMenuDescriptorBase;
import jetbrains.mps.smodel.SNodePointer;
import org.jetbrains.mps.openapi.model.SNode;
import org.jetbrains.mps.openapi.model.SModel;
import jetbrains.mps.smodel.action.SNodeFactoryOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.baseLanguage.behavior.QualifiedReference__BehaviorDescriptor;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.editor.runtime.selection.SelectionUtil;
import jetbrains.mps.openapi.editor.selection.SelectionManager;
import jetbrains.mps.lang.editor.generator.internal.AbstractCellMenuPart_ReplaceNode_Group;
import jetbrains.mps.openapi.editor.menus.EditorMenuDescriptor;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SReferenceLink;

public class QualifiedReferenceMenu extends AbstractCellMenuComponent {
  public QualifiedReferenceMenu() {
    super(new SubstituteInfoPartExt[]{new QualifiedReference_generic_cellMenu_dbgh7b_a0(), new QualifiedReference_customReplace_cellMenu_dbgh7b_b0()});
  }
  public static class QualifiedReference_generic_cellMenu_dbgh7b_a0 extends AbstractCellMenuPart_Generic_Item {
    public QualifiedReference_generic_cellMenu_dbgh7b_a0() {
    }
    @Override
    public List<SubstituteAction> createActions(CellContext cellContext, EditorContext editorContext) {
      return ListSequence.fromList(super.createActions(cellContext, editorContext)).select((action) -> {
        return (SubstituteAction) new NodeSubstituteActionWrapper(action) {
          @Override
          public EditorMenuTraceInfo getEditorMenuTraceInfo() {
            EditorMenuTraceInfoImpl result = new EditorMenuTraceInfoImpl();
            result.setDescriptor(new EditorMenuDescriptorBase("generic item", new SNodePointer("r:00000000-0000-4000-0000-011c895902c3(jetbrains.mps.baseLanguage.editor)", "4848386836749503180")));
            return result;
          }
        };
      }).toList();
    }

    protected void handleAction(SNode node, SModel model, EditorContext editorContext) {
      SNode expr = SNodeFactoryOperations.createNewNode(CONCEPTS.ClassifierClassExpression$lN, null);
      SLinkOperations.setTarget(expr, LINKS.classifier$7Ex9, QualifiedReference__BehaviorDescriptor.getClassifier_id7S22xyoLQG7.invoke(node));
      SNodeOperations.replaceWithAnother(node, expr);
      SelectionUtil.selectLabelCellAnSetCaret(editorContext, expr, SelectionManager.LAST_CELL, -1);
    }
    public String getMatchingText() {
      return "class";
    }
  }
  public static class QualifiedReference_customReplace_cellMenu_dbgh7b_b0 extends AbstractCellMenuPart_ReplaceNode_Group {
    public QualifiedReference_customReplace_cellMenu_dbgh7b_b0() {
    }
    protected List<?> createParameterObjects(SNode node, EditorContext editorContext) {
      return QueriesUtil.replaceNodeMenu_parameterObjects(QualifiedReference__BehaviorDescriptor.getClassifier_id7S22xyoLQG7.invoke(node), node);
    }
    protected SNode createReplacementNode(Object _parameterObject, SNode node, SModel model, EditorContext editorContext) {
      final SNode parameterObject = (SNode) _parameterObject;
      return QueriesUtil.replaceNodeMenu_createNewNode(QualifiedReference__BehaviorDescriptor.getClassifier_id7S22xyoLQG7.invoke(node), parameterObject, node);
    }
    @Override
    protected EditorMenuDescriptor getEditorMenuDescriptor(Object parameterObject) {
      return new EditorMenuDescriptorBase("replace node (group of custom actions) with parameter: " + ((parameterObject == null ? "null" : parameterObject.toString())), new SNodePointer("r:00000000-0000-4000-0000-011c895902c3(jetbrains.mps.baseLanguage.editor)", "1165018751529"));
    }

  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept ClassifierClassExpression$lN = MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x103fb730c14L, "jetbrains.mps.baseLanguage.structure.ClassifierClassExpression");
  }

  private static final class LINKS {
    /*package*/ static final SReferenceLink classifier$7Ex9 = MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x103fb730c14L, 0x103fb73a43eL, "classifier");
  }
}
