1.7.2. Contract Editor Controller

Go to the Controller tab and replace its content with the following code:

package com.company.bpmdemo.web.contract;

import com.haulmont.cuba.gui.components.AbstractEditor;
import com.company.bpmdemo.entity.Contract;
import com.haulmont.bpm.entity.ProcAttachment;
import com.haulmont.bpm.gui.procactions.ProcActionsFrame;
import com.haulmont.cuba.gui.app.core.file.FileDownloadHelper;
import com.haulmont.cuba.gui.components.Table;

import javax.inject.Inject;

public class ContractEdit extends AbstractEditor<Contract> {
    private static final String PROCESS_CODE = "contractApproval";

    @Inject
    private ProcActionsFrame procActionsFrame;

    @Inject
    private Table<ProcAttachment> attachmentsTable;

    @Override
    public void ready() {
        FileDownloadHelper.initGeneratedColumn(attachmentsTable, "file");
        initProcActionsFrame();
    }

    private void initProcActionsFrame() {
        procActionsFrame.initializer()
                .standard()
                .init(PROCESS_CODE, getItem());
    }
}

Click OK to save the changes.

Let’s examine the controller code in details.

The ProcActionsFrame is the frame that displays process actions available to the user at the moment. On initialization, the frame searches for a related ProcInstance object by two parameters: process code and entity instance. If the ProcInstance object is not found then a new instance is created and the frame displays the start process button. If the related process instance is found then the frame searches for an uncompleted process task for the current user and displays buttons for process task actions. See ProcActionsFrame for details.

In the contract editor, the process actions frame initialization is performed in the initProcActionsFrame() method. The main part of the method is the invocation of the init(PROCESS_CODE, getItem()). The PROCESS_CODE stores a process code (contractApproval - we saw this value during the model deployment, see Process Model Deployment). The second argument getItem() is the current contract.

The standard() initialization does the following:

  • initializes standard process actions predicates that will be invoked before the process is started and before process tasks are completed. The predicates commit the entity editor.

  • initializes standard listeners that will show notifications like "Process started" or "Task completed" and refresh the procActionsFrame after the process is started or process task is completed.