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.substitute.ConstraintsFilteringSubstituteMenuPartDecorator;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.lang.editor.menus.ParameterizedMenuPart;
import org.jetbrains.mps.openapi.language.SConcept;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SConceptOperations;
import jetbrains.mps.lang.editor.menus.substitute.SingleItemSubstituteMenuPart;
import jetbrains.mps.lang.editor.menus.substitute.DefaultSubstituteMenuItem;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import jetbrains.mps.smodel.presentation.NodePresentationUtil;
import jetbrains.mps.smodel.runtime.IconResource;
import jetbrains.mps.smodel.runtime.IconResourceUtil;
import jetbrains.mps.openapi.editor.cells.EditorCell;
import jetbrains.mps.openapi.editor.cells.CellTraversalUtil;
import jetbrains.mps.nodeEditor.cells.EditorCell_Label;
import jetbrains.mps.editor.runtime.selection.SelectionUtil;
import jetbrains.mps.openapi.editor.selection.SelectionManager;
public class ActionTestChildToWrap1_SubstituteMenu 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 ConstraintsFilteringSubstituteMenuPartDecorator(new ActionTestChildToWrap1_SubstituteMenu.SMP_Param_kxaev4_a(), MetaAdapterFactory.getConcept(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x47ad1fca2ee71badL, "jetbrains.mps.lang.actions.testLanguage.structure.ActionTestChildToWrap1")));
return result;
}
private class SMP_Param_kxaev4_a extends ParameterizedMenuPart<SConcept, SubstituteMenuItem, SubstituteMenuContext> {
@NotNull
@Override
protected List<SubstituteMenuItem> createItems(SConcept parameter, SubstituteMenuContext context) {
return new ActionTestChildToWrap1_SubstituteMenu.SMP_Param_kxaev4_a.SMP_Action_kxaev4_a0(parameter).createItems(context);
}
@Nullable
@Override
protected Iterable<? extends SConcept> getParameters(SubstituteMenuContext _context) {
return SConceptOperations.getAllSubConcepts2(MetaAdapterFactory.getConcept(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x47ad1fca2ee71badL, "jetbrains.mps.lang.actions.testLanguage.structure.ActionTestChildToWrap1"), _context.getModel());
}
private class SMP_Action_kxaev4_a0 extends SingleItemSubstituteMenuPart {
private final SConcept myParameterObject;
public SMP_Action_kxaev4_a0(SConcept parameterObject) {
myParameterObject = parameterObject;
}
@Nullable
@Override
protected SubstituteMenuItem createItem(SubstituteMenuContext _context) {
return new ActionTestChildToWrap1_SubstituteMenu.SMP_Param_kxaev4_a.SMP_Action_kxaev4_a0.Item(_context);
}
private class Item extends DefaultSubstituteMenuItem {
private final SubstituteMenuContext _context;
public Item(SubstituteMenuContext context) {
super(MetaAdapterFactory.getConcept(0x737ed1fffa634ebcL, 0xa834435499b23c64L, 0x47ad1fca2ee71badL, "jetbrains.mps.lang.actions.testLanguage.structure.ActionTestChildToWrap1"), context.getParentNode(), context.getCurrentTargetNode(), context.getEditorContext());
_context = context;
}
@Nullable
@Override
public SNode createNode(@NotNull String pattern) {
return SConceptOperations.createNewNode(SNodeOperations.asInstanceConcept(myParameterObject));
}
@Nullable
@Override
public String getMatchingText(@NotNull String pattern) {
if (myParameterObject instanceof SAbstractConcept) {
return NodePresentationUtil.matchingText((SAbstractConcept) myParameterObject);
}
return "" + myParameterObject;
}
@Nullable
@Override
public String getDescriptionText(@NotNull String pattern) {
if (myParameterObject instanceof SAbstractConcept) {
return NodePresentationUtil.descriptionText((SAbstractConcept) myParameterObject);
}
return "" + myParameterObject;
}
@Nullable
@Override
public IconResource getIcon(@NotNull String pattern) {
if (myParameterObject instanceof SAbstractConcept) {
return IconResourceUtil.getIconResourceForConcept(((SAbstractConcept) myParameterObject));
}
return null;
}
@Override
public void select(@NotNull SNode createdNode, @NotNull String pattern) {
// 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(5);
}
return;
}
SelectionUtil.selectLabelCellAnSetCaret(_context.getEditorContext(), createdNode, SelectionManager.FIRST_ERROR_CELL + "|" + SelectionManager.FOCUS_POLICY_CELL + "|" + SelectionManager.FIRST_EDITABLE_CELL + "|" + SelectionManager.FIRST_CELL, -1);
}
}
}
}
}