package jetbrains.mps.lang.editor.intentions;
/*Generated by MPS */
import jetbrains.mps.intentions.AbstractIntentionDescriptor;
import jetbrains.mps.openapi.intentions.IntentionFactory;
import jetbrains.mps.openapi.intentions.Kind;
import jetbrains.mps.smodel.SNodePointer;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.openapi.editor.EditorContext;
import java.util.Collection;
import jetbrains.mps.openapi.intentions.IntentionExecutable;
import java.util.List;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import java.util.ArrayList;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SConceptOperations;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.internal.collections.runtime.IWhereFilter;
import jetbrains.mps.intentions.AbstractIntentionExecutable;
import jetbrains.mps.openapi.intentions.ParameterizedIntentionExecutable;
import jetbrains.mps.smodel.action.SNodeFactoryOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.lang.editor.behavior.IMenu__BehaviorDescriptor;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import jetbrains.mps.openapi.editor.EditorPanelManager;
import jetbrains.mps.openapi.intentions.IntentionDescriptor;
public final class ConvertTransformationMenu_Intention extends AbstractIntentionDescriptor implements IntentionFactory {
public ConvertTransformationMenu_Intention() {
super(Kind.NORMAL, false, new SNodePointer("r:00000000-0000-4000-0000-011c8959029b(jetbrains.mps.lang.editor.intentions)", "3597524805843504132"));
}
@Override
public String getPresentation() {
return "ConvertTransformationMenu";
}
@Override
public boolean isApplicable(final SNode node, final EditorContext editorContext) {
return true;
}
@Override
public boolean isSurroundWith() {
return false;
}
public Collection<IntentionExecutable> instances(final SNode node, final EditorContext context) {
List<IntentionExecutable> list = ListSequence.fromList(new ArrayList<IntentionExecutable>());
List<SAbstractConcept> paramList = parameter(node, context);
if (paramList != null) {
for (SAbstractConcept param : paramList) {
ListSequence.fromList(list).addElement(new ConvertTransformationMenu_Intention.IntentionImplementation(param));
}
}
return list;
}
private List<SAbstractConcept> parameter(final SNode node, final EditorContext editorContext) {
return ListSequence.fromList(SConceptOperations.getAllSubConcepts(MetaAdapterFactory.getInterfaceConcept(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x4e0f93d8a0c11832L, "jetbrains.mps.lang.editor.structure.ITransformationMenu"), SNodeOperations.getModel(node))).where(new IWhereFilter<SAbstractConcept>() {
public boolean accept(SAbstractConcept it) {
return !(it.isAbstract()) && it != SNodeOperations.getConcept(node);
}
}).toListSequence();
}
/*package*/ final class IntentionImplementation extends AbstractIntentionExecutable implements ParameterizedIntentionExecutable {
private SAbstractConcept myParameter;
public IntentionImplementation(SAbstractConcept parameter) {
myParameter = parameter;
}
@Override
public String getDescription(final SNode node, final EditorContext editorContext) {
String descr = SConceptOperations.conceptAlias(myParameter);
if ((descr == null || descr.length() == 0)) {
descr = myParameter.getName();
}
return "Convert to " + descr;
}
@Override
public void execute(final SNode node, final EditorContext editorContext) {
SNode newNode = SNodeFactoryOperations.createNewNode(SNodeFactoryOperations.asInstanceConcept(myParameter), null);
if (SNodeOperations.isInstanceOf(newNode, MetaAdapterFactory.getConcept(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x4e0f93d8a0ac3ebaL, "jetbrains.mps.lang.editor.structure.TransformationMenu"))) {
SLinkOperations.setTarget(SNodeOperations.cast(newNode, MetaAdapterFactory.getConcept(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x4e0f93d8a0ac3ebaL, "jetbrains.mps.lang.editor.structure.TransformationMenu")), MetaAdapterFactory.getReferenceLink(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x169efbc9a9048c53L, 0x5b7b4c4d511049b4L, "conceptDeclaration"), IMenu__BehaviorDescriptor.getApplicableConcept_id1quYWAD18xk.invoke(node));
}
ListSequence.fromList(SLinkOperations.getChildren(newNode, MetaAdapterFactory.getContainmentLink(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x10802efe25aL, 0x47bf8397520e5942L, "smodelAttribute"))).addSequence(ListSequence.fromList(SLinkOperations.getChildren(node, MetaAdapterFactory.getContainmentLink(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x10802efe25aL, 0x47bf8397520e5942L, "smodelAttribute"))));
SPropertyOperations.set(newNode, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x10802efe25aL, 0x115eca8579fL, "virtualPackage"), SPropertyOperations.getString(node, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x10802efe25aL, 0x115eca8579fL, "virtualPackage")));
ListSequence.fromList(SLinkOperations.getChildren(newNode, MetaAdapterFactory.getContainmentLink(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x4e0f93d8a0c11832L, 0x16be955f384efffcL, "sections"))).addSequence(ListSequence.fromList(SLinkOperations.getChildren(node, MetaAdapterFactory.getContainmentLink(0x18bc659203a64e29L, 0xa83a7ff23bde13baL, 0x4e0f93d8a0c11832L, 0x16be955f384efffcL, "sections"))));
SNodeOperations.replaceWithAnother(node, newNode);
if ((SNodeOperations.getParent(newNode) == null)) {
// We replaced a root node with a root node, open the new node in the editor
EditorPanelManager editorPanelManager = editorContext.getEditorPanelManager();
if (editorPanelManager != null) {
editorPanelManager.openEditor(newNode);
}
}
}
@Override
public IntentionDescriptor getDescriptor() {
return ConvertTransformationMenu_Intention.this;
}
public Object getParameter() {
return myParameter;
}
}
}