package jetbrains.mps.lang.test.runtime;
/*Generated by MPS */
import org.jetbrains.mps.openapi.model.SNode;
import java.util.Map;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import jetbrains.mps.openapi.editor.EditorComponent;
import jetbrains.mps.nodeEditor.NodeEditorComponent;
import jetbrains.mps.lang.test.behavior.AnonymousCellAnnotation__BehaviorDescriptor;
import jetbrains.mps.nodeEditor.inspector.InspectorEditorComponent;
import jetbrains.mps.openapi.editor.selection.Selection;
import jetbrains.mps.openapi.editor.selection.SingularSelection;
import jetbrains.mps.openapi.editor.cells.EditorCell;
import junit.framework.Assert;
import jetbrains.mps.internal.collections.runtime.MapSequence;
import jetbrains.mps.nodeEditor.cells.EditorCell_Label;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.nodeEditor.selection.NodeRangeSelection;
public class CellReference {
private SNode myNode;
private SNode myAnnotation;
private Map<SNode, SNode> myMap;
public CellReference(SNode node, SNode annotation, Map<SNode, SNode> map) {
myNode = node;
myAnnotation = SNodeOperations.cast(annotation, MetaAdapterFactory.getConcept(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x11e31babe12L, "jetbrains.mps.lang.test.structure.AnonymousCellAnnotation"));
myMap = map;
}
public SNode getNode() {
return this.myNode;
}
@Override
public String toString() {
return "(node " + myNode.getNodeId().toString() + ", id " + SPropertyOperations.getString(myAnnotation, MetaAdapterFactory.getProperty(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x11e31babe12L, 0x11e31babe13L, "cellId")) + ")";
}
public EditorComponent setupSelection(NodeEditorComponent editorComponent) {
return AnonymousCellAnnotation__BehaviorDescriptor.setupSelection_id5g7DxxpaP55.invoke(myAnnotation, editorComponent, myNode, myMap);
}
public void assertSelectionIsTheSame(EditorComponent editorComponent, Map<SNode, SNode> map) {
if (SPropertyOperations.getBoolean(myAnnotation, MetaAdapterFactory.getProperty(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x11e31babe12L, 0x1b73330fb1241e01L, "isInInspector"))) {
assert editorComponent instanceof InspectorEditorComponent;
}
Selection selection = editorComponent.getSelectionManager().getSelection();
assert selection != null : "Selection was not set in the resulting editor";
if (selection instanceof SingularSelection) {
EditorCell selectedCell = ((SingularSelection) selection).getEditorCell();
Assert.assertSame(getNode(), MapSequence.fromMap(map).get(selectedCell.getSNode()));
Assert.assertEquals(SPropertyOperations.getString(myAnnotation, MetaAdapterFactory.getProperty(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x11e31babe12L, 0x11e31babe13L, "cellId")), selectedCell.getCellId());
if (selectedCell instanceof EditorCell_Label) {
EditorCell_Label label = (EditorCell_Label) selectedCell;
Assert.assertEquals(SPropertyOperations.getInteger(myAnnotation, MetaAdapterFactory.getProperty(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x11e31babe12L, 0x56ffc0a94fe5fc33L, "selectionStart")), label.getSelectionStart());
Assert.assertEquals(SPropertyOperations.getInteger(myAnnotation, MetaAdapterFactory.getProperty(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x11e31babe12L, 0x56ffc0a94fe5fc35L, "selectionEnd")), label.getSelectionEnd());
}
Assert.assertNull(SLinkOperations.getTarget(myAnnotation, MetaAdapterFactory.getReferenceLink(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x11e31babe12L, 0x1ad0cd452e1f9accL, "nodeRangeSelectionStart")));
Assert.assertNull(SLinkOperations.getTarget(myAnnotation, MetaAdapterFactory.getReferenceLink(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x11e31babe12L, 0x1ad0cd452e1f9acdL, "nodeRangeSelectionEnd")));
} else if (selection instanceof NodeRangeSelection) {
NodeRangeSelection rangeSelection = (NodeRangeSelection) selection;
Assert.assertNotNull(SLinkOperations.getTarget(myAnnotation, MetaAdapterFactory.getReferenceLink(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x11e31babe12L, 0x1ad0cd452e1f9accL, "nodeRangeSelectionStart")));
Assert.assertNotNull(SLinkOperations.getTarget(myAnnotation, MetaAdapterFactory.getReferenceLink(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x11e31babe12L, 0x1ad0cd452e1f9acdL, "nodeRangeSelectionEnd")));
Assert.assertEquals(MapSequence.fromMap(myMap).get(SLinkOperations.getTarget(myAnnotation, MetaAdapterFactory.getReferenceLink(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x11e31babe12L, 0x1ad0cd452e1f9accL, "nodeRangeSelectionStart"))), MapSequence.fromMap(map).get(rangeSelection.getFirstNode()));
Assert.assertEquals(MapSequence.fromMap(myMap).get(SLinkOperations.getTarget(myAnnotation, MetaAdapterFactory.getReferenceLink(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x11e31babe12L, 0x1ad0cd452e1f9acdL, "nodeRangeSelectionEnd"))), MapSequence.fromMap(map).get(rangeSelection.getLastNode()));
} else {
Assert.fail("Selection of unsupported type: " + selection.getClass());
}
}
}