/FileExtraction/Java_unseen/rubato-composer_rubato-composer/java/src/org/rubato/rubettes/bigbang/model/undo/RemoveOperationEdit.java
package org.rubato.rubettes.bigbang.model.undo;

import org.rubato.rubettes.bigbang.model.undo.AbstractUndoableEdit;

import org.rubato.rubettes.bigbang.model.graph.BigBangOperationGraph;
import org.rubato.rubettes.bigbang.model.graph.CompositionState;
import org.rubato.rubettes.bigbang.model.operations.AbstractOperation;

public class RemoveOperationEdit extends AbstractUndoableEdit {
	
	private BigBangOperationGraph graph;
	private AbstractOperation operation;
	private boolean hasToBeReinserted;
	private Integer startingState;
	
	public RemoveOperationEdit(AbstractOperation operation, BigBangOperationGraph graph) {
		this.graph = graph;
		this.operation = operation;
	}
	
	public void execute() {
		this.startingState = this.graph.getEndpoints(this.operation).getFirst().getIndex();
		this.hasToBeReinserted = this.graph.removeOperation(this.operation);
	}
	
	@Override
	public void undo() {
		super.undo();
		if (this.hasToBeReinserted) {
			this.graph.setInsertionState(this.startingState);
		} else {
			this.graph.setInsertionState(null);
		}
		this.graph.addOrInsertOperation(this.operation, false);
	}
	
	@Override
	public void redo() {
		super.redo();
		this.execute();
	}
	
	@Override
	public String getPresentationName() {
		return "Remove " + this.operation.toString();
	}

}
