All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jpattern.gwt.client.command.CommandChain Maven / Gradle / Ivy

package com.jpattern.gwt.client.command;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.jpattern.shared.result.IResult;

/**
 * 
 * @author Francesco Cina'
 *
 */
public class CommandChain extends ACommand {

	List commands = new ArrayList();
	private Iterator commandIterator;
	
	@Override
	public void exec(IResult commandResult) {
		commandIterator = commands.iterator();
		callback(commandResult);
	}
	
	protected void callback(IResult commandResult) {
		if (commandIterator.hasNext() && commandResult.getErrorMessages().isEmpty()) {
			ACommand nextCommand = commandIterator.next();
			nextCommand.visit(getProvider());
			nextCommand.exec(new CommandChainCallBack());
		} else {
			getCommandCallBack().callback(commandResult);
		}
	}
	
	public void addCommand(ACommand command) {
		commands.add(command);
	}
	
	
	class CommandChainCallBack implements ICommandCallBack {
		
		@Override
		public void callback(IResult commandResult) {
			CommandChain.this.callback(commandResult);
		}

	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy