package fmp.provider.command;

import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.command.SetCommand;
import org.eclipse.emf.edit.domain.EditingDomain;

import fmp.Feature;
import fmp.FmpPackage;

/**
 * @author Michal
 * TODO should work for selections with multiple objects 
 */
public class MakeMandatoryOptionalCommand extends CompoundCommand {
	EObject owner;
	boolean mandatory;
	
	public MakeMandatoryOptionalCommand(EditingDomain domain, EObject owner, boolean mandatory) {
		this.owner = owner;
		this.mandatory = mandatory;
		
		append(new SetCommand(domain, owner, FmpPackage.eINSTANCE.getNode_Min(), mandatory ? new Integer(1) : new Integer(0)));
		append(new SetCommand(domain, owner, FmpPackage.eINSTANCE.getNode_Max(), new Integer(1)));
	}
	public boolean canExecute() {
		if (owner instanceof Feature)
			return true;
		return false;
	}
}
