package jetbrains.mps.lang.editor.tableTests.editor;
/*Generated by MPS */
import jetbrains.mps.nodeEditor.cellMenu.AbstractNodeSubstituteInfo;
import org.jetbrains.mps.openapi.model.SNode;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import jetbrains.mps.openapi.editor.EditorContext;
import java.util.List;
import jetbrains.mps.openapi.editor.cells.SubstituteAction;
import jetbrains.mps.smodel.action.ModelActions;
import jetbrains.mps.smodel.action.AbstractChildNodeSetter;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.smodel.action.SNodeFactoryOperations;
/*package*/ class StateMachineSubstituteInfo extends AbstractNodeSubstituteInfo {
private final int myRow;
private final int myColumn;
private final SNode myParent;
private final SContainmentLink myLink;
private final SNode myCurrentChild;
public StateMachineSubstituteInfo(EditorContext editorContext, int row, int column, SNode parent, SNode currentChild, SContainmentLink link) {
super(editorContext);
myRow = row;
myColumn = column;
myParent = parent;
myCurrentChild = currentChild;
myLink = link;
}
@Override
protected List<SubstituteAction> createActions() {
return ModelActions.createChildNodeSubstituteActions(myParent, myCurrentChild, myLink, null, new AbstractChildNodeSetter() {
@Override
public SNode doExecute(SNode parentNode, SNode oldChild, SNode newChild, @Nullable EditorContext editorContext) {
if (myCurrentChild != null) {
SNodeOperations.replaceWithAnother(myCurrentChild, newChild);
} else {
if (myRow == 0) {
SNodeOperations.insertPrevSiblingChild(ListSequence.fromList(SLinkOperations.getChildren(myParent, MetaAdapterFactory.getContainmentLink(0xdf8799e7254a406fL, 0xbd67f4cc27337152L, 0xa99ffe1c8456ba1L, 0xa99ffe1c8456ba3L, "events"))).getElement(myColumn - 1), newChild);
}
if (myColumn == 0) {
SNodeOperations.insertPrevSiblingChild(ListSequence.fromList(SLinkOperations.getChildren(myParent, MetaAdapterFactory.getContainmentLink(0xdf8799e7254a406fL, 0xbd67f4cc27337152L, 0xa99ffe1c8456ba1L, 0xa99ffe1c8456ba5L, "states"))).getElement(myRow - 1), newChild);
}
if (myRow > 0 && myColumn > 0) {
ListSequence.fromList(SLinkOperations.getChildren(myParent, MetaAdapterFactory.getContainmentLink(0xdf8799e7254a406fL, 0xbd67f4cc27337152L, 0xa99ffe1c8456ba1L, 0xa99ffe1c8456ba4L, "transitions"))).addElement((SNode) newChild);
}
}
if (myRow > 0 && myColumn > 0) {
SNode event = ListSequence.fromList(SLinkOperations.getChildren(myParent, MetaAdapterFactory.getContainmentLink(0xdf8799e7254a406fL, 0xbd67f4cc27337152L, 0xa99ffe1c8456ba1L, 0xa99ffe1c8456ba3L, "events"))).getElement(myColumn - 1);
SNode state = ListSequence.fromList(SLinkOperations.getChildren(myParent, MetaAdapterFactory.getContainmentLink(0xdf8799e7254a406fL, 0xbd67f4cc27337152L, 0xa99ffe1c8456ba1L, 0xa99ffe1c8456ba5L, "states"))).getElement(myRow - 1);
SNode transition = (SNode) newChild;
SLinkOperations.setTarget(transition, MetaAdapterFactory.getContainmentLink(0xdf8799e7254a406fL, 0xbd67f4cc27337152L, 0xa99ffe1c845743dL, 0xa99ffe1c845743fL, "trigger"), SNodeFactoryOperations.createNewNode(SNodeFactoryOperations.asInstanceConcept(MetaAdapterFactory.getConcept(0xdf8799e7254a406fL, 0xbd67f4cc27337152L, 0xa99ffe1c8457446L, "jetbrains.mps.lang.editor.tableTests.structure.EventReference")), null));
SLinkOperations.setTarget(SLinkOperations.getTarget(transition, MetaAdapterFactory.getContainmentLink(0xdf8799e7254a406fL, 0xbd67f4cc27337152L, 0xa99ffe1c845743dL, 0xa99ffe1c845743fL, "trigger")), MetaAdapterFactory.getReferenceLink(0xdf8799e7254a406fL, 0xbd67f4cc27337152L, 0xa99ffe1c8457446L, 0xa99ffe1c8457447L, "event"), event);
SLinkOperations.setTarget(transition, MetaAdapterFactory.getContainmentLink(0xdf8799e7254a406fL, 0xbd67f4cc27337152L, 0xa99ffe1c845743dL, 0xa99ffe1c845743eL, "fromState"), SNodeFactoryOperations.createNewNode(SNodeFactoryOperations.asInstanceConcept(MetaAdapterFactory.getConcept(0xdf8799e7254a406fL, 0xbd67f4cc27337152L, 0xa99ffe1c8457444L, "jetbrains.mps.lang.editor.tableTests.structure.StateReference")), null));
SLinkOperations.setTarget(SLinkOperations.getTarget(transition, MetaAdapterFactory.getContainmentLink(0xdf8799e7254a406fL, 0xbd67f4cc27337152L, 0xa99ffe1c845743dL, 0xa99ffe1c845743eL, "fromState")), MetaAdapterFactory.getReferenceLink(0xdf8799e7254a406fL, 0xbd67f4cc27337152L, 0xa99ffe1c8457444L, 0xa99ffe1c8457445L, "state"), state);
}
return newChild;
}
}, getEditorContext());
}
}