package jetbrains.mps.samples.ChemMastery.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 jetbrains.mps.editor.runtime.style.Padding;
import jetbrains.mps.editor.runtime.style.Measure;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.nodeEditor.cellLayout.CellLayout_Vertical;
import jetbrains.mps.nodeEditor.cells.EditorCell_Constant;
import jetbrains.mps.nodeEditor.cells.EditorCell_Property;
import jetbrains.mps.nodeEditor.cells.ModelAccessor;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.internal.collections.runtime.Sequence;
import jetbrains.mps.openapi.editor.cells.CellActionType;
import jetbrains.mps.editor.runtime.cells.EmptyCellAction;
import jetbrains.mps.lang.editor.menus.transformation.DefaultTransformationMenuLookup;
import jetbrains.mps.smodel.language.LanguageRegistry;
import jetbrains.mps.nodeEditor.cellMenu.SChildSubstituteInfo;
import jetbrains.mps.nodeEditor.cells.EditorCell_Component;
import javax.swing.JComponent;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SProperty;
import org.jetbrains.mps.openapi.language.SContainmentLink;

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

  public SheetEntry_EditorBuilder_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_ekbrl8_a");
    editorCell.setBig(true);
    setCellContext(editorCell);
    Style style = new StyleImpl();
    style.set(StyleAttributes.PADDING_TOP, new Padding(1, Measure.SPACES));
    editorCell.getStyle().putAll(style);
    editorCell.addEditorCell(createCollection_1());
    editorCell.addEditorCell(createComponent_0());
    if (nodeCondition_ekbrl8_a2a()) {
      editorCell.addEditorCell(createCollection_2());
    }
    return editorCell;
  }
  private boolean nodeCondition_ekbrl8_a2a() {
    return SPropertyOperations.getBoolean(SNodeOperations.as(SNodeOperations.getContainingRoot(myNode), CONCEPTS.ChemSheet$VW), PROPS.showButtons$AWXr);
  }
  private EditorCell createCollection_1() {
    EditorCell_Collection editorCell = new EditorCell_Collection(getEditorContext(), myNode, new CellLayout_Vertical());
    editorCell.setCellId("Collection_ekbrl8_a0");
    editorCell.addEditorCell(createConstant_0());
    if (nodeCondition_ekbrl8_a1a0()) {
      editorCell.addEditorCell(createReadOnlyModelAccessor_0());
    }
    return editorCell;
  }
  private boolean nodeCondition_ekbrl8_a1a0() {
    return SNodeOperations.isInstanceOf(myNode, CONCEPTS.EquationEntry$bY);
  }
  private EditorCell createConstant_0() {
    EditorCell_Constant editorCell = new EditorCell_Constant(getEditorContext(), myNode, "");
    editorCell.setCellId("Constant_ekbrl8_a0a");
    Style style = new StyleImpl();
    style.set(StyleAttributes.SELECTABLE, false);
    editorCell.getStyle().putAll(style);
    editorCell.setDefaultText("");
    return editorCell;
  }
  private EditorCell createReadOnlyModelAccessor_0() {
    EditorCell_Property editorCell = EditorCell_Property.create(getEditorContext(), new ModelAccessor.ReadOnly() {
      public String getText() {
        Iterable<SNode> entries = SNodeOperations.ofConcept(SLinkOperations.getChildren(SNodeOperations.as(SNodeOperations.getParent(myNode), CONCEPTS.ChemSheet$VW), LINKS.entries$Fzjl), CONCEPTS.EquationEntry$bY);
        return String.valueOf(Sequence.fromIterable(entries).indexOf(myNode) + 1) + ")";
      }
    }, myNode);
    editorCell.setAction(CellActionType.DELETE, EmptyCellAction.getInstance());
    editorCell.setAction(CellActionType.BACKSPACE, EmptyCellAction.getInstance());
    editorCell.setCellId("ReadOnlyModelAccessor_ekbrl8_b0a");
    Style style = new StyleImpl();
    style.set(StyleAttributes.SELECTABLE, false);
    style.set(StyleAttributes.EDITABLE, false);
    editorCell.getStyle().putAll(style);
    return editorCell;
  }
  private EditorCell createComponent_0() {
    EditorCell editorCell = getCellFactory().createEditorComponentCell(myNode, "jetbrains.mps.samples.ChemMastery.editor.SheetEntryContent");
    DeleteSheetEntry.setCellActions(editorCell, myNode, getEditorContext());
    editorCell.setTransformationMenuLookup(new DefaultTransformationMenuLookup(LanguageRegistry.getInstance(getEditorContext().getRepository()), CONCEPTS.SheetEntry$3$));
    editorCell.setSubstituteInfo(new SChildSubstituteInfo(editorCell));
    return editorCell;
  }
  private EditorCell createCollection_2() {
    EditorCell_Collection editorCell = new EditorCell_Collection(getEditorContext(), myNode, new CellLayout_Vertical());
    editorCell.setCellId("Collection_ekbrl8_c0");
    editorCell.addEditorCell(createConstant_1());
    editorCell.addEditorCell(createCollection_3());
    return editorCell;
  }
  private EditorCell createConstant_1() {
    EditorCell_Constant editorCell = new EditorCell_Constant(getEditorContext(), myNode, "");
    editorCell.setCellId("Constant_ekbrl8_a2a");
    Style style = new StyleImpl();
    style.set(StyleAttributes.SELECTABLE, false);
    editorCell.getStyle().putAll(style);
    editorCell.setDefaultText("");
    return editorCell;
  }
  private EditorCell createCollection_3() {
    EditorCell_Collection editorCell = new EditorCell_Collection(getEditorContext(), myNode, new CellLayout_Horizontal());
    editorCell.setCellId("Collection_ekbrl8_b2a");
    Style style = new StyleImpl();
    style.set(StyleAttributes.SELECTABLE, false);
    style.set(StyleAttributes.DRAW_BORDER, true);
    editorCell.getStyle().putAll(style);
    editorCell.addEditorCell(createCollection_4());
    editorCell.addEditorCell(createCollection_5());
    editorCell.addEditorCell(createCollection_6());
    if (nodeCondition_ekbrl8_a3b2a()) {
      editorCell.addEditorCell(createCollection_7());
    }
    return editorCell;
  }
  private boolean nodeCondition_ekbrl8_a3b2a() {
    return SNodeOperations.isInstanceOf(myNode, CONCEPTS.EquationEntry$bY) && !(SNodeOperations.isInstanceOf(SNodeOperations.getPrevSibling(myNode), CONCEPTS.DocumentationEntry$cW));
  }
  private EditorCell createCollection_4() {
    EditorCell_Collection editorCell = new EditorCell_Collection(getEditorContext(), myNode, new CellLayout_Vertical());
    editorCell.setCellId("Collection_ekbrl8_a1c0");
    Style style = new StyleImpl();
    style.set(StyleAttributes.SELECTABLE, false);
    editorCell.getStyle().putAll(style);
    editorCell.addEditorCell(createJComponent_0());
    return editorCell;
  }
  private EditorCell createJComponent_0() {
    EditorCell editorCell = EditorCell_Component.createComponentCell(getEditorContext(), myNode, _QueryFunction_JComponent_ekbrl8_a0a1c0(), "JComponent_ekbrl8_a0b2a");
    editorCell.setCellId("JComponent_ekbrl8_a0b2a_0");
    return editorCell;
  }
  private JComponent _QueryFunction_JComponent_ekbrl8_a0a1c0() {
    return ButtonFactory.createNextEquationButton(getEditorContext(), myNode);
  }
  private EditorCell createCollection_5() {
    EditorCell_Collection editorCell = new EditorCell_Collection(getEditorContext(), myNode, new CellLayout_Vertical());
    editorCell.setCellId("Collection_ekbrl8_b1c0");
    Style style = new StyleImpl();
    style.set(StyleAttributes.SELECTABLE, false);
    editorCell.getStyle().putAll(style);
    editorCell.addEditorCell(createJComponent_1());
    return editorCell;
  }
  private EditorCell createJComponent_1() {
    EditorCell editorCell = EditorCell_Component.createComponentCell(getEditorContext(), myNode, _QueryFunction_JComponent_ekbrl8_a0b1c0(), "JComponent_ekbrl8_a1b2a");
    editorCell.setCellId("JComponent_ekbrl8_a1b2a_0");
    return editorCell;
  }
  private JComponent _QueryFunction_JComponent_ekbrl8_a0b1c0() {
    return ButtonFactory.createNextDocumentButton(getEditorContext(), myNode);
  }
  private EditorCell createCollection_6() {
    EditorCell_Collection editorCell = new EditorCell_Collection(getEditorContext(), myNode, new CellLayout_Vertical());
    editorCell.setCellId("Collection_ekbrl8_c1c0");
    Style style = new StyleImpl();
    style.set(StyleAttributes.SELECTABLE, false);
    editorCell.getStyle().putAll(style);
    editorCell.addEditorCell(createJComponent_2());
    return editorCell;
  }
  private EditorCell createJComponent_2() {
    EditorCell editorCell = EditorCell_Component.createComponentCell(getEditorContext(), myNode, _QueryFunction_JComponent_ekbrl8_a0c1c0(), "JComponent_ekbrl8_a2b2a");
    editorCell.setCellId("JComponent_ekbrl8_a2b2a_0");
    return editorCell;
  }
  private JComponent _QueryFunction_JComponent_ekbrl8_a0c1c0() {
    return ButtonFactory.createRemoveButton(getEditorContext(), myNode);
  }
  private EditorCell createCollection_7() {
    EditorCell_Collection editorCell = new EditorCell_Collection(getEditorContext(), myNode, new CellLayout_Vertical());
    editorCell.setCellId("Collection_ekbrl8_d1c0");
    Style style = new StyleImpl();
    style.set(StyleAttributes.SELECTABLE, false);
    editorCell.getStyle().putAll(style);
    editorCell.addEditorCell(createJComponent_3());
    return editorCell;
  }
  private EditorCell createJComponent_3() {
    EditorCell editorCell = EditorCell_Component.createComponentCell(getEditorContext(), myNode, _QueryFunction_JComponent_ekbrl8_a0d1c0(), "JComponent_ekbrl8_a3b2a");
    editorCell.setCellId("JComponent_ekbrl8_a3b2a_0");
    return editorCell;
  }
  private JComponent _QueryFunction_JComponent_ekbrl8_a0d1c0() {
    return ButtonFactory.createDocumentButton(getEditorContext(), myNode);
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept ChemSheet$VW = MetaAdapterFactory.getConcept(0xa9a262e8f8054598L, 0x88c614f38937d309L, 0x6ef7184fab9f2130L, "jetbrains.mps.samples.ChemMastery.structure.ChemSheet");
    /*package*/ static final SConcept EquationEntry$bY = MetaAdapterFactory.getConcept(0xa9a262e8f8054598L, 0x88c614f38937d309L, 0x6ef7184fab9f24e0L, "jetbrains.mps.samples.ChemMastery.structure.EquationEntry");
    /*package*/ static final SConcept SheetEntry$3$ = MetaAdapterFactory.getConcept(0xa9a262e8f8054598L, 0x88c614f38937d309L, 0x6ef7184fab9f24daL, "jetbrains.mps.samples.ChemMastery.structure.SheetEntry");
    /*package*/ static final SConcept DocumentationEntry$cW = MetaAdapterFactory.getConcept(0xa9a262e8f8054598L, 0x88c614f38937d309L, 0x6ef7184fab9f24e2L, "jetbrains.mps.samples.ChemMastery.structure.DocumentationEntry");
  }

  private static final class PROPS {
    /*package*/ static final SProperty showButtons$AWXr = MetaAdapterFactory.getProperty(0xa9a262e8f8054598L, 0x88c614f38937d309L, 0x6ef7184fab9f2130L, 0x5b2638e8bdbef0c0L, "showButtons");
  }

  private static final class LINKS {
    /*package*/ static final SContainmentLink entries$Fzjl = MetaAdapterFactory.getContainmentLink(0xa9a262e8f8054598L, 0x88c614f38937d309L, 0x6ef7184fab9f2130L, 0x6ef7184fab9f24ddL, "entries");
  }
}
