package jetbrains.mps.lang.structure.pluginSolution.plugin;
/*Generated by MPS */
import jetbrains.mps.ide.platform.actions.core.MoveNodesAction;
import jetbrains.mps.baseLanguage.closures.runtime._FunctionTypes;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.project.MPSProject;
import java.util.List;
import jetbrains.mps.ide.platform.actions.core.MoveNodesUtil;
import jetbrains.mps.baseLanguage.closures.runtime.Wrappers;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import com.intellij.openapi.ui.Messages;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.ide.refactoring.MoveUpDialog;
import jetbrains.mps.internal.collections.runtime.MapSequence;
import java.util.HashMap;
import java.util.ArrayList;
import jetbrains.mps.ide.platform.refactoring.NodeLocation;
import jetbrains.mps.smodel.structure.Extension;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.internal.collections.runtime.IWhereFilter;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
public class MoveFeatureUp implements MoveNodesAction {
private String myName;
private String myKind;
private _FunctionTypes._return_P1_E0<? extends Boolean, ? super SNode> myApplicableToConceptFeature;
private _FunctionTypes._return_P2_E0<? extends SNode, ? super SNode, ? super SNode> myNeedToMerge;
public MoveFeatureUp(String name, String kind, _FunctionTypes._return_P1_E0<? extends Boolean, ? super SNode> applicableToConceptFeature, _FunctionTypes._return_P2_E0<? extends SNode, ? super SNode, ? super SNode> needToMerge) {
myName = name;
myKind = kind;
myApplicableToConceptFeature = applicableToConceptFeature;
myNeedToMerge = needToMerge;
}
public String getName() {
return myName;
}
public boolean isApplicable(MPSProject project, final List<SNode> nodesToMove) {
if (!(MoveNodesUtil.areSiblings(nodesToMove, project.getRepository()))) {
return false;
}
final Wrappers._boolean result = new Wrappers._boolean();
project.getRepository().getModelAccess().runReadAction(new Runnable() {
public void run() {
result.value = myApplicableToConceptFeature.invoke(ListSequence.fromList(nodesToMove).first());
}
});
return result.value;
}
public void execute(final MPSProject project, List<SNode> nodesToMove) {
final String featureKind = this.myKind;
if (ListSequence.fromList(nodesToMove).count() > 1) {
Messages.showErrorDialog(project.getProject(), "Moving multiple concept elements is not supported.\n" + "Please, select single " + featureKind + ".", "Select single " + featureKind + ".");
return;
}
final SNode feature = SNodeOperations.cast(ListSequence.fromList(nodesToMove).first(), MetaAdapterFactory.getInterfaceConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x11d2ea63881L, "jetbrains.mps.lang.structure.structure.IStructureDeprecatable"));
final SNode targetConcept = MoveUpDialog.getConcept(project, feature, featureKind);
if (targetConcept == null) {
return;
}
final Wrappers._T<SNode> mergeTarget = new Wrappers._T<SNode>();
project.getRepository().getModelAccess().runReadAction(new Runnable() {
public void run() {
mergeTarget.value = myNeedToMerge.invoke(feature, targetConcept);
}
});
boolean merge = false;
if (mergeTarget.value != null) {
int wantToMerge;
wantToMerge = Messages.showYesNoCancelDialog(project.getProject(), "Target concept already has " + myKind + " with the same name. Do you want to merge?\n" + "You might have to update instances manually in case of value conflicts.", "Do you want to merge?", null);
if (wantToMerge == Messages.YES) {
merge = true;
} else if (wantToMerge == Messages.NO) {
merge = false;
} else {
return;
}
}
if (merge) {
MoveNodesUtil.moveTo(project, getName(), MapSequence.<MoveNodesUtil.NodeProcessor, List<SNode>>fromMapAndKeysArray(new HashMap<MoveNodesUtil.NodeProcessor, List<SNode>>(), new MoveNodesUtil.ExistingTargetProcessor(mergeTarget.value.getReference(), project)).withValues(ListSequence.fromListAndArray(new ArrayList<SNode>(), feature)));
} else {
MoveNodesUtil.moveTo(project, getName(), MapSequence.<MoveNodesUtil.NodeProcessor, List<SNode>>fromMapAndKeysArray(new HashMap<MoveNodesUtil.NodeProcessor, List<SNode>>(), new MoveNodesUtil.NodeCreatingProcessor(new NodeLocation.NodeLocationChild(targetConcept, feature.getContainmentLink()), project)).withValues(ListSequence.fromListAndArray(new ArrayList<SNode>(), feature)));
}
}
public static class MovePropertyUp_extension extends Extension.Default<MoveNodesAction> {
public MovePropertyUp_extension() {
super("jetbrains.mps.ide.platform.MoveNodesActionEP");
}
public MoveNodesAction get() {
return new MoveFeatureUp("Move Property Up", "property", new _FunctionTypes._return_P1_E0<Boolean, SNode>() {
public Boolean invoke(SNode conceptFeature) {
return SNodeOperations.hasRole(conceptFeature, MetaAdapterFactory.getContainmentLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x1103553c5ffL, 0xf979c3ba6cL, "propertyDeclaration"));
}
}, new _FunctionTypes._return_P2_E0<SNode, SNode, SNode>() {
public SNode invoke(final SNode node, SNode concept) {
return ListSequence.fromList(SLinkOperations.getChildren(concept, MetaAdapterFactory.getContainmentLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x1103553c5ffL, 0xf979c3ba6cL, "propertyDeclaration"))).where(new IWhereFilter<SNode>() {
public boolean accept(SNode it) {
return eq_g4dz8g_a0a0a0a0a0a0a0a0d0a0a1i(SPropertyOperations.getString(it, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name")), SPropertyOperations.getString(SNodeOperations.cast(node, MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086bL, "jetbrains.mps.lang.structure.structure.PropertyDeclaration")), MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name")));
}
}).first();
}
});
}
private static boolean eq_g4dz8g_a0a0a0a0a0a0a0a0d0a0a1i(Object a, Object b) {
return (a != null ? a.equals(b) : a == b);
}
}
public static class MoveContainmentLinkUp_extension extends Extension.Default<MoveNodesAction> {
public MoveContainmentLinkUp_extension() {
super("jetbrains.mps.ide.platform.MoveNodesActionEP");
}
public MoveNodesAction get() {
return new MoveFeatureUp("Move Link Up", "link", new _FunctionTypes._return_P1_E0<Boolean, SNode>() {
public Boolean invoke(SNode conceptFeature) {
return SNodeOperations.hasRole(conceptFeature, MetaAdapterFactory.getContainmentLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x1103553c5ffL, 0xf979c3ba6bL, "linkDeclaration")) && SPropertyOperations.hasValue(SNodeOperations.cast(conceptFeature, MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, "jetbrains.mps.lang.structure.structure.LinkDeclaration")), MetaAdapterFactory.getProperty(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf980556927L, "metaClass"), "aggregation", "reference");
}
}, new _FunctionTypes._return_P2_E0<SNode, SNode, SNode>() {
public SNode invoke(final SNode node, SNode concept) {
return ListSequence.fromList(SLinkOperations.getChildren(concept, MetaAdapterFactory.getContainmentLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x1103553c5ffL, 0xf979c3ba6bL, "linkDeclaration"))).where(new IWhereFilter<SNode>() {
public boolean accept(SNode it) {
return SPropertyOperations.hasValue(it, MetaAdapterFactory.getProperty(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf980556927L, "metaClass"), "aggregation", "reference") && eq_g4dz8g_a0a0a0a0a0a0a0a0a3a0a0b9(SPropertyOperations.getString(it, MetaAdapterFactory.getProperty(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf98052f333L, "role")), SPropertyOperations.getString(SNodeOperations.cast(node, MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, "jetbrains.mps.lang.structure.structure.LinkDeclaration")), MetaAdapterFactory.getProperty(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf98052f333L, "role")));
}
}).first();
}
});
}
private static boolean eq_g4dz8g_a0a0a0a0a0a0a0a0a3a0a0b9(Object a, Object b) {
return (a != null ? a.equals(b) : a == b);
}
}
public static class MoveRefrenceLinkUp_extension extends Extension.Default<MoveNodesAction> {
public MoveRefrenceLinkUp_extension() {
super("jetbrains.mps.ide.platform.MoveNodesActionEP");
}
public MoveNodesAction get() {
return new MoveFeatureUp("Move Link Up", "link", new _FunctionTypes._return_P1_E0<Boolean, SNode>() {
public Boolean invoke(SNode conceptFeature) {
return SNodeOperations.hasRole(conceptFeature, MetaAdapterFactory.getContainmentLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x1103553c5ffL, 0xf979c3ba6bL, "linkDeclaration")) && SPropertyOperations.hasValue(SNodeOperations.cast(conceptFeature, MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, "jetbrains.mps.lang.structure.structure.LinkDeclaration")), MetaAdapterFactory.getProperty(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf980556927L, "metaClass"), "reference", "reference");
}
}, new _FunctionTypes._return_P2_E0<SNode, SNode, SNode>() {
public SNode invoke(final SNode node, SNode concept) {
return ListSequence.fromList(SLinkOperations.getChildren(concept, MetaAdapterFactory.getContainmentLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x1103553c5ffL, 0xf979c3ba6bL, "linkDeclaration"))).where(new IWhereFilter<SNode>() {
public boolean accept(SNode it) {
return SPropertyOperations.hasValue(it, MetaAdapterFactory.getProperty(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf980556927L, "metaClass"), "reference", "reference") && eq_g4dz8g_a0a0a0a0a0a0a0a0a3a0a0b01(SPropertyOperations.getString(it, MetaAdapterFactory.getProperty(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf98052f333L, "role")), SPropertyOperations.getString(SNodeOperations.cast(node, MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, "jetbrains.mps.lang.structure.structure.LinkDeclaration")), MetaAdapterFactory.getProperty(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf98052f333L, "role")));
}
}).first();
}
});
}
private static boolean eq_g4dz8g_a0a0a0a0a0a0a0a0a3a0a0b01(Object a, Object b) {
return (a != null ? a.equals(b) : a == b);
}
}
}