package com.coltsoftware.liquidsledgehammer.commands;

import java.io.PrintStream;

import com.coltsoftware.liquidsledgehammer.Command;
import com.coltsoftware.liquidsledgehammer.State;
import com.coltsoftware.liquidsledgehammer.cmd.Arguments;
import com.coltsoftware.liquidsledgehammer.collections.FinancialTreeNode;
import com.coltsoftware.liquidsledgehammer.model.FinancialTransaction;
import com.coltsoftware.liquidsledgehammer.model.SubTransaction;

public final class ListTreeCommand implements Command {

	@Override
	public void execute(State state, Arguments arguments, PrintStream out) {
		FinancialTreeNode treeNode = state.getCurrentNode();
		out.println(formatTopNode(treeNode));
		for (FinancialTreeNode node : treeNode)
			out.println(formatNode(node));
		for (SubTransaction subTransaction : treeNode.getSubTransactions())
			out.println(formatSubTransaction(subTransaction));
	}

	private static String formatTopNode(FinancialTreeNode node) {
		return String.format("[%s %s]", node.getName(), node.getTotalValue());
	}

	private static String formatSubTransaction(SubTransaction subTransaction) {
		FinancialTransaction transaction = subTransaction.getTransaction();
		return String.format("%s\t%s\t%s", transaction.getDate(),
				transaction.getDescription(), subTransaction.getValue());
	}

	private static String formatNode(FinancialTreeNode node) {
		return String.format("%s %s", node.getName(), node.getTotalValue());
	}

	@Override
	public void printUsage(PrintStream out) {
		out.println("    ls\tList tree");
	}
}

@@ -1210,16 +1210,20 @@
 %5Ct%25s%5Ct%25s
+%5Ct%25s
 %22, trans
@@ -1240,16 +1240,55 @@
 Date(),%0A
+%09%09%09%09transaction.getSource().getName(),%0A
 %09%09%09%09tran

Add source name to transaction listing