package antw.ui;

import antw.ant.Printer;
import antw.model.Project;
import antw.model.Projects;
import antw.model.Target;

public class TreeTable extends Table {

    private Project _lastProject = new Project("root");
    private int _spaceCount = 2;

    @Override
    public void logTargetStartet(Printer printer, Target target) {
        if (!target.getProject().equals(_lastProject)) {
            switchToSubProject(printer, _lastProject, target.getProject());
            switchFromSubProject(printer, _lastProject, target.getProject());
            printProject(printer, target.getProject());
        }
        _lastProject = target.getProject();
        printer.space(_spaceCount + 2);
        printer.out("|--- " + target.getName());
    }

    private void printProject(Printer printer, Project project) {
        printer.space(_spaceCount + 2);
        printer.out("|");
        printer.space(_spaceCount + 1);
        printer.out(project.getName());
    }

    private void switchFromSubProject(Printer printer, Project lastProject, Project project) {
        if (lastProject.isSubProject()) {
            if (!project.isSubProject()) {
                printer.space(_spaceCount + 1);
                _spaceCount -= 2;
                printer.out("/");
            }
        }
    }

    private void switchToSubProject(Printer printer, Project lastProject, Project currentProject) {
        if (!lastProject.isSubProject()) {
            if (currentProject.isSubProject()) {
                _spaceCount += 2;
                printer.space(_spaceCount + 1);
                printer.out("\\");
            }
        }

    }

    @Override
    public void logTargetFinished(Printer printer, Target target) {

    }

    @Override
    public void logBuildFinished(Printer printer, Projects projects) {

    }

    @Override
    public void logBuildStarted(Printer printer, Projects projects) {

    }

}

@@ -11,16 +11,40 @@
 tw.ui;%0A%0A
+import java.util.Date;%0A%0A
 import a
@@ -60,16 +60,16 @@
 rinter;%0A
-
 import a
@@ -140,16 +140,43 @@
 .Target;
+%0Aimport antw.util.TimeUtil;
 %0A%0Apublic
@@ -297,16 +297,41 @@
 unt = 2;
+%0A    private Date _start;
 %0A%0A    @O
@@ -790,34 +790,304 @@
 out(
-%22%7C--- %22 + target.getName()
+%0A                %22%25-40s %25-40s%25n%22,%0A                new Object%5B%5D %7B%0A                        %22%7C--- %22 + target.getName(),%0A                        %22%5B%22 + target.getCounter() + %22 times; %22%0A                                + TimeUtil.formatTimeDuration(System.currentTimeMillis() - _start.getTime()) + %22%5D%22 %7D
 );%0A 
@@ -2238,26 +2238,54 @@
 cts projects) %7B%0A
+        _start = new Date();
 %0A    %7D%0A%0A%7D%0A

improve tree table log