package jetbrains.mps.editor.runtime.impl.cellActions; /*Generated by MPS */ import jetbrains.mps.editor.runtime.cells.AbstractCellAction; import org.jetbrains.mps.openapi.model.SNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.mps.openapi.language.SContainmentLink; import org.jetbrains.mps.openapi.language.SAbstractConcept; import org.jetbrains.annotations.Nullable; import jetbrains.mps.smodel.adapter.MetaAdapterByDeclaration; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; import jetbrains.mps.openapi.editor.EditorContext; import jetbrains.mps.openapi.editor.cells.EditorCell; import jetbrains.mps.editor.runtime.cells.ReadOnlyUtil; import jetbrains.mps.smodel.SModelUtil_new; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import jetbrains.mps.smodel.legacy.ConceptMetaInfoConverter; public class CellAction_DeleteSmart extends AbstractCellAction { private SNode myLegacyLink; private String myLegacyRole; @NotNull private SNode mySource; @NotNull private SNode myTarget; private boolean myCanBeNull = true; private boolean myEnabled = true; private SContainmentLink myLink; private SAbstractConcept myLinkTargetConcept; public CellAction_DeleteSmart(SNode source, SContainmentLink link, SNode target) { this(source, link, target, null); } public CellAction_DeleteSmart(@NotNull SNode source, @NotNull SContainmentLink link, @NotNull SNode target, @Nullable SAbstractConcept specificTargetConcept) { mySource = source; myLink = link; myTarget = target; if (specificTargetConcept != null) { myLinkTargetConcept = MetaAdapterByDeclaration.asInstanceConcept(specificTargetConcept); } else { myLinkTargetConcept = MetaAdapterByDeclaration.asInstanceConcept(myLink.getTargetConcept()); } myCanBeNull = link.isOptional(); myLegacyRole = null; myLegacyLink = null; if (myCanBeNull) { return; } myEnabled = !(link.isMultiple()) && neq_89lc4r_a0a0k0m(SNodeOperations.getConcept(myTarget), myLinkTargetConcept); } @Override public boolean canExecute(EditorContext context) { if (!(myEnabled)) { return false; } EditorCell myTargetCell = context.getEditorComponent().findNodeCell(myTarget); return !(ReadOnlyUtil.isCellOrSelectionReadOnlyInEditor(context.getEditorComponent(), myTargetCell)); } @Override public void execute(EditorContext context) { SNodeOperations.deleteNode(myTarget); if (!(myCanBeNull)) { if (myLegacyLink != null) { // old way SNode defaultTarget = SModelUtil_new.instantiateConceptDeclaration(SLinkOperations.getTarget(myLegacyLink, MetaAdapterFactory.getReferenceLink(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0xf979bd086aL, 0xf98055fef0L, "target")), SNodeOperations.getModel(mySource), true); SLinkOperations.setTarget(mySource, ((ConceptMetaInfoConverter) mySource.getConcept()).convertAggregation(myLegacyRole), defaultTarget); } else { // new way assert myLink != null; SNode defaultTarget = SModelUtil_new.instantiateConceptDeclaration(myLinkTargetConcept, SNodeOperations.getModel(mySource), null, true); SLinkOperations.setTarget(mySource, myLink, defaultTarget); } } } private static boolean neq_89lc4r_a0a0k0m(Object a, Object b) { return !(((a != null ? a.equals(b) : a == b))); } }