WorkPlans column extension

Since version 1.1.2, columns in input and output products of work-plans can be injected from other plugins.

Work-plans plugin injects 2 basic columns by itself so consider that as a good documentation.

In order to add a column

you should add a class for a column loader (preferably: com.qcadoo.mes....yourPlugin.workPlansColumnExtension.YourPluginColumnLoader.java, to hold convention), which looks a little bit like this:

@Component
public class PluginNameColumnLoader {

    @Autowired
    private WorkPlansColumnLoaderService workPlansColumnLoaderService;

    private static final Logger LOG = LoggerFactory.getLogger(PluginNameColumnLoader.class);

    public void addPluginNameColumnsForProducts() {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Columns for input and output products table will be populated ...");
        }
 
        workPlansColumnLoaderService.fillColumnsForProducts(PluginNameConstants.PLUGIN_IDENTIFIER);
    }
 

    public void deletePluginNameColumnsForProducts() {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Columns for input and output products table will be unpopulated ...");
        }

        workPlansColumnLoaderService.clearColumnsForProducts(PluginNameConstants.PLUGIN_IDENTIFIER);
    }
}

then you have to add a column definition xml, which this time has to be in the following location:

/plugin-name/src/main/resources/pluginName/model/data/columnForProducts.xml

and it looks like this:

 <?xml version="1.0" encoding="UTF-8"?>
 <!--
 copyright comment 
 -->
  
 <column>
 <row IDENTIFIER="" NAME="" DESCRIPTION="" COLUMNFILLER="" ALIGNMENT="" TYPE="" ACTIVE="" />
 </column>
  • identifier - column identifier which you will use in columnFiller class (for ex. productName)
  • name - locale key for column name (it will show in column selection window, as well as in workplan raport)
  • description - locale key for column description (it will show up only in column selection window)
  • columnfiller - full path to the class that will fill the column values
  • alignment - column alignment on reports (01left,02right)
  • type - to which products column will be added (input, output or both)
  • active - if set to true, column will be added as active to all operations on all levels. If set to false column will be just available for user to select it in the column selection window.

The last thing you have to do is to add invocations of the columnLoader methods in the multiTenantEnable and multiTenantDisable methods of the class that is called by this thing:

 <custom:custom class="SomeClass" />

in your qcadoo-plugin.xml.

And the SomeClass should have something like this in it (it can have other things, but those are relevant to column addition):

 @Component
 public class SomeClass extends Module {
 
     @Autowired
     private PluginNameColumnLoader pluginNameColumnLoader;
 
     @Override
     @Transactional
     public void multiTenantEnable() {
         pluginNameColumnLoader.addPluginNameColumnsForProducts();
     }
 

     @Override
     @Transactional
     public void multiTenantDisable() {
         pluginNameColumnLoader.deletePluginNameColumnsForProducts();
     }
 }

In order to fill the column

This one is simple, you create a class, preferably in the workPlansColumnExtension package where columnLoader class lies, named: YourPluginColumnFiller.java but that's not mandatory. That class has to implement the ColumnFiller interface like this:

public class PluginNameColumnFiller implements ColumnFiller {

    @Override
    public Map<Entity, Map<String, String>> getValues(List<Entity> orders) {
        // returning the map of column values 
    }
}  

that method takes a list of orders in the argument, and has to return map of the following structure:

  • the key is an Entity of the model operationProductInComponent or operationProductOutComponent representing the row
  • the value is a map which
    • key is a columnIdentifier specified earlier in the xml with column definition
    • value is the value to put in that column
That's all there is to it.