package jetbrains.mps.lang.editor.test.generation.editor;

/*Generated by MPS */

import jetbrains.mps.editor.runtime.descriptor.AbstractEditorBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.openapi.editor.EditorContext;
import jetbrains.mps.openapi.editor.cells.EditorCell;
import jetbrains.mps.nodeEditor.cells.EditorCell_Collection;
import jetbrains.mps.nodeEditor.cellLayout.CellLayout_Horizontal;
import jetbrains.mps.openapi.editor.style.Style;
import jetbrains.mps.editor.runtime.style.StyleImpl;
import jetbrains.mps.editor.runtime.style.StyleAttributes;
import org.jetbrains.mps.openapi.language.SProperty;
import jetbrains.mps.openapi.editor.menus.transformation.SPropertyInfo;
import jetbrains.mps.nodeEditor.cells.EditorCell_Property;
import jetbrains.mps.nodeEditor.cells.SPropertyAccessor;
import jetbrains.mps.editor.runtime.style.FocusPolicy;
import jetbrains.mps.lang.editor.menus.transformation.NamedTransformationMenuLookup;
import jetbrains.mps.smodel.language.LanguageRegistry;
import jetbrains.mps.nodeEditor.cellMenu.CompositeSubstituteInfo;
import jetbrains.mps.lang.editor.cellProviders.PropertyCellContext;
import jetbrains.mps.nodeEditor.cellMenu.SubstituteInfoPartExt;
import jetbrains.mps.nodeEditor.cellMenu.SChildSubstituteInfoPartEx;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.IAttributeDescriptor;
import jetbrains.mps.internal.collections.runtime.Sequence;
import java.util.Objects;
import jetbrains.mps.lang.core.behavior.PropertyAttribute__BehaviorDescriptor;
import jetbrains.mps.nodeEditor.EditorManager;
import jetbrains.mps.openapi.editor.update.AttributeKind;
import jetbrains.mps.lang.editor.generator.internal.AbstractCellMenuPart_Generic_Group;
import java.util.List;
import org.jetbrains.mps.openapi.model.SModel;
import jetbrains.mps.openapi.editor.menus.EditorMenuDescriptor;
import jetbrains.mps.lang.editor.menus.EditorMenuDescriptorBase;
import jetbrains.mps.smodel.SNodePointer;
import jetbrains.mps.lang.editor.generator.internal.AbstractCellMenuPart_ReplaceNode_Group;
import jetbrains.mps.openapi.editor.cells.SubstituteAction;
import jetbrains.mps.nodeEditor.cellMenu.CellContext;
import jetbrains.mps.lang.editor.generator.internal.AbstractCellMenuPart_Generic_Item;
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.generator.internal.AbstractCellMenuPart_PropertyPostfixHints;
import jetbrains.mps.lang.editor.generator.internal.AbstractCellMenuPart_PropertyValues;
import jetbrains.mps.lang.editor.generator.internal.AbstractCellMenuPart_ReplaceNode_CustomNodeConcept;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SConcept;

/*package*/ class TransactionalProperty_EditorCellModel_ComponentBuilder_a extends AbstractEditorBuilder {
  @NotNull
  private SNode myNode;

  public TransactionalProperty_EditorCellModel_ComponentBuilder_a(@NotNull EditorContext context, @NotNull SNode node) {
    super(context);
    myNode = node;
  }

  @NotNull
  @Override
  public SNode getNode() {
    return myNode;
  }

  /*package*/ EditorCell createCell() {
    return createCollection_0();
  }

  private EditorCell createCollection_0() {
    EditorCell_Collection editorCell = new EditorCell_Collection(getEditorContext(), myNode, new CellLayout_Horizontal());
    editorCell.setCellId("Collection_vfuuik_a");
    Style style = new StyleImpl();
    style.set(StyleAttributes.SELECTABLE, false);
    editorCell.getStyle().putAll(style);
    if (nodeCondition_vfuuik_a0a()) {
      editorCell.addEditorCell(createProperty_0());
    }
    return editorCell;
  }
  private boolean nodeCondition_vfuuik_a0a() {
    boolean var = getEditorContext() != null || myNode != null;
    return var;
  }
  private EditorCell createProperty_0() {
    getCellFactory().pushCellContext();
    try {
      final SProperty property = PROPS.theProperty$q6LT;
      getCellFactory().setPropertyInfo(new SPropertyInfo(myNode, property));
      EditorCell_Property editorCell = EditorCell_Property.create(getEditorContext(), new SPropertyAccessor(myNode, property, false, false), myNode);
      editorCell.setDefaultText("<no theProperty>");
      editorCell.setCellId("idd");
      if (nodeCondition_vfuuik_a0a_0()) {
        editorCell.getStyle().set(StyleAttributes.FOCUS_POLICY, FocusPolicy.ATTRACTS_RECURSIVELY);
      }
      TestTargetActionMap.setCellActions(editorCell, myNode, getEditorContext());
      editorCell.addKeyMap(new TestTargetKeymap());
      editorCell.setTransformationMenuLookup(new NamedTransformationMenuLookup(LanguageRegistry.getInstance(getEditorContext().getRepository()), CONCEPTS.AbstractCellTest$Pr, "jetbrains.mps.lang.editor.test.generation.editor.TestTargetTransformationMenu"));
      editorCell.setSubstituteInfo(new CompositeSubstituteInfo(getEditorContext(), new PropertyCellContext(myNode, property), new SubstituteInfoPartExt[]{new TransactionalProperty_generic_cellMenu_vfuuik_a0a0(), new TransactionalProperty_generic_cellMenu_vfuuik_b0a0(), new TransactionalProperty_customReplace_cellMenu_vfuuik_c0a0(), new TransactionalProperty_customReplace_cellMenu_vfuuik_d0a0(), new TransactionalProperty_component_cellMenu_vfuuik_e0a0(), new TransactionalProperty_generic_cellMenu_vfuuik_f0a0(), new TransactionalProperty_theProperty_postfixCellMenu_vfuuik_g0a0(), new TransactionalProperty_theProperty_cellMenu_vfuuik_h0a0(), new ReplaceWith_Constant_cellMenu_vfuuik_i0a0(), new SChildSubstituteInfoPartEx(editorCell)}));
      setCellContext(editorCell);
      Iterable<SNode> propertyAttributes = SNodeOperations.ofConcept(new IAttributeDescriptor.AllAttributes().list(myNode), CONCEPTS.PropertyAttribute$Gb);
      Iterable<SNode> currentPropertyAttributes = Sequence.fromIterable(propertyAttributes).where((it) -> Objects.equals(PropertyAttribute__BehaviorDescriptor.getProperty_id1avfQ4BBzOo.invoke(it), property));
      if (Sequence.fromIterable(currentPropertyAttributes).isNotEmpty()) {
        EditorManager manager = EditorManager.getInstanceFromContext(getEditorContext());
        return manager.createNodeRoleAttributeCell(Sequence.fromIterable(currentPropertyAttributes).first(), AttributeKind.PROPERTY, editorCell);
      } else
      return editorCell;
    } finally {
      getCellFactory().popCellContext();
    }
  }
  private boolean nodeCondition_vfuuik_a0a_0() {
    boolean var = getEditorContext() != null || myNode != null;
    return var;
  }
  public static class TransactionalProperty_generic_cellMenu_vfuuik_a0a0 extends AbstractCellMenuPart_Generic_Group {
    public TransactionalProperty_generic_cellMenu_vfuuik_a0a0() {
    }

    protected List<?> createParameterObjects(SNode node, EditorContext editorContext) {
      boolean var = node != null || editorContext != null;
      return (var ? null : null);

    }
    protected void handleAction(Object parameterObject, SNode node, SModel model, EditorContext editorContext) {
      this.handleAction_impl((String) parameterObject, node, model, editorContext);
    }
    private void handleAction_impl(String parameterObject, SNode node, SModel model, EditorContext editorContext) {
      boolean var = parameterObject != null || node != null || model != null || editorContext != null;
      if (var) {
        // just usage of var
      }
    }
    protected boolean isReferentPresentation() {
      return false;
    }

    @Override
    protected EditorMenuDescriptor getEditorMenuDescriptor(Object parameterObject) {
      return new EditorMenuDescriptorBase("generic group with parameter: " + ((parameterObject == null ? "null" : parameterObject.toString())), new SNodePointer("r:5198f57a-b6fe-4b27-af15-f0dc1a790395(jetbrains.mps.lang.editor.test.generation.editor)", "53454498079449004"));
    }
  }
  public static class TransactionalProperty_generic_cellMenu_vfuuik_b0a0 extends AbstractCellMenuPart_Generic_Group {
    public TransactionalProperty_generic_cellMenu_vfuuik_b0a0() {
    }

    protected List<?> createParameterObjects(SNode node, EditorContext editorContext) {
      return null;

    }
    protected void handleAction(Object parameterObject, SNode node, SModel model, EditorContext editorContext) {
      this.handleAction_impl((String) parameterObject, node, model, editorContext);
    }
    private void handleAction_impl(String parameterObject, SNode node, SModel model, EditorContext editorContext) {
    }
    protected boolean isReferentPresentation() {
      return false;
    }
    protected String getMatchingText(Object _parameterObject) {
      final String parameterObject = (String) _parameterObject;
      return String.valueOf(parameterObject);
    }
    protected String getDescriptionText(Object _parameterObject) {
      final String parameterObject = (String) _parameterObject;
      return String.valueOf(parameterObject);
    }

    @Override
    protected EditorMenuDescriptor getEditorMenuDescriptor(Object parameterObject) {
      return new EditorMenuDescriptorBase("generic group with parameter: " + ((parameterObject == null ? "null" : parameterObject.toString())), new SNodePointer("r:5198f57a-b6fe-4b27-af15-f0dc1a790395(jetbrains.mps.lang.editor.test.generation.editor)", "53454498079449056"));
    }
  }
  public static class TransactionalProperty_customReplace_cellMenu_vfuuik_c0a0 extends AbstractCellMenuPart_ReplaceNode_Group {
    public TransactionalProperty_customReplace_cellMenu_vfuuik_c0a0() {
    }
    protected List<?> createParameterObjects(SNode node, EditorContext editorContext) {
      boolean var = node != null || editorContext != null;
      return (var ? null : null);
    }
    protected SNode createReplacementNode(Object _parameterObject, SNode node, SModel model, EditorContext editorContext) {
      final String parameterObject = (String) _parameterObject;
      boolean var = parameterObject != null || node != null || model != null || editorContext != null;
      return (var ? null : null);
    }
    @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:5198f57a-b6fe-4b27-af15-f0dc1a790395(jetbrains.mps.lang.editor.test.generation.editor)", "53454498079449074"));
    }

  }
  public static class TransactionalProperty_customReplace_cellMenu_vfuuik_d0a0 extends AbstractCellMenuPart_ReplaceNode_Group {
    public TransactionalProperty_customReplace_cellMenu_vfuuik_d0a0() {
    }
    protected List<?> createParameterObjects(SNode node, EditorContext editorContext) {
      return null;
    }
    protected SNode createReplacementNode(Object _parameterObject, SNode node, SModel model, EditorContext editorContext) {
      final String parameterObject = (String) _parameterObject;
      return null;
    }
    protected String getMatchingText(Object _parameterObject) {
      final String parameterObject = (String) _parameterObject;
      return String.valueOf(parameterObject);
    }
    protected String getDescriptionText(Object _parameterObject) {
      final String parameterObject = (String) _parameterObject;
      return String.valueOf(parameterObject);
    }
    @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:5198f57a-b6fe-4b27-af15-f0dc1a790395(jetbrains.mps.lang.editor.test.generation.editor)", "53454498079449126"));
    }

  }
  public static class TransactionalProperty_component_cellMenu_vfuuik_e0a0 implements SubstituteInfoPartExt {
    private TestTargetMenuComponent myComponent;
    public TransactionalProperty_component_cellMenu_vfuuik_e0a0() {
      this.myComponent = new TestTargetMenuComponent();
    }
    public List<SubstituteAction> createActions(CellContext cellContext, EditorContext editorContext) {
      return this.myComponent.createSubstituteActions(cellContext, editorContext);
    }
  }
  public static class TransactionalProperty_generic_cellMenu_vfuuik_f0a0 extends AbstractCellMenuPart_Generic_Item {
    public TransactionalProperty_generic_cellMenu_vfuuik_f0a0() {
    }
    @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:5198f57a-b6fe-4b27-af15-f0dc1a790395(jetbrains.mps.lang.editor.test.generation.editor)", "53454498079449148")));
            return result;
          }
        };
      }).toList();
    }

    protected void handleAction(SNode node, SModel model, EditorContext editorContext) {
      boolean var = node != null || model != null || editorContext != null;
      if (var) {
        // just usage of var
      }
    }
    public String getMatchingText() {
      return "matchingText";
    }
  }
  public static class TransactionalProperty_theProperty_postfixCellMenu_vfuuik_g0a0 extends AbstractCellMenuPart_PropertyPostfixHints {
    public TransactionalProperty_theProperty_postfixCellMenu_vfuuik_g0a0() {
    }
    @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("property postfix hints", new SNodePointer("r:5198f57a-b6fe-4b27-af15-f0dc1a790395(jetbrains.mps.lang.editor.test.generation.editor)", "53454498079462857")));
            return result;
          }
        };
      }).toList();
    }

    protected List<String> getPostfixes(SNode node, EditorContext editorContext) {
      boolean var = node != null;
      return (var ? null : null);
    }
  }
  public static class TransactionalProperty_theProperty_cellMenu_vfuuik_h0a0 extends AbstractCellMenuPart_PropertyValues {
    public TransactionalProperty_theProperty_cellMenu_vfuuik_h0a0() {
    }
    @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("property postfix values", new SNodePointer("r:5198f57a-b6fe-4b27-af15-f0dc1a790395(jetbrains.mps.lang.editor.test.generation.editor)", "53454498079466740")));
            return result;
          }
        };
      }).toList();
    }

    protected List<String> getPropertyValues(SNode node, EditorContext editorContext) {
      boolean var = node != null;
      return (var ? null : null);
    }
  }
  public static class ReplaceWith_Constant_cellMenu_vfuuik_i0a0 extends AbstractCellMenuPart_ReplaceNode_CustomNodeConcept {
    public ReplaceWith_Constant_cellMenu_vfuuik_i0a0() {
    }
    public SAbstractConcept getReplacementConcept() {
      return CONCEPTS.Constant$B_;
    }
    @Override
    protected EditorMenuDescriptor createEditorMenuDescriptor(CellContext cellContext, EditorContext editorContext) {
      return new EditorMenuDescriptorBase("replace node (custom node concept: " + "Constant" + ")", new SNodePointer("r:5198f57a-b6fe-4b27-af15-f0dc1a790395(jetbrains.mps.lang.editor.test.generation.editor)", "53454498079449174"));
    }
  }

  private static final class PROPS {
    /*package*/ static final SProperty theProperty$q6LT = MetaAdapterFactory.getProperty(0xeaa98d49af584b80L, 0xb585c05e7b5fd335L, 0xbde89531aadcccL, 0xbde89531aae3a9L, "theProperty");
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept AbstractCellTest$Pr = MetaAdapterFactory.getConcept(0xeaa98d49af584b80L, 0xb585c05e7b5fd335L, 0xbde89531a681a1L, "jetbrains.mps.lang.editor.test.generation.structure.AbstractCellTest");
    /*package*/ static final SConcept PropertyAttribute$Gb = MetaAdapterFactory.getConcept(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x2eb1ad060897da56L, "jetbrains.mps.lang.core.structure.PropertyAttribute");
    /*package*/ static final SConcept Constant$B_ = MetaAdapterFactory.getConcept(0xeaa98d49af584b80L, 0xb585c05e7b5fd335L, 0xbde8953186ee02L, "jetbrains.mps.lang.editor.test.generation.structure.Constant");
  }
}
