/*  
 * Copyright 2004-2009 unitarou <boss@unitarou.org>. 
 * All rights reserved.
 * 
 * This program and the accompanying materials are made available under the terms of 
 * the Common Public License v1.0 which accompanies this distribution, 
 * and is available at http://opensource.org/licenses/cpl.php
 * 
 * Contributors:
 *     unitarou - initial API and implementation
 */
package org.unitarou.sgf.cmd;



import org.unitarou.cmd.AbstractCommand;
import org.unitarou.cmd.Command;
import org.unitarou.sgf.GameTree;
import org.unitarou.sgf.Node;

/**
 * {@link org.unitarou.sgf.GameTree}ðwèµ½m[hÌqÆµÄÇÁ·éR}hÅ·B<br>
 * 
 * g£_ª{@link org.unitarou.sgf.Sequence}ÌöÅ éêÍ
 * {@link org.unitarou.sgf.cmd.AddGameTree}ðÀsµÜ·B<br>
 * 
 * g£_ª{@link org.unitarou.sgf.Sequence}ÌöÈOÌêÍA
 * {@link org.unitarou.sgf.cmd.CreateGameTreeImpl}ðÀsµÜ·B
 * 
 * @author UNITAROU &lt;boss@unitarou.org&gt;
 */
public class CreateGameTree extends AbstractCommand {
	
	
	private final Command command_;
	
	/**
	 * @param parent 
	 * @param extensionPoint 
	 * @param child 
	 */
	public CreateGameTree(GameTree parent, Node extensionPoint, GameTree child) {
		super();
		
		if (parent.getSequence().getLast() == extensionPoint) { 
			command_ = new AddGameTree(parent, child);
		} else {
			command_ = new CreateGameTreeImpl(parent, extensionPoint, child);
		}
	}

	@Override
	protected void executeCommand() {
		command_.execute();
	}

	@Override
	protected void undoCommand() {
		command_.undo();
	}
}
