package jetbrains.mps.lang.editor.editor;

/*Generated by MPS */

import jetbrains.mps.nodeEditor.menus.substitute.SubstituteMenuBase;
import jetbrains.mps.lang.editor.menus.EditorMenuDescriptorBase;
import jetbrains.mps.smodel.SNodePointer;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import jetbrains.mps.lang.editor.menus.MenuPart;
import jetbrains.mps.openapi.editor.menus.substitute.SubstituteMenuItem;
import jetbrains.mps.openapi.editor.menus.substitute.SubstituteMenuContext;
import java.util.ArrayList;
import jetbrains.mps.lang.editor.menus.GroupMenuPart;
import jetbrains.mps.util.Computable;
import java.util.Objects;
import java.util.Arrays;
import jetbrains.mps.lang.editor.menus.substitute.ConstraintsFilteringSubstituteMenuPartDecorator;
import jetbrains.mps.lang.editor.menus.ConceptMenusPart;
import java.util.Collection;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.lang.editor.behavior.TransformationLocation__BehaviorDescriptor;
import jetbrains.mps.internal.collections.runtime.Sequence;
import jetbrains.mps.lang.editor.actions.TransformationMenuActionsUtil;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import jetbrains.mps.lang.editor.menus.substitute.SimpleConceptSubstituteMenuPart;
import jetbrains.mps.lang.editor.menus.substitute.DefaultSubstituteMenuLookup;
import jetbrains.mps.smodel.language.LanguageRegistry;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;

public class TransformationFeature_SubstituteMenu extends SubstituteMenuBase {
  public TransformationFeature_SubstituteMenu() {
    super(false, new EditorMenuDescriptorBase("default substitute menu for " + "TransformationFeature", new SNodePointer("r:00000000-0000-4000-0000-011c89590299(jetbrains.mps.lang.editor.editor)", "1741258697587153981")));
  }
  @NotNull
  @Override
  protected List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> getParts(final SubstituteMenuContext _context) {
    List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> result = new ArrayList<MenuPart<SubstituteMenuItem, SubstituteMenuContext>>();
    result.add(new SMP_Group_97h82d_a());
    return result;
  }

  public class SMP_Group_97h82d_a extends GroupMenuPart<SubstituteMenuItem, SubstituteMenuContext> {
    private boolean condition;
    public SMP_Group_97h82d_a() {
      super(new EditorMenuDescriptorBase("substitute menu group", new SNodePointer("r:00000000-0000-4000-0000-011c89590299(jetbrains.mps.lang.editor.editor)", "1741258697587153982")));
    }
    @Override
    protected void initialize(SubstituteMenuContext _context) {
      super.initialize(_context);
      condition = new Computable<Boolean>() {
        public Boolean compute() {
          return Objects.equals(_context.getLink(), LINKS.features$gNd);
        }
      }.compute();
    }
    @Override
    protected List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> getParts() {
      return Arrays.<MenuPart<SubstituteMenuItem, SubstituteMenuContext>>asList(new SMP_Group_97h82d_a0(), new SMP_Group_97h82d_b0());
    }
    public class SMP_Group_97h82d_a0 extends GroupMenuPart<SubstituteMenuItem, SubstituteMenuContext> {
      public SMP_Group_97h82d_a0() {
        super(new EditorMenuDescriptorBase("substitute menu group", new SNodePointer("r:00000000-0000-4000-0000-011c89590299(jetbrains.mps.lang.editor.editor)", "1741258697587154023")));
      }
      @Override
      protected boolean isApplicable(SubstituteMenuContext _context) {
        return condition;
      }
      @Override
      protected List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> getParts() {
        return Arrays.<MenuPart<SubstituteMenuItem, SubstituteMenuContext>>asList(new ConstraintsFilteringSubstituteMenuPartDecorator(new SMP_Concepts_97h82d_a0a(), CONCEPTS.TransformationFeature$e4));
      }
      public class SMP_Concepts_97h82d_a0a extends ConceptMenusPart<SubstituteMenuItem, SubstituteMenuContext> {
        public SMP_Concepts_97h82d_a0a() {
          super(new EditorMenuDescriptorBase("simple actions for the list of concepts", new SNodePointer("r:00000000-0000-4000-0000-011c89590299(jetbrains.mps.lang.editor.editor)", "1741258697587154028")));
        }
        protected Collection getConcepts(SubstituteMenuContext _context) {
          SNode section = SNodeOperations.getNodeAncestor(_context.getParentNode(), CONCEPTS.TransformationMenuSection$SB, true, false);
          final Iterable<SConcept> availableFeatures = ListSequence.fromList(SLinkOperations.getChildren(section, LINKS.locations$m8FB)).translate((it) -> (Collection<SConcept>) TransformationLocation__BehaviorDescriptor.getAvailableFeatures_id1A4kJjlZ$rL.invoke(it));
          Iterable<SConcept> concepts = Sequence.fromIterable(TransformationMenuActionsUtil.getSubconceptsWithCurrentChildConceptsExcluded(CONCEPTS.TransformationFeature$e4, _context.getParentNode(), LINKS.features$gNd, _context.getCurrentTargetNode())).select((it) -> SNodeOperations.castConcept(it, CONCEPTS.TransformationFeature$e4));
          if (section != null) {
            concepts = Sequence.fromIterable(concepts).where((it) -> Sequence.fromIterable(availableFeatures).contains(it));
          }
          return Sequence.fromIterable(concepts).toList();
        }

        @Override
        protected Collection<SubstituteMenuItem> createItemsForConcept(final SubstituteMenuContext _context, final SAbstractConcept concept) {
          return new SimpleConceptSubstituteMenuPart(concept, new EditorMenuDescriptorBase("simple action for concept: " + concept.getName(), null)).createItems(_context);
        }
      }
    }
    public class SMP_Group_97h82d_b0 extends GroupMenuPart<SubstituteMenuItem, SubstituteMenuContext> {
      public SMP_Group_97h82d_b0() {
        super(new EditorMenuDescriptorBase("substitute menu group", new SNodePointer("r:00000000-0000-4000-0000-011c89590299(jetbrains.mps.lang.editor.editor)", "1741258697587154160")));
      }
      @Override
      protected boolean isApplicable(SubstituteMenuContext _context) {
        return !(condition);
      }
      @Override
      protected List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> getParts() {
        return Arrays.<MenuPart<SubstituteMenuItem, SubstituteMenuContext>>asList(new SMP_Subconcepts_97h82d_a1a());
      }
      public class SMP_Subconcepts_97h82d_a1a extends ConceptMenusPart<SubstituteMenuItem, SubstituteMenuContext> {
        public SMP_Subconcepts_97h82d_a1a() {
          super(new EditorMenuDescriptorBase("include menus for all the direct subconcepts of " + "TransformationFeature", new SNodePointer("r:00000000-0000-4000-0000-011c89590299(jetbrains.mps.lang.editor.editor)", "1741258697587154164")));
        }

        @Override
        protected Collection<SAbstractConcept> getConcepts(final SubstituteMenuContext _context) {
          return getDirectDescendants(_context, CONCEPTS.TransformationFeature$e4);
        }

        @Override
        protected Collection<SubstituteMenuItem> createItemsForConcept(SubstituteMenuContext context, SAbstractConcept concept) {
          return context.createItems(new DefaultSubstituteMenuLookup(LanguageRegistry.getInstance(context.getEditorContext().getRepository()), concept));
        }
      }
    }
  }

  private static final class LINKS {
    /*package*/ static final SContainmentLink features$gNd = MetaAdapterFactory.getContainmentLink(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x652f322a364c9a28L, 0x7c45559defbb3517L, "features");
    /*package*/ static final SContainmentLink locations$m8FB = MetaAdapterFactory.getContainmentLink(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x6ec02d9918b4efbcL, 0x6ec02d9918b4efbdL, "locations");
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept TransformationFeature$e4 = MetaAdapterFactory.getConcept(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x7c45559defb64aa5L, "jetbrains.mps.lang.editor.structure.TransformationFeature");
    /*package*/ static final SConcept TransformationMenuSection$SB = MetaAdapterFactory.getConcept(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x6ec02d9918b4efbcL, "jetbrains.mps.lang.editor.structure.TransformationMenuSection");
  }
}
