public void execute(final SNode node, final EditorContext editorContext) { SNode ifStatement = SNodeFactoryOperations.createNewNode( "jetbrains.mps.baseLanguage.structure.IfStatement", null); List<SNode> selectedNodes = editorContext.getSelectedNodes(); SNodeOperations.insertNextSiblingChild( ListSequence.fromList(selectedNodes).last(), ifStatement); for (SNode selectedNode : ListSequence.fromList(selectedNodes)) { ListSequence.fromList( SLinkOperations.getTargets( SLinkOperations.getTarget(ifStatement, "ifTrue", true), "statement", true)) .addElement( SNodeOperations.getAncestor( selectedNode, "jetbrains.mps.baseLanguage.structure.Statement", true, false)); } editorContext.select(SLinkOperations.getTarget(ifStatement, "condition", true)); }
public void execute(final SNode node, final EditorContext editorContext) { SNode result = SNodeFactoryOperations.createNewNode( "jetbrains.mps.lang.editor.structure.CellModel_Collection", null); SLinkOperations.setTarget( result, "cellLayout", SNodeFactoryOperations.createNewNode( "jetbrains.mps.lang.editor.structure.CellLayout_Horizontal", null), true); List<SNode> nodes = editorContext.getSelectedNodes(); SNodeOperations.insertNextSiblingChild(ListSequence.fromList(nodes).last(), result); for (SNode sn : nodes) { ListSequence.fromList(SLinkOperations.getTargets(result, "childCellModel", true)) .addElement( SNodeOperations.cast(sn, "jetbrains.mps.lang.editor.structure.EditorCellModel")); } }
@Override public void execute(final SNode node, final EditorContext editorContext) { SNode routineDefinition = SNodeFactoryOperations.createNewNode( SNodeFactoryOperations.asInstanceConcept( MetaAdapterFactory.getConcept( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2de971c785ed6f79L, "jetbrains.mps.samples.Kaja.structure.RoutineDefinition")), null); List<SNode> selectedNodes = editorContext.getSelectedNodes(); ListSequence.fromList( SLinkOperations.getChildren( SLinkOperations.getTarget( SNodeOperations.getNodeAncestor( node, MetaAdapterFactory.getConcept( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2d523c5e4cc45746L, "jetbrains.mps.samples.Kaja.structure.Script"), true, false), MetaAdapterFactory.getContainmentLink( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2d523c5e4cc45746L, 0x2d523c5e4cc4574cL, "body")), MetaAdapterFactory.getContainmentLink( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2de971c785f06a3fL, 0x2de971c785f06a40L, "commands"))) .addElement(routineDefinition); SNode call = SConceptOperations.createNewNode( MetaAdapterFactory.getConcept( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2de971c785ed6f92L, "jetbrains.mps.samples.Kaja.structure.RoutineCall")); SLinkOperations.setTarget( call, MetaAdapterFactory.getReferenceLink( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2de971c785ed6f92L, 0x2de971c785ede3ccL, "definition"), routineDefinition); SNodeOperations.insertPrevSiblingChild(ListSequence.fromList(selectedNodes).first(), call); for (SNode selectedNode : ListSequence.fromList(selectedNodes)) { ListSequence.fromList( SLinkOperations.getChildren( SLinkOperations.getTarget( routineDefinition, MetaAdapterFactory.getContainmentLink( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2de971c785ed6f79L, 0x2de971c785ed6f7cL, "body")), MetaAdapterFactory.getContainmentLink( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2de971c785f06a3fL, 0x2de971c785f06a40L, "commands"))) .addElement( SNodeOperations.getNodeAncestor( selectedNode, MetaAdapterFactory.getConcept( 0x49a08c51fe543ccL, 0xbd998b46d641d7f5L, 0x2d523c5e4cc4574aL, "jetbrains.mps.samples.Kaja.structure.AbstractCommand"), true, false)); } editorContext.selectWRTFocusPolicy(routineDefinition); }
private boolean isApplicableToNode(final SNode node, final EditorContext editorContext) { return ListSequence.fromList(((List<SNode>) editorContext.getSelectedNodes())).isNotEmpty(); }