package jetbrains.mps.lang.actions.testLanguage.editor; /*Generated by MPS */ import jetbrains.mps.nodeEditor.menus.substitute.SubstituteMenuBase; import org.jetbrains.annotations.NotNull; import java.util.List; import jetbrains.mps.lang.editor.menus.MenuPart; import jetbrains.mps.openapi.editor.menus.substitute.SubstituteMenuItem; import jetbrains.mps.openapi.editor.menus.substitute.SubstituteMenuContext; import java.util.ArrayList; import jetbrains.mps.lang.editor.menus.GroupMenuPart; import jetbrains.mps.lang.actions.testLanguage.actions.StringHolder; import jetbrains.mps.util.Computable; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import java.util.Arrays; import jetbrains.mps.lang.editor.menus.substitute.ConstraintsFilteringSubstituteMenuPartDecorator; import jetbrains.mps.lang.editor.menus.substitute.SingleItemSubstituteMenuPart; import org.jetbrains.annotations.Nullable; import jetbrains.mps.lang.editor.menus.substitute.DefaultSubstituteMenuItem; import org.jetbrains.mps.openapi.model.SNode; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SConceptOperations; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations; import jetbrains.mps.smodel.runtime.IconResource; import jetbrains.mps.smodel.runtime.IconResourceUtil; import jetbrains.mps.editor.runtime.selection.SelectionUtil; import jetbrains.mps.internal.collections.runtime.ListSequence; import jetbrains.mps.openapi.editor.selection.SelectionManager; import jetbrains.mps.openapi.editor.cells.EditorCell; import jetbrains.mps.openapi.editor.cells.CellTraversalUtil; import jetbrains.mps.nodeEditor.cells.EditorCell_Label; import org.jetbrains.mps.openapi.persistence.PersistenceFacade; import jetbrains.mps.smodel.SModelUtil_new; import jetbrains.mps.smodel.SReference; public class AddMenuPart_SimpleItemSubstitute extends SubstituteMenuBase { @NotNull @Override protected List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> getParts(final SubstituteMenuContext _context) { List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> result = new ArrayList<MenuPart<SubstituteMenuItem, SubstituteMenuContext>>(); result.add(new AddMenuPart_SimpleItemSubstitute.SMP_Group_mw8afp_a()); return result; } public class SMP_Group_mw8afp_a extends GroupMenuPart<SubstituteMenuItem, SubstituteMenuContext> { private StringHolder firstMatchingText; @Override protected void initialize(SubstituteMenuContext _context) { super.initialize(_context); firstMatchingText = new Computable<StringHolder>() { public StringHolder compute() { // additional compilation test for all passed parameters boolean tmpVar = _context.getParentNode() != null; tmpVar = tmpVar && _context.getCurrentTargetNode() != null; tmpVar = tmpVar && _context.getLink() != null; tmpVar = tmpVar && _context.getEditorContext() != null; tmpVar = tmpVar && _context.getModel() != null; return new StringHolder(); } }.compute(); } @Override protected boolean isApplicable(SubstituteMenuContext _context) { return eq_mw8afp_a0a0c1(_context.getLink(), MetaAdapterFactory.getContainmentLink(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x2365c14e1671696fL, 0x232dec78ad89892aL, "addMenu_simpleItemSubstitute")); } @Override protected List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> getParts() { return Arrays.<MenuPart<SubstituteMenuItem, SubstituteMenuContext>>asList(new ConstraintsFilteringSubstituteMenuPartDecorator(new AddMenuPart_SimpleItemSubstitute.SMP_Group_mw8afp_a.SMP_Action_mw8afp_a0(), MetaAdapterFactory.getConcept(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x2365c14e167220f9L, "jetbrains.mps.lang.actions.testLanguage.structure.ActionTestChild1")), new ConstraintsFilteringSubstituteMenuPartDecorator(new AddMenuPart_SimpleItemSubstitute.SMP_Group_mw8afp_a.SMP_Action_mw8afp_b0(), MetaAdapterFactory.getConcept(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x2365c14e167220f9L, "jetbrains.mps.lang.actions.testLanguage.structure.ActionTestChild1")), new ConstraintsFilteringSubstituteMenuPartDecorator(new AddMenuPart_SimpleItemSubstitute.SMP_Group_mw8afp_a.SMP_Action_mw8afp_c0(), MetaAdapterFactory.getConcept(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x2365c14e1672224dL, "jetbrains.mps.lang.actions.testLanguage.structure.ActionTestChild2"))); } private class SMP_Action_mw8afp_a0 extends SingleItemSubstituteMenuPart { @Nullable @Override protected SubstituteMenuItem createItem(SubstituteMenuContext _context) { return new AddMenuPart_SimpleItemSubstitute.SMP_Group_mw8afp_a.SMP_Action_mw8afp_a0.Item(_context); } private class Item extends DefaultSubstituteMenuItem { private final SubstituteMenuContext _context; public Item(SubstituteMenuContext context) { super(MetaAdapterFactory.getConcept(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x2365c14e167220f9L, "jetbrains.mps.lang.actions.testLanguage.structure.ActionTestChild1"), context.getParentNode(), context.getCurrentTargetNode(), context.getEditorContext()); _context = context; } @Nullable @Override public SNode createNode(@NotNull String pattern) { // compilation test for all passed parameters boolean tmpVar = pattern != null; tmpVar = tmpVar && _context.getParentNode() != null; tmpVar = tmpVar && _context.getCurrentTargetNode() != null; tmpVar = tmpVar && _context.getLink() != null; tmpVar = tmpVar && _context.getModel() != null; SNode result = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x2365c14e167220f9L, "jetbrains.mps.lang.actions.testLanguage.structure.ActionTestChild1")); SLinkOperations.addNewChild(result, MetaAdapterFactory.getContainmentLink(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x2365c14e167220f9L, 0x7f805f0c2dd46343L, "child1"), MetaAdapterFactory.getConcept(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x7f805f0c2dd45b4eL, "jetbrains.mps.lang.actions.testLanguage.structure.ActionTestChild1Child")); return result; } @Nullable @Override public String getMatchingText(@NotNull String pattern) { // compilation test for all passed parameters boolean tmpVar = pattern != null; tmpVar = tmpVar && _context.getParentNode() != null; tmpVar = tmpVar && _context.getCurrentTargetNode() != null; tmpVar = tmpVar && _context.getLink() != null; tmpVar = tmpVar && _context.getModel() != null; return firstMatchingText.matchingText; } @Nullable @Override public String getDescriptionText(@NotNull String pattern) { // compilation test for all passed parameters boolean tmpVar = pattern != null; tmpVar = tmpVar && _context.getParentNode() != null; tmpVar = tmpVar && _context.getCurrentTargetNode() != null; tmpVar = tmpVar && _context.getLink() != null; tmpVar = tmpVar && _context.getModel() != null; return "Description of " + firstMatchingText.matchingText; } @Nullable @Override public SNode getType(@NotNull String pattern) { // compilation test for all passed parameters boolean tmpVar = pattern != null; tmpVar = tmpVar && _context.getParentNode() != null; tmpVar = tmpVar && _context.getCurrentTargetNode() != null; tmpVar = tmpVar && _context.getLink() != null; tmpVar = tmpVar && _context.getModel() != null; return _quotation_createNode_mw8afp_a7a0c0a(); } @Nullable @Override public IconResource getIcon(@NotNull String pattern) { // compilation test for all passed parameters boolean tmpVar = pattern != null; tmpVar = tmpVar && _context.getParentNode() != null; tmpVar = tmpVar && _context.getCurrentTargetNode() != null; tmpVar = tmpVar && _context.getLink() != null; tmpVar = tmpVar && _context.getModel() != null; return IconResourceUtil.getIconResourceForConcept(MetaAdapterFactory.getConcept(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x2365c14e167220f9L, "jetbrains.mps.lang.actions.testLanguage.structure.ActionTestChild1")); } @Override public boolean canExecute(@NotNull String pattern) { return canExecute_internal(pattern, false); } @Override public boolean canExecuteStrictly(@NotNull String pattern) { return canExecute_internal(pattern, true); } public boolean canExecute_internal(@NotNull String pattern, boolean strictly) { // compilation test for all passed parameters boolean tmpVar = pattern != null; tmpVar = tmpVar && strictly; tmpVar = tmpVar && _context.getParentNode() != null; tmpVar = tmpVar && _context.getCurrentTargetNode() != null; tmpVar = tmpVar && _context.getLink() != null; tmpVar = tmpVar && _context.getModel() != null; return (strictly ? firstMatchingText.matchingText.equals(pattern) : firstMatchingText.matchingText.startsWith(pattern)); } @Override public void select(@NotNull SNode createdNode, @NotNull String pattern) { // returning node to select SelectionUtil.selectLabelCellAnSetCaret(_context.getEditorContext(), ListSequence.fromList(SLinkOperations.getChildren(createdNode, MetaAdapterFactory.getContainmentLink(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x2365c14e167220f9L, 0x7f805f0c2dd46343L, "child1"))).first(), SelectionManager.FIRST_ERROR_CELL + "|" + SelectionManager.FOCUS_POLICY_CELL + "|" + SelectionManager.FIRST_EDITABLE_CELL + "|" + SelectionManager.FIRST_CELL, -1); } } } private class SMP_Action_mw8afp_b0 extends SingleItemSubstituteMenuPart { @Nullable @Override protected SubstituteMenuItem createItem(SubstituteMenuContext _context) { return new AddMenuPart_SimpleItemSubstitute.SMP_Group_mw8afp_a.SMP_Action_mw8afp_b0.Item(_context); } private class Item extends DefaultSubstituteMenuItem { private final SubstituteMenuContext _context; public Item(SubstituteMenuContext context) { super(MetaAdapterFactory.getConcept(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x2365c14e167220f9L, "jetbrains.mps.lang.actions.testLanguage.structure.ActionTestChild1"), context.getParentNode(), context.getCurrentTargetNode(), context.getEditorContext()); _context = context; } @Nullable @Override public SNode createNode(@NotNull String pattern) { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x2c99ba4dd5ff2533L, "jetbrains.mps.lang.actions.testLanguage.structure.ActionTestChild1SubConcept")); } @Nullable @Override public String getMatchingText(@NotNull String pattern) { return "newChild2_fake_filtered"; } @Override public boolean canExecute(@NotNull String pattern) { return canExecute_internal(pattern, false); } @Override public boolean canExecuteStrictly(@NotNull String pattern) { return canExecute_internal(pattern, true); } public boolean canExecute_internal(@NotNull String pattern, boolean strictly) { return false; } } } private class SMP_Action_mw8afp_c0 extends SingleItemSubstituteMenuPart { @Nullable @Override protected SubstituteMenuItem createItem(SubstituteMenuContext _context) { return new AddMenuPart_SimpleItemSubstitute.SMP_Group_mw8afp_a.SMP_Action_mw8afp_c0.Item(_context); } private class Item extends DefaultSubstituteMenuItem { private final SubstituteMenuContext _context; public Item(SubstituteMenuContext context) { super(MetaAdapterFactory.getConcept(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x2365c14e1672224dL, "jetbrains.mps.lang.actions.testLanguage.structure.ActionTestChild2"), context.getParentNode(), context.getCurrentTargetNode(), context.getEditorContext()); _context = context; } @Nullable @Override public SNode createNode(@NotNull String pattern) { return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x2365c14e1672224dL, "jetbrains.mps.lang.actions.testLanguage.structure.ActionTestChild2")); } @Nullable @Override public String getMatchingText(@NotNull String pattern) { return "newChild2"; } @Nullable @Override public String getDescriptionText(@NotNull String pattern) { return "NewChild2 description text"; } @Nullable @Override public SNode getType(@NotNull String pattern) { return _quotation_createNode_mw8afp_a0a0c2a(); } @Override public void select(@NotNull SNode createdNode, @NotNull String pattern) { // compilation test for all passed parameters boolean tmpVar = pattern != null; tmpVar = tmpVar && _context.getParentNode() != null; tmpVar = tmpVar && createdNode != null; tmpVar = tmpVar && _context.getLink() != null; tmpVar = tmpVar && _context.getModel() != null; tmpVar = tmpVar && _context.getEditorContext() != null; // selecting a custom cell _context.getEditorContext().flushEvents(); EditorCell createdNodeCell = _context.getEditorContext().getEditorComponent().findNodeCell(createdNode); if (createdNodeCell != null) { EditorCell firstLeaf = CellTraversalUtil.getFirstLeaf(createdNodeCell); _context.getEditorContext().getEditorComponent().changeSelection(firstLeaf); if (firstLeaf instanceof EditorCell_Label) { ((EditorCell_Label) firstLeaf).setCaretPosition(3); } return; } SelectionUtil.selectLabelCellAnSetCaret(_context.getEditorContext(), createdNode, SelectionManager.FIRST_ERROR_CELL + "|" + SelectionManager.FOCUS_POLICY_CELL + "|" + SelectionManager.FIRST_EDITABLE_CELL + "|" + SelectionManager.FIRST_CELL, -1); } } } } private static boolean eq_mw8afp_a0a0c1(Object a, Object b) { return (a != null ? a.equals(b) : a == b); } private static SNode _quotation_createNode_mw8afp_a7a0c0a() { PersistenceFacade facade = PersistenceFacade.getInstance(); SNode quotedNode_1 = null; quotedNode_1 = SModelUtil_new.instantiateConceptDeclaration(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0x7866978ea0f04cc7L, 0x81bc4d213d9375e1L, "jetbrains.mps.lang.smodel"), 0x108f968b3caL, "SNodeType"), null, null, false); quotedNode_1.setReference(MetaAdapterFactory.getReferenceLink(0x7866978ea0f04cc7L, 0x81bc4d213d9375e1L, 0x108f968b3caL, 0x1090e46ca51L, "concept"), SReference.create(MetaAdapterFactory.getReferenceLink(0x7866978ea0f04cc7L, 0x81bc4d213d9375e1L, 0x108f968b3caL, 0x1090e46ca51L, "concept"), quotedNode_1, facade.createModelReference("r:4d38763d-a252-449a-a228-c5edf22068a3(jetbrains.mps.lang.actions.testLanguage.structure)"), facade.createNodeId("2550657305103442169"))); return quotedNode_1; } private static SNode _quotation_createNode_mw8afp_a0a0c2a() { PersistenceFacade facade = PersistenceFacade.getInstance(); SNode quotedNode_1 = null; quotedNode_1 = SModelUtil_new.instantiateConceptDeclaration(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0x7866978ea0f04cc7L, 0x81bc4d213d9375e1L, "jetbrains.mps.lang.smodel"), 0x108f968b3caL, "SNodeType"), null, null, false); quotedNode_1.setReference(MetaAdapterFactory.getReferenceLink(0x7866978ea0f04cc7L, 0x81bc4d213d9375e1L, 0x108f968b3caL, 0x1090e46ca51L, "concept"), SReference.create(MetaAdapterFactory.getReferenceLink(0x7866978ea0f04cc7L, 0x81bc4d213d9375e1L, 0x108f968b3caL, 0x1090e46ca51L, "concept"), quotedNode_1, facade.createModelReference("r:4d38763d-a252-449a-a228-c5edf22068a3(jetbrains.mps.lang.actions.testLanguage.structure)"), facade.createNodeId("2550657305103442509"))); return quotedNode_1; } }