package ua.com.fielden.platform.domaintree.impl;

import ua.com.fielden.platform.domaintree.ICalculatedProperty.CalculatedPropertyAttribute;
import ua.com.fielden.platform.domaintree.centre.ICentreDomainTreeManager.ICentreDomainTreeManagerAndEnhancer;
import ua.com.fielden.platform.domaintree.centre.ICentreDomainTreeRepresentation.IAddToResultTickRepresentation;
import ua.com.fielden.platform.entity.AbstractEntity;

/**
 *
 * @author TG Team
 *
 */
public class CentreManagerConfigurator {
    private final Class<?> root;

    public CentreManagerConfigurator(final Class<? extends AbstractEntity<?>> root) {
	this.root = root;
    }

    public ICentreDomainTreeManagerAndEnhancer configCentre(final ICentreDomainTreeManagerAndEnhancer cdtme) {
	return cdtme;
    }

    public CentreManagerConfigurator addCriteria(final ICentreDomainTreeManagerAndEnhancer cdtme, final String prop) {
	cdtme.getFirstTick().check(root, prop, true);
	return this;
    }

    public CentreManagerConfigurator addColumn(final ICentreDomainTreeManagerAndEnhancer cdtme, final String prop) {
	final IAddToResultTickRepresentation rtr = cdtme.getRepresentation().getSecondTick();
	cdtme.getSecondTick().check(root, prop, true);
	cdtme.getSecondTick().setWidth(root, prop, rtr.getWidthByDefault(root, prop));
	return this;
    }

    public CentreManagerConfigurator addColumn(final ICentreDomainTreeManagerAndEnhancer cdtme, final String prop, final int width) {
	cdtme.getSecondTick().check(root, prop, true);
	cdtme.getSecondTick().setWidth(root, prop, width);
	return this;
    }

    public CentreManagerConfigurator addTotal(final ICentreDomainTreeManagerAndEnhancer cdtme, final String title, final String description, final String formula, final String relatedProperty) {
	cdtme.getEnhancer().addCalculatedProperty(root, "", formula, title, description, CalculatedPropertyAttribute.NO_ATTR, relatedProperty);
	cdtme.getEnhancer().apply();
	cdtme.getSecondTick().check(root, CalculatedProperty.generateNameFrom(title), true);
	return this;
    }

    /** Root type, which domain tree is configured by this configurator. */
    protected Class<?> root() {
	return root;
    }
}

@@ -43,16 +43,211 @@
 .impl;%0A%0A
+import java.util.Arrays;%0Aimport java.util.Date;%0Aimport java.util.List;%0A%0Aimport org.joda.time.DateTime;%0Aimport org.joda.time.format.DateTimeFormat;%0Aimport org.joda.time.format.DateTimeFormatter;%0A%0A
 import u
@@ -2352,11 +2352,470 @@
 t;%0A    %7D
+%0A%0A    /** Convenient entity strings conversion method. */%0A    protected static List%3CString%3E entityVal(final String ... strs) %7B%0A%09return Arrays.asList(strs);%0A    %7D%0A%0A    /** Convenient date conversion method in format 'yyyy-MM-dd HH:mm:ss'. */%0A    protected static Date dateVal(final String str) %7B%0A%09final DateTimeFormatter formatter = DateTimeFormat.forPattern(%22yyyy-MM-dd HH:mm:ss%22);%0A%09final DateTime dt = formatter.parseDateTime(str);%0A%09return dt.toDate();%0A    %7D
 %0A%7D%0A

Provided convenient methods (for entity, date) to convert criteria strings into default configuration values.