Template in 6.4 RC1 questions

Hi
I noticed a significant improvement in Template in 6.4RC1 compared to RC. I am now trying to use some power of this new functionality.

I have started designing a template by copying from existing one. Seems like you have used markup language but I’m not sure as I am not a frequent user of that. I have some questions and need help to improve the template.

  1. Noticed that the template is located inside the project, can this be moved to a common place where the Studio can reuse it for any project?
  2. How can migrate the template from one version to new version, do I need to copy manually?

I have few more questions regarding coding of the template, focusing the controller.
3. How can I get the composite entity name
4. how can i get the field name of the composite entity

Question focusing the screen XML:
5. How can i use specific component e.g. use CssLayout for individual fields instead of one fieldGroup and set the Datasource properties to those fields? The objective is to make it Responsive (knowing we have to using CSS in theme)

Thank you .

Here is copy of the template. I also have attached the test project and feel free to use it for illustration if you want.


<%
if (copyright) {
    println '/*'
    println " * ${copyright.replace('\n', '\n * ')}"
    println ' */'
} else {
    print ""
}
%>package ${packageName};

import com.haulmont.cuba.gui.components.AbstractEditor;
import com.haulmont.cuba.core.global.Metadata;
import com.haulmont.cuba.gui.components.Table;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory
import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.LookupPickerField;
import ${entity.fqn};
import javax.inject.Inject;
import javax.inject.Named;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
<%if (classComment) {%>
${classComment}<%}%>
public class ${controllerName} extends AbstractEditor<${entity.className}> {

    @Inject
    private Metadata metadata;
    @Inject
    private Table<${entity.className}> ${entity.className};
    @Inject
    private ComponentsFactory componentsFactory;
    

    @Override
    public void init(Map<String, Object> params) {

        initComboColums();
        initTableColumnListeners();
    }


   @Override
    protected void initNewItem(${entity.className} item) {
        item.setStatus(OrderStatus.NEW);
        Date date = new Date();
        item.setDocDate(date);

    }
    
    
    public void onAdd(Component source) {
        SalesOrderLine line = metadata.create(SalesOrderLine.class);
        line.set${entity.className}(salesOrderDs.getItem());
        salesOrderLinesDs.addItem(line);
    
         //creating lineNumber
        int max = 0;
        Integer lastNum = salesOrderLinesDs.getItems().stream()
                .map(SalesOrderLine::getEntryNumber)
                .max(Integer::compareTo)
                .orElse(0);
        line.setEntryNumber(lastNum+1);

        salesOrderLineDs.addItem(line);

       // set focus on the first cell of the added row
        salesOrderLineTable.scrollTo(line);

        // set focus on the first cell of the added row
        salesOrderLineTable.setSelected(line);
        salesOrderLineTable.requestFocus(line, "product");
        
    }


    public void onRemove(Component source) {
        if (salesOrderLinesDs.getItem() != null) {
            salesOrderLinesDs.removeItem(salesOrderLinesDs.getItem());
        }
    }


    public void onSave() {
        if (validateAll()) {
            getDsContext().commit();
            showNotification(getMessage("changesSaved"), NotificationType.HUMANIZED);
        }
    }



 private void initComboColums() {
        salesOrderLineTable.addGeneratedColumn("product", client -> {
            LookupPickerField field = componentsFactory.createComponent(LookupPickerField.class);
            field.setWidth("100%");
            field.setOptionsDatasource(productsDs);
            field.setDatasource(salesOrderLineTable.getItemDatasource(client), "product");
            field.addLookupAction();
            return field;
        });
        
        }
        
        
        
    private void initTableColumnListeners(){
        salesOrderLineDs.addItemPropertyChangeListener(e -> {
            if ("product".equals(e.getProperty())) {
              
            }
        }
    }
    
    
}

testtemplate.zip (69.8K)

Hi,

> can this be moved to a common place where the Studio can reuse it for any project?

For the moment, there is no such option in the platform. However, to support templates reusability, we are planning to use the ‘studio.user.home’/templates directory for the templates available for all projects.

How can migrate the template from one version to new version, do I need to copy manually?

Unfortunately, I didn’t fully understand the question. Did you mean the platform version? In order to divide templates by versions, you can set a range of versions, compatible with this template, in the Platform version range field. If no range is set for a template, the template will always be displayed. If a template’s range does not contain the current project version, this template will not be displayed in the list of available templates.

In the XML descriptor the range is defined by the platformVersionRange attribute. The example of version ranges implementation you can find in com.haulmont.studio.backend.TemplateEngineTest#versionMatchingRange.

> I have few more questions regarding coding of the template, focusing the controller.

1-2 Actually, only the methods from helper and parameters passed to the template are available for now. The information on the methods and objects passed to templates you can find in the Studio Help, when you open the template editor.

So, answering your questions, it is not possible yet.

> Question focusing the screen XML:

Again, we haven’t implemented this option yet. In future, we are going to generate the set of objects containing the data on each column or a field instead of xml fieldGroup generated today.

:ticket: See the following issue in our bug tracker:

https://youtrack.cuba-platform.com/issue/STUDIO-3356