package jetbrains.mps.editor.runtime.impl.cellActions;

/*Generated by MPS */

import jetbrains.mps.annotations.GeneratedClass;
import jetbrains.mps.editor.runtime.cells.AbstractCellAction;
import org.jetbrains.mps.openapi.model.SNode;
import org.jetbrains.mps.openapi.language.SProperty;
import jetbrains.mps.nodeEditor.cellActions.CellAction_DeleteNode;
import jetbrains.mps.openapi.editor.EditorContext;
import org.jetbrains.mps.openapi.model.SNodeAccessUtil;

@GeneratedClass(node = "r:b9f36c08-4a75-4513-9277-a390d3426e0f(jetbrains.mps.editor.runtime.impl.cellActions)/3766068586453539585", model = "r:b9f36c08-4a75-4513-9277-a390d3426e0f(jetbrains.mps.editor.runtime.impl.cellActions)")
public class CellAction_DeleteSPropertyOrNode extends AbstractCellAction {
  private final SNode mySemanticNode;
  private final SProperty myProperty;
  private final CellAction_DeleteNode.DeleteDirection myDirection;
  public CellAction_DeleteSPropertyOrNode(SNode semanticNode, SProperty property) {
    this(semanticNode, property, CellAction_DeleteNode.DeleteDirection.FORWARD);
  }
  public CellAction_DeleteSPropertyOrNode(SNode semanticNode, SProperty property, CellAction_DeleteNode.DeleteDirection direction) {
    mySemanticNode = semanticNode;
    myProperty = property;
    myDirection = direction;
  }
  @Override
  public boolean canExecute(EditorContext context) {
    return true;
  }
  @Override
  public void execute(EditorContext context) {
    if (SNodeAccessUtil.getProperty(mySemanticNode, myProperty) != null) {
      SNodeAccessUtil.setProperty(mySemanticNode, myProperty, null);
    } else {
      CellAction_DeleteEasily deleteAction = new CellAction_DeleteEasily(mySemanticNode, myDirection);
      if (deleteAction.canExecute(context)) {
        deleteAction.execute(context);
      }
    }
  }
}
