package eu.ydp.empiria.player.client.module.tutor;

import com.google.common.base.Optional;
import com.google.inject.Inject;

import eu.ydp.empiria.player.client.gin.scopes.module.ModuleScoped;
import eu.ydp.empiria.player.client.module.tutor.actions.OutcomeDrivenActionTypeGenerator;

public class ActionEventGenerator {

	@Inject @ModuleScoped
	private ActionExecutorService executorService;
	
	@Inject @ModuleScoped
	private OutcomeDrivenActionTypeGenerator actionTypeGenerator;
	
	private final EndHandler endHandler = new EndHandler() {
		@Override
		public void onEnd() {
			onActionEnd();
		}
	};
	
	public void start(){
		executorService.execute(ActionType.DEFAULT, endHandler);
	}
	
	public void stop(){
		executorService.execute(ActionType.DEFAULT, endHandler);
	}
	
	public void stateChanged(){
		Optional<ActionType> actionType = actionTypeGenerator.findActionType();
		if (actionType.isPresent()){
			executorService.execute(actionType.get(), endHandler);
		}
	}

	private void onActionEnd() {
		executorService.execute(ActionType.DEFAULT, endHandler);
	}
}

@@ -657,145 +657,79 @@
 ecut
-orService.execute(ActionType.DEFAULT, endHandler);%0D%0A%09%7D%0D%0A%09%0D%0A%09public void stop()%7B%0D%0A%09%09executorService.execute(ActionType.DEFAULT, endHandler
+eDefaultAction();%0D%0A%09%7D%0D%0A%09%0D%0A%09public void stop()%7B%0D%0A%09%09executeDefaultAction(
 );%0D%0A
@@ -881,33 +881,23 @@
 %09%09execut
-orService.execute
+eAction
 (actionT
@@ -905,28 +905,16 @@
 pe.get()
-, endHandler
 );%0D%0A%09%09%7D%0D
@@ -963,25 +963,88 @@
 ecut
-orService.
+eDefaultAction();%0D%0A%09%7D%0D%0A%0D%0A%09private void executeDefaultAction() %7B%0D%0A%09%09
 execute
+Action
 (Act
@@ -1058,16 +1058,108 @@
 .DEFAULT
+);%0D%0A%09%7D%0D%0A%0D%0A%09private void executeAction(ActionType action) %7B%0D%0A%09%09executorService.execute(action
 , endHan

refactor ActionEventGenerator issue YPUB-5505