/**
 * 
 */
package de.darwinspl.feature.evolution.Invoker;

import java.util.ArrayList;
import java.util.Date;

import de.darwinspl.feature.evolution.basic.operations.*;
import de.darwinspl.feature.evolution.operations.AddFeatureWithGroup;
import eu.hyvar.feature.HyFeature;
import eu.hyvar.feature.HyFeatureModel;
import eu.hyvar.feature.HyFeatureTypeEnum;

/**
 * Get request from the editor and invoke the corresponding evoOp to execute the command.
 */
public class OperationInvoker {

	//Catalog of all existing evoOps
	protected ArrayList<EvolutionOperation> evoOps = new ArrayList<>();
	
	private ArrayList<EvolutionOperation> commandHistory = new ArrayList<>();
	private int counterOfExecuteCommands = 0;
	
	/**
	 * undo the last command and decrease the counter of execute commands.
	 */
	public void undo() {
		if (counterOfExecuteCommands > 0)
			commandHistory.get(counterOfExecuteCommands--).undo();
	}
	
	/**
	 * execute the last undo command, to recover the old state.
	 */
	/*public void redo() {
		commandHistory.get(++counterOfExecuteCommands).execute();
	}*/
	
	/**
	 * provide addFeature operation as command for use
	 * @param name of the new feature
	 * @param type of the new feature
	 * @param timestamp since the feature is valid
	 * @param tfm the corresponding model
	 */
	public HyFeatureModel AddFeature(String name, HyFeatureTypeEnum type, HyFeature parent, Date timestamp, HyFeatureModel tfm) {
		
		ComplexOperation addFeatureWithGroup = new AddFeatureWithGroup(name, type, parent, timestamp, tfm);
		evoOps.add(addFeatureWithGroup);
		addFeatureWithGroup.execute();
		//add the operation as next command in the history
		commandHistory.add(++counterOfExecuteCommands, addFeatureWithGroup);
		
		return tfm;
	}
	
}

@@ -173,16 +173,85 @@
 ons.*;%0D%0A
+import de.darwinspl.feature.evolution.operations.AddFeatureInGroup;%0D%0A
 import d
@@ -433,16 +433,61 @@
 peEnum;%0D
+%0Aimport eu.hyvar.feature.HyGroupComposition;%0D
 %0A%0D%0A/**%0D%0A
@@ -1911,11 +1911,433 @@
 %0A%09%7D%0D%0A%09%0D%0A
+%09public HyFeatureModel AddFeature(String name, HyFeatureTypeEnum type, HyGroupComposition groupComposition, Date timestamp, HyFeatureModel tfm) %7B%0D%0A%09%09%0D%0A%09%09ComplexOperation addFeatureInGroup = new AddFeatureInGroup(name, type, groupComposition, timestamp, tfm);%0D%0A%09%09evoOps.add(addFeatureInGroup);%0D%0A%09%09addFeatureInGroup.execute();%0D%0A%09%09commandHistory.add(++counterOfExecuteCommands, addFeatureInGroup);%0D%0A%09%09%0D%0A%09%09return tfm;%0D%0A%09%7D%0D%0A%09%0D%0A
 %7D%0D%0A

Add evoOp AddFeatureInGroup to the Invoker